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 "snmp/agent.h"
|
|
|
|
|
|
|
|
#define MODULE_DESCRIPTION "SNMP [Sub]Agent for Asterisk"
|
|
|
|
|
|
|
|
int res_snmp_agentx_subagent;
|
|
|
|
int res_snmp_dont_stop;
|
2009-06-15 17:34:30 +00:00
|
|
|
static int res_snmp_enabled;
|
2006-02-26 20:46:11 +00:00
|
|
|
|
2006-03-25 23:50:09 +00:00
|
|
|
static pthread_t thread = AST_PTHREADT_NULL;
|
2006-02-26 20:46:11 +00:00
|
|
|
|
2007-07-23 14:32:04 +00:00
|
|
|
/*!
|
|
|
|
* \brief Load res_snmp.conf config file
|
|
|
|
* \return 1 on load, 0 file does not exist
|
|
|
|
*/
|
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;
|
2007-08-16 21:09:46 +00:00
|
|
|
struct ast_flags config_flags = { 0 };
|
2006-08-11 13:42:49 +00:00
|
|
|
char *cat;
|
|
|
|
|
2006-02-26 20:46:11 +00:00
|
|
|
res_snmp_enabled = 0;
|
|
|
|
res_snmp_agentx_subagent = 1;
|
2007-08-16 21:09:46 +00:00
|
|
|
cfg = ast_config_load("res_snmp.conf", config_flags);
|
2008-09-12 23:30:03 +00:00
|
|
|
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
|
2006-08-31 21:00:20 +00:00
|
|
|
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
|
|
|
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(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
|
|
|
{
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(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
|
|
|
}
|
|
|
|
|
2009-03-18 02:21:23 +00:00
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "SNMP [Sub]Agent for Asterisk",
|
2006-08-21 02:11:39 +00:00
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
|
|
|
);
|