Wed Jan 8 2020 09:50:19

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.

Macros

#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. More...
 
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 , .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 = "ac1f6a56484a8820659555499174e588" , .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.nosp@m.@voo.nosp@m.p.as
ExtRef:
Uses the Net-SNMP libraries available at http://net-snmp.sourceforge.net/

Definition in file res_snmp.c.

Macro Definition Documentation

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

Definition at line 34 of file res_snmp.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 122 of file res_snmp.c.

static void __unreg_module ( void  )
static

Definition at line 122 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 46 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, ast_variable::value, and var.

Referenced by load_module().

47 {
48  struct ast_variable *var;
49  struct ast_config *cfg;
50  struct ast_flags config_flags = { 0 };
51  char *cat;
52 
53  res_snmp_enabled = 0;
55  cfg = ast_config_load("res_snmp.conf", config_flags);
57  ast_log(LOG_WARNING, "Could not load res_snmp.conf\n");
58  return 0;
59  }
60  cat = ast_category_browse(cfg, NULL);
61  while (cat) {
62  var = ast_variable_browse(cfg, cat);
63 
64  if (strcasecmp(cat, "general") == 0) {
65  while (var) {
66  if (strcasecmp(var->name, "subagent") == 0) {
67  if (ast_true(var->value))
69  else if (ast_false(var->value))
71  else {
72  ast_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value);
73  ast_config_destroy(cfg);
74  return 1;
75  }
76  } else if (strcasecmp(var->name, "enabled") == 0) {
78  } else {
79  ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
80  ast_config_destroy(cfg);
81  return 1;
82  }
83  var = var->next;
84  }
85  } else {
86  ast_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
87  ast_config_destroy(cfg);
88  return 1;
89  }
90 
91  cat = ast_category_browse(cfg, cat);
92  }
93  ast_config_destroy(cfg);
94  return 1;
95 }
static int res_snmp_enabled
Definition: res_snmp.c:38
#define LOG_WARNING
Definition: logger.h:144
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
#define CONFIG_STATUS_FILEMISSING
Definition: config.h:50
const char * value
Definition: config.h:79
#define ast_config_load(filename, flags)
Load a config file.
Definition: config.h:170
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
const char * name
Definition: config.h:77
#define LOG_ERROR
Definition: logger.h:155
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: utils.c:1533
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
Structure used to handle boolean flags.
Definition: utils.h:200
int res_snmp_agentx_subagent
Definition: res_snmp.c:36
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"...
Definition: utils.c:1550
struct ast_variable * next
Definition: config.h:82
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
static int load_module ( void  )
static

Definition at line 97 of file res_snmp.c.

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

98 {
99  if(!load_config())
101 
102  ast_verb(1, "Loading [Sub]Agent Module\n");
103 
104  res_snmp_dont_stop = 1;
105  if (res_snmp_enabled)
106  return ast_pthread_create_background(&thread, NULL, agent_thread, NULL);
107  else
108  return 0;
109 }
pthread_t thread
Definition: app_meetme.c:962
void * agent_thread(void *arg)
Definition: agent.c:185
static int res_snmp_enabled
Definition: res_snmp.c:38
static int load_config(void)
Load res_snmp.conf config file.
Definition: res_snmp.c:46
#define ast_verb(level,...)
Definition: logger.h:243
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:426
int res_snmp_dont_stop
Definition: res_snmp.c:37
static int unload_module ( void  )
static

Definition at line 111 of file res_snmp.c.

References AST_PTHREADT_NULL, and ast_verb.

112 {
113  ast_verb(1, "Unloading [Sub]Agent Module\n");
114 
115  res_snmp_dont_stop = 0;
116  return ((thread != AST_PTHREADT_NULL) ? pthread_join(thread, NULL) : 0);
117 }
pthread_t thread
Definition: app_meetme.c:962
#define ast_verb(level,...)
Definition: logger.h:243
#define AST_PTHREADT_NULL
Definition: lock.h:65
int res_snmp_dont_stop
Definition: res_snmp.c:37

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, }
static

Definition at line 122 of file res_snmp.c.

Definition at line 122 of file res_snmp.c.

int res_snmp_agentx_subagent

Definition at line 36 of file res_snmp.c.

Referenced by agent_thread().

int res_snmp_dont_stop

Definition at line 37 of file res_snmp.c.

Referenced by agent_thread().

int res_snmp_enabled
static

Definition at line 38 of file res_snmp.c.

pthread_t thread = AST_PTHREADT_NULL
static

Definition at line 40 of file res_snmp.c.