diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-19 00:19:29 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-19 00:19:29 +0000 |
commit | f8247040e6231c4b3b5099ea3a526348b7941566 (patch) | |
tree | 0cc92ad6ebf6ae49a62f6e7ef8ec819121d63630 /trunk/res/res_snmp.c | |
parent | d88e56c61ce2042544c1a8a71c93b69ab2e6ffba (diff) |
Creating tag for the release of asterisk-1.6.0-beta1v1.6.0-beta1
git-svn-id: http://svn.digium.com/svn/asterisk/tags/1.6.0-beta1@99163 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'trunk/res/res_snmp.c')
-rw-r--r-- | trunk/res/res_snmp.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/trunk/res/res_snmp.c b/trunk/res/res_snmp.c new file mode 100644 index 000000000..71a79f209 --- /dev/null +++ b/trunk/res/res_snmp.c @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2006 Voop as + * Thorsten Lockert <tholo@voop.as> + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * + * \brief SNMP Agent / SubAgent support for Asterisk + * + * \author Thorsten Lockert <tholo@voop.as> + * + * \extref Uses the Net-SNMP libraries available at + * http://net-snmp.sourceforge.net/ + */ + +/*** MODULEINFO + <depend>netsnmp</depend> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/channel.h" +#include "asterisk/module.h" + +#include "snmp/agent.h" + +#define MODULE_DESCRIPTION "SNMP [Sub]Agent for Asterisk" + +int res_snmp_agentx_subagent; +int res_snmp_dont_stop; +int res_snmp_enabled; + +static pthread_t thread = AST_PTHREADT_NULL; + +/*! + * \brief Load res_snmp.conf config file + * \return 1 on load, 0 file does not exist +*/ +static int load_config(void) +{ + struct ast_variable *var; + struct ast_config *cfg; + struct ast_flags config_flags = { 0 }; + char *cat; + + res_snmp_enabled = 0; + res_snmp_agentx_subagent = 1; + cfg = ast_config_load("res_snmp.conf", config_flags); + if (!cfg) { + ast_log(LOG_WARNING, "Could not load res_snmp.conf\n"); + return 0; + } + cat = ast_category_browse(cfg, NULL); + while (cat) { + var = ast_variable_browse(cfg, cat); + + if (strcasecmp(cat, "general") == 0) { + while (var) { + if (strcasecmp(var->name, "subagent") == 0) { + if (ast_true(var->value)) + res_snmp_agentx_subagent = 1; + else if (ast_false(var->value)) + res_snmp_agentx_subagent = 0; + else { + ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value); + ast_config_destroy(cfg); + return 1; + } + } else if (strcasecmp(var->name, "enabled") == 0) { + res_snmp_enabled = ast_true(var->value); + } else { + ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat); + ast_config_destroy(cfg); + return 1; + } + var = var->next; + } + } else { + ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat); + ast_config_destroy(cfg); + return 1; + } + + cat = ast_category_browse(cfg, cat); + } + ast_config_destroy(cfg); + return 1; +} + +static int load_module(void) +{ + if(!load_config()) + return AST_MODULE_LOAD_DECLINE; + + ast_verb(1, "Loading [Sub]Agent Module\n"); + + res_snmp_dont_stop = 1; + if (res_snmp_enabled) + return ast_pthread_create_background(&thread, NULL, agent_thread, NULL); + else + return 0; +} + +static int unload_module(void) +{ + ast_verb(1, "Unloading [Sub]Agent Module\n"); + + res_snmp_dont_stop = 0; + return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0); +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "SNMP [Sub]Agent for Asterisk", + .load = load_module, + .unload = unload_module, + ); |