2006-02-26 20:46:11 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2007-02-24 19:27:50 +00:00
|
|
|
*
|
|
|
|
* \extref Uses the Net-SNMP libraries available at
|
|
|
|
* http://net-snmp.sourceforge.net/
|
2006-02-26 20:46:11 +00:00
|
|
|
*/
|
|
|
|
|
2006-04-24 17:11:45 +00:00
|
|
|
/*** MODULEINFO
|
2006-06-23 01:50:55 +00:00
|
|
|
<depend>netsnmp</depend>
|
2006-04-24 17:11:45 +00:00
|
|
|
***/
|
|
|
|
|
2006-02-26 20:46:11 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/options.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;
|
|
|
|
|
2006-03-25 23:50:09 +00:00
|
|
|
static pthread_t thread = AST_PTHREADT_NULL;
|
2006-02-26 20:46:11 +00:00
|
|
|
|
|
|
|
static int load_config(void)
|
|
|
|
{
|
2006-08-11 13:42:49 +00:00
|
|
|
struct ast_variable *var;
|
|
|
|
struct ast_config *cfg;
|
|
|
|
char *cat;
|
|
|
|
|
2006-02-26 20:46:11 +00:00
|
|
|
res_snmp_enabled = 0;
|
|
|
|
res_snmp_agentx_subagent = 1;
|
2006-08-11 13:42:49 +00:00
|
|
|
cfg = ast_config_load("res_snmp.conf");
|
2006-08-31 21:00:20 +00:00
|
|
|
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);
|
2006-02-26 20:46:11 +00:00
|
|
|
ast_config_destroy(cfg);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-08-31 21:00:20 +00:00
|
|
|
} 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;
|
2006-02-26 20:46:11 +00:00
|
|
|
}
|
2006-08-31 21:00:20 +00:00
|
|
|
var = var->next;
|
2006-02-26 20:46:11 +00:00
|
|
|
}
|
2006-08-31 21:00:20 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
|
|
|
|
ast_config_destroy(cfg);
|
|
|
|
return 1;
|
2006-02-26 20:46:11 +00:00
|
|
|
}
|
|
|
|
|
2006-08-31 21:00:20 +00:00
|
|
|
cat = ast_category_browse(cfg, cat);
|
|
|
|
}
|
|
|
|
ast_config_destroy(cfg);
|
|
|
|
return 1;
|
2006-02-26 20:46:11 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2006-02-26 20:46:11 +00:00
|
|
|
{
|
2006-08-31 21:00:20 +00:00
|
|
|
if(!load_config())
|
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
2006-02-26 20:46:11 +00:00
|
|
|
|
2006-08-11 13:42:49 +00:00
|
|
|
ast_verbose(VERBOSE_PREFIX_1 "Loading [Sub]Agent Module\n");
|
2006-02-26 20:46:11 +00:00
|
|
|
|
2006-08-11 13:42:49 +00:00
|
|
|
res_snmp_dont_stop = 1;
|
2006-02-26 20:46:11 +00:00
|
|
|
if (res_snmp_enabled)
|
2006-10-04 19:51:38 +00:00
|
|
|
return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
|
2006-02-26 20:46:11 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2006-02-26 20:46:11 +00:00
|
|
|
{
|
2006-08-11 13:42:49 +00:00
|
|
|
ast_verbose(VERBOSE_PREFIX_1 "Unloading [Sub]Agent Module\n");
|
2006-02-26 20:46:11 +00:00
|
|
|
|
2006-08-11 13:42:49 +00:00
|
|
|
res_snmp_dont_stop = 0;
|
2007-01-13 03:06:24 +00:00
|
|
|
return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0);
|
2006-02-26 20:46:11 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "SNMP [Sub]Agent for Asterisk",
|
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
|
|
|
);
|