res_snmp.c File Reference

SNMP Agent / SubAgent support for Asterisk. More...

#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "snmp/agent.h"

Include dependency graph for res_snmp.c:

Go to the source code of this file.

Defines

#define MODULE_DESCRIPTION   "SNMP [Sub]Agent for Asterisk"

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int load_config (void)
 Load res_snmp.conf config file.
static int load_module (void)
 Load the module.
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "SNMP [Sub]Agent for Asterisk" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, }
static struct ast_module_infoast_module_info = &__mod_info
int res_snmp_agentx_subagent
int res_snmp_dont_stop
static int res_snmp_enabled
static pthread_t thread = AST_PTHREADT_NULL


Detailed Description

SNMP Agent / SubAgent support for Asterisk.

Author:
Thorsten Lockert <tholo@voop.as>
Uses the Net-SNMP libraries available at http://net-snmp.sourceforge.net/

Definition in file res_snmp.c.


Define Documentation

#define MODULE_DESCRIPTION   "SNMP [Sub]Agent for Asterisk"

Definition at line 43 of file res_snmp.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 142 of file res_snmp.c.

static void __unreg_module ( void   )  [static]

Definition at line 142 of file res_snmp.c.

static int load_config ( void   )  [static]

Load res_snmp.conf config file.

Returns:
1 on load, 0 file does not exist

Definition at line 55 of file res_snmp.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load, ast_false(), ast_log, ast_true(), ast_variable_browse(), CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, ast_variable::value, and var.

00056 {
00057    struct ast_variable *var;
00058    struct ast_config *cfg;
00059    struct ast_flags config_flags = { 0 };
00060    char *cat;
00061 
00062    res_snmp_enabled = 0;
00063    res_snmp_agentx_subagent = 1;
00064    cfg = ast_config_load("res_snmp.conf", config_flags);
00065    if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
00066       ast_log(LOG_WARNING, "Could not load res_snmp.conf\n");
00067       return 0;
00068    }
00069    cat = ast_category_browse(cfg, NULL);
00070    while (cat) {
00071       var = ast_variable_browse(cfg, cat);
00072 
00073       if (strcasecmp(cat, "general") == 0) {
00074          while (var) {
00075             if (strcasecmp(var->name, "subagent") == 0) {
00076                if (ast_true(var->value))
00077                   res_snmp_agentx_subagent = 1;
00078                else if (ast_false(var->value))
00079                   res_snmp_agentx_subagent = 0;
00080                else {
00081                   ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value);
00082                   ast_config_destroy(cfg);
00083                   return 1;
00084                }
00085             } else if (strcasecmp(var->name, "enabled") == 0) {
00086                res_snmp_enabled = ast_true(var->value);
00087             } else {
00088                ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
00089                ast_config_destroy(cfg);
00090                return 1;
00091             }
00092             var = var->next;
00093          }
00094       } else {
00095          ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
00096          ast_config_destroy(cfg);
00097          return 1;
00098       }
00099 
00100       cat = ast_category_browse(cfg, cat);
00101    }
00102    ast_config_destroy(cfg);
00103    return 1;
00104 }

static int load_module ( void   )  [static]

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.

Definition at line 116 of file res_snmp.c.

References agent_thread(), AST_MODULE_LOAD_DECLINE, ast_pthread_create_background, ast_verb, load_config(), and NULL.

00117 {
00118    if(!load_config())
00119       return AST_MODULE_LOAD_DECLINE;
00120 
00121    ast_verb(1, "Loading [Sub]Agent Module\n");
00122 
00123    res_snmp_dont_stop = 1;
00124    if (res_snmp_enabled)
00125       return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
00126    else
00127       return 0;
00128 }

static int unload_module ( void   )  [static]

Definition at line 130 of file res_snmp.c.

References AST_PTHREADT_NULL, ast_verb, and NULL.

00131 {
00132    ast_verb(1, "Unloading [Sub]Agent Module\n");
00133 
00134    res_snmp_dont_stop = 0;
00135    return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0);
00136 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "SNMP [Sub]Agent for Asterisk" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, } [static]

Definition at line 142 of file res_snmp.c.

Definition at line 142 of file res_snmp.c.

Definition at line 45 of file res_snmp.c.

Referenced by agent_thread().

Definition at line 46 of file res_snmp.c.

Referenced by agent_thread().

int res_snmp_enabled [static]

Definition at line 47 of file res_snmp.c.

pthread_t thread = AST_PTHREADT_NULL [static]

Definition at line 49 of file res_snmp.c.


Generated on Thu Apr 16 06:33:22 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6