Sat Aug 6 00:39:32 2011

Asterisk developer's documentation


res_snmp.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Voop as
00003  * Thorsten Lockert <tholo@voop.as>
00004  *
00005  * This program is free software, distributed under the terms of
00006  * the GNU General Public License Version 2. See the LICENSE file
00007  * at the top of the source tree.
00008  */
00009 
00010 /*! \file
00011  *
00012  * \brief SNMP Agent / SubAgent support for Asterisk
00013  *
00014  * \author Thorsten Lockert <tholo@voop.as>
00015  *
00016  * \extref Uses the Net-SNMP libraries available at
00017  *  http://net-snmp.sourceforge.net/
00018  */
00019 
00020 /*** MODULEINFO
00021    <depend>netsnmp</depend>
00022  ***/
00023 
00024 #include "asterisk.h"
00025 
00026 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 182808 $")
00027 
00028 #include "asterisk/channel.h"
00029 #include "asterisk/module.h"
00030 
00031 #include "snmp/agent.h"
00032 
00033 #define  MODULE_DESCRIPTION   "SNMP [Sub]Agent for Asterisk"
00034 
00035 int res_snmp_agentx_subagent;
00036 int res_snmp_dont_stop;
00037 int res_snmp_enabled;
00038 
00039 static pthread_t thread = AST_PTHREADT_NULL;
00040 
00041 /*!
00042  * \brief Load res_snmp.conf config file
00043  * \return 1 on load, 0 file does not exist
00044 */
00045 static int load_config(void)
00046 {
00047    struct ast_variable *var;
00048    struct ast_config *cfg;
00049    char *cat;
00050 
00051    res_snmp_enabled = 0;
00052    res_snmp_agentx_subagent = 1;
00053    cfg = ast_config_load("res_snmp.conf");
00054    if (!cfg) {
00055       ast_log(LOG_WARNING, "Could not load res_snmp.conf\n");
00056       return 0;
00057    }
00058    cat = ast_category_browse(cfg, NULL);
00059    while (cat) {
00060       var = ast_variable_browse(cfg, cat);
00061 
00062       if (strcasecmp(cat, "general") == 0) {
00063          while (var) {
00064             if (strcasecmp(var->name, "subagent") == 0) {
00065                if (ast_true(var->value))
00066                   res_snmp_agentx_subagent = 1;
00067                else if (ast_false(var->value))
00068                   res_snmp_agentx_subagent = 0;
00069                else {
00070                   ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value);
00071                   ast_config_destroy(cfg);
00072                   return 1;
00073                }
00074             } else if (strcasecmp(var->name, "enabled") == 0) {
00075                res_snmp_enabled = ast_true(var->value);
00076             } else {
00077                ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
00078                ast_config_destroy(cfg);
00079                return 1;
00080             }
00081             var = var->next;
00082          }
00083       } else {
00084          ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
00085          ast_config_destroy(cfg);
00086          return 1;
00087       }
00088 
00089       cat = ast_category_browse(cfg, cat);
00090    }
00091    ast_config_destroy(cfg);
00092    return 1;
00093 }
00094 
00095 static int load_module(void)
00096 {
00097    if(!load_config())
00098       return AST_MODULE_LOAD_DECLINE;
00099 
00100    ast_verbose(VERBOSE_PREFIX_1 "Loading [Sub]Agent Module\n");
00101 
00102    res_snmp_dont_stop = 1;
00103    if (res_snmp_enabled)
00104       return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
00105    else
00106       return 0;
00107 }
00108 
00109 static int unload_module(void)
00110 {
00111    ast_verbose(VERBOSE_PREFIX_1 "Unloading [Sub]Agent Module\n");
00112 
00113    res_snmp_dont_stop = 0;
00114    return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0);
00115 }
00116 
00117 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "SNMP [Sub]Agent for Asterisk",
00118       .load = load_module,
00119       .unload = unload_module,
00120       );

Generated on Sat Aug 6 00:39:32 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7