2 * Copyright (C) 2006 Voop as
3 * Thorsten Lockert <tholo@voop.as>
5 * This program is free software, distributed under the terms of
6 * the GNU General Public License Version 2. See the LICENSE file
7 * at the top of the source tree.
12 * \brief SNMP Agent / SubAgent support for Asterisk
14 * \author Thorsten Lockert <tholo@voop.as>
18 <depend>netsnmp</depend>
23 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
25 #include "asterisk/channel.h"
26 #include "asterisk/module.h"
27 #include "asterisk/logger.h"
28 #include "asterisk/options.h"
30 #include "snmp/agent.h"
32 #define MODULE_DESCRIPTION "SNMP [Sub]Agent for Asterisk"
34 int res_snmp_agentx_subagent
;
35 int res_snmp_dont_stop
;
38 static pthread_t thread
= AST_PTHREADT_NULL
;
40 static int load_config(void)
42 struct ast_variable
*var
;
43 struct ast_config
*cfg
;
47 res_snmp_agentx_subagent
= 1;
48 cfg
= ast_config_load("res_snmp.conf");
50 ast_log(LOG_WARNING
, "Could not load res_snmp.conf\n");
53 cat
= ast_category_browse(cfg
, NULL
);
55 var
= ast_variable_browse(cfg
, cat
);
57 if (strcasecmp(cat
, "general") == 0) {
59 if (strcasecmp(var
->name
, "subagent") == 0) {
60 if (ast_true(var
->value
))
61 res_snmp_agentx_subagent
= 1;
62 else if (ast_false(var
->value
))
63 res_snmp_agentx_subagent
= 0;
65 ast_log(LOG_ERROR
, "Value '%s' does not evaluate to true or false.\n", var
->value
);
66 ast_config_destroy(cfg
);
69 } else if (strcasecmp(var
->name
, "enabled") == 0) {
70 res_snmp_enabled
= ast_true(var
->value
);
72 ast_log(LOG_ERROR
, "Unrecognized variable '%s' in category '%s'\n", var
->name
, cat
);
73 ast_config_destroy(cfg
);
79 ast_log(LOG_ERROR
, "Unrecognized category '%s'\n", cat
);
80 ast_config_destroy(cfg
);
84 cat
= ast_category_browse(cfg
, cat
);
86 ast_config_destroy(cfg
);
90 static int load_module(void)
93 return AST_MODULE_LOAD_DECLINE
;
95 ast_verbose(VERBOSE_PREFIX_1
"Loading [Sub]Agent Module\n");
97 res_snmp_dont_stop
= 1;
99 return ast_pthread_create_background(&thread
, NULL
, agent_thread
, NULL
);
104 static int unload_module(void)
106 ast_verbose(VERBOSE_PREFIX_1
"Unloading [Sub]Agent Module\n");
108 res_snmp_dont_stop
= 0;
109 return ((thread
!= AST_PTHREADT_NULL
) ? pthread_join(thread
, NULL
) : 0);
112 AST_MODULE_INFO(ASTERISK_GPL_KEY
, AST_MODFLAG_GLOBAL_SYMBOLS
, "SNMP [Sub]Agent for Asterisk",
114 .unload
= unload_module
,