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>
16 * \extref Uses the Net-SNMP libraries available at
17 * http://net-snmp.sourceforge.net/
21 <depend>netsnmp</depend>
26 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
28 #include "asterisk/channel.h"
29 #include "asterisk/module.h"
31 #include "snmp/agent.h"
33 #define MODULE_DESCRIPTION "SNMP [Sub]Agent for Asterisk"
35 int res_snmp_agentx_subagent
;
36 int res_snmp_dont_stop
;
39 static pthread_t thread
= AST_PTHREADT_NULL
;
42 * \brief Load res_snmp.conf config file
43 * \return 1 on load, 0 file does not exist
45 static int load_config(void)
47 struct ast_variable
*var
;
48 struct ast_config
*cfg
;
49 struct ast_flags config_flags
= { 0 };
53 res_snmp_agentx_subagent
= 1;
54 cfg
= ast_config_load("res_snmp.conf", config_flags
);
56 ast_log(LOG_WARNING
, "Could not load res_snmp.conf\n");
59 cat
= ast_category_browse(cfg
, NULL
);
61 var
= ast_variable_browse(cfg
, cat
);
63 if (strcasecmp(cat
, "general") == 0) {
65 if (strcasecmp(var
->name
, "subagent") == 0) {
66 if (ast_true(var
->value
))
67 res_snmp_agentx_subagent
= 1;
68 else if (ast_false(var
->value
))
69 res_snmp_agentx_subagent
= 0;
71 ast_log(LOG_ERROR
, "Value '%s' does not evaluate to true or false.\n", var
->value
);
72 ast_config_destroy(cfg
);
75 } else if (strcasecmp(var
->name
, "enabled") == 0) {
76 res_snmp_enabled
= ast_true(var
->value
);
78 ast_log(LOG_ERROR
, "Unrecognized variable '%s' in category '%s'\n", var
->name
, cat
);
79 ast_config_destroy(cfg
);
85 ast_log(LOG_ERROR
, "Unrecognized category '%s'\n", cat
);
86 ast_config_destroy(cfg
);
90 cat
= ast_category_browse(cfg
, cat
);
92 ast_config_destroy(cfg
);
96 static int load_module(void)
99 return AST_MODULE_LOAD_DECLINE
;
101 ast_verb(1, "Loading [Sub]Agent Module\n");
103 res_snmp_dont_stop
= 1;
104 if (res_snmp_enabled
)
105 return ast_pthread_create_background(&thread
, NULL
, agent_thread
, NULL
);
110 static int unload_module(void)
112 ast_verb(1, "Unloading [Sub]Agent Module\n");
114 res_snmp_dont_stop
= 0;
115 return ((thread
!= AST_PTHREADT_NULL
) ? pthread_join(thread
, NULL
) : 0);
118 AST_MODULE_INFO(ASTERISK_GPL_KEY
, AST_MODFLAG_GLOBAL_SYMBOLS
, "SNMP [Sub]Agent for Asterisk",
120 .unload
= unload_module
,