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
|
|
|
*
|
2012-09-21 17:14:59 +00:00
|
|
|
* Uses the Net-SNMP libraries available at
|
2007-02-24 19:27:50 +00:00
|
|
|
* http://net-snmp.sourceforge.net/
|
2006-02-26 20:46:11 +00:00
|
|
|
*/
|
|
|
|
|
2012-10-14 21:44:27 +00:00
|
|
|
/*! \li \ref res_snmp.c uses the configuration file \ref res_snmp.conf
|
2012-10-01 23:24:10 +00:00
|
|
|
* \addtogroup configuration_file Configuration Files
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \page res_snmp.conf res_snmp.conf
|
|
|
|
* \verbinclude res_snmp.conf.sample
|
|
|
|
*/
|
|
|
|
|
2006-04-24 17:11:45 +00:00
|
|
|
/*** MODULEINFO
|
2006-06-23 01:50:55 +00:00
|
|
|
<depend>netsnmp</depend>
|
2011-07-14 20:28:54 +00:00
|
|
|
<support_level>extended</support_level>
|
2006-04-24 17:11:45 +00:00
|
|
|
***/
|
|
|
|
|
2006-02-26 20:46:11 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2012-10-01 23:24:10 +00:00
|
|
|
/*!
|
|
|
|
* \brief Load the module
|
|
|
|
*
|
|
|
|
* Module loading including tests for configuration or dependencies.
|
|
|
|
* This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
|
|
|
|
* or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
|
|
|
|
* tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
|
|
|
|
* configuration file or other non-critical problem return
|
|
|
|
* AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
|
|
|
|
*/
|
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",
|
2015-05-06 00:49:04 +00:00
|
|
|
.support_level = AST_MODULE_SUPPORT_EXTENDED,
|
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
|
|
|
);
|