Sat Aug 6 00:40:04 2011

Asterisk developer's documentation


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"

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)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
static const struct ast_module_infoast_module_info = &__mod_info
int res_snmp_agentx_subagent
int res_snmp_dont_stop
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>
ExtRef:
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 33 of file res_snmp.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 120 of file res_snmp.c.

static void __unreg_module ( void   )  [static]

Definition at line 120 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 45 of file res_snmp.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load(), ast_false(), ast_log(), ast_true(), ast_variable_browse(), LOG_ERROR, LOG_WARNING, and var.

00046 {
00047    struct ast_variable *var;
00048    struct ast_config *cfg;
00049    char *cat;
00050 
00051    res_snmp_enabled = 0;
00052    res_snmp_agentx_subagent = 1;
00053    cfg = ast_config_load("res_snmp.conf");
00054    if (!cfg) {
00055       ast_log(LOG_WARNING, "Could not load res_snmp.conf\n");
00056       return 0;
00057    }
00058    cat = ast_category_browse(cfg, NULL);
00059    while (cat) {
00060       var = ast_variable_browse(cfg, cat);
00061 
00062       if (strcasecmp(cat, "general") == 0) {
00063          while (var) {
00064             if (strcasecmp(var->name, "subagent") == 0) {
00065                if (ast_true(var->value))
00066                   res_snmp_agentx_subagent = 1;
00067                else if (ast_false(var->value))
00068                   res_snmp_agentx_subagent = 0;
00069                else {
00070                   ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value);
00071                   ast_config_destroy(cfg);
00072                   return 1;
00073                }
00074             } else if (strcasecmp(var->name, "enabled") == 0) {
00075                res_snmp_enabled = ast_true(var->value);
00076             } else {
00077                ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
00078                ast_config_destroy(cfg);
00079                return 1;
00080             }
00081             var = var->next;
00082          }
00083       } else {
00084          ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
00085          ast_config_destroy(cfg);
00086          return 1;
00087       }
00088 
00089       cat = ast_category_browse(cfg, cat);
00090    }
00091    ast_config_destroy(cfg);
00092    return 1;
00093 }

static int load_module ( void   )  [static]

Definition at line 95 of file res_snmp.c.

References AST_MODULE_LOAD_DECLINE, ast_pthread_create_background, ast_verbose(), load_config(), and VERBOSE_PREFIX_1.

00096 {
00097    if(!load_config())
00098       return AST_MODULE_LOAD_DECLINE;
00099 
00100    ast_verbose(VERBOSE_PREFIX_1 "Loading [Sub]Agent Module\n");
00101 
00102    res_snmp_dont_stop = 1;
00103    if (res_snmp_enabled)
00104       return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
00105    else
00106       return 0;
00107 }

static int unload_module ( void   )  [static]

Definition at line 109 of file res_snmp.c.

References AST_PTHREADT_NULL, ast_verbose(), and VERBOSE_PREFIX_1.

00110 {
00111    ast_verbose(VERBOSE_PREFIX_1 "Unloading [Sub]Agent Module\n");
00112 
00113    res_snmp_dont_stop = 0;
00114    return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0);
00115 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 120 of file res_snmp.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 120 of file res_snmp.c.

int res_snmp_agentx_subagent

Definition at line 35 of file res_snmp.c.

int res_snmp_dont_stop

Definition at line 36 of file res_snmp.c.

int res_snmp_enabled

Definition at line 37 of file res_snmp.c.

pthread_t thread = AST_PTHREADT_NULL [static]

Definition at line 39 of file res_snmp.c.


Generated on Sat Aug 6 00:40:04 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7