More...
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/wait.h>
#include "snmpstats.h"
#include "snmpstats_globals.h"
#include "../../timer.h"
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "openserSIPRegUserTable.h"
#include "openserSIPContactTable.h"
#include "interprocess_buffer.h"
#include "hashTable.h"
#include "alarm_checks.h"
#include "utilities.h"
#include "sub_agent.h"

Go to the source code of this file.
Functions | |
| static int | mod_child_init (int rank) |
| static void | mod_destroy (void) |
| static int | mod_init (void) |
| static int | register_message_code_statistics (void) |
| int | set_snmp_community (modparam_t type, void *val) |
| int | set_snmpget_path (modparam_t type, void *val) |
| static void | sigchld_handler (int signal) |
| static int | spawn_sysUpTime_child () |
Variables | |
| char * | in_message_code_names [] |
| stat_var ** | in_message_code_stats = NULL |
| static struct sigaction | old_sigchld_handler |
| char * | out_message_code_names [] |
| stat_var ** | out_message_code_stats = NULL |
| char * | snmp_community = NULL |
| char * | snmpget_path = NULL |
| MODULE_VERSION volatile pid_t | sysUpTime_pid |
Definition in file snmpstats.c.
| static int mod_child_init | ( | int | rank | ) | [static] |
This function is called when Kamailio has finished creating all instances of itself. It is at this point that we want to create our AgentX sub-agent process, and register a handler for any state changes of our child.
Definition at line 276 of file snmpstats.c.
References PROC_MAIN, and spawn_sysUpTime_child().
| static void mod_destroy | ( | void | ) | [static] |
This function is called when Kamailio is shutting down. When this happens, we log a useful message and kill the AgentX Sub-Agent child process
Definition at line 291 of file snmpstats.c.
References freeInterprocessBuffer(), and LM_INFO.
| static int mod_init | ( | void | ) | [static] |
This is the first function to be called by Kamailio, to initialize the module. This call must always return a value as soon as possible. If it were not to return, then Kamailio would not be able to initialize any of the other modules.
Definition at line 231 of file snmpstats.c.
References ALARM_AGENT_FREQUENCY_IN_SECONDS, initInterprocessBuffers(), register_message_code_statistics(), register_timer(), registerForUSRLOCCallbacks(), and run_alarm_check().
| static int register_message_code_statistics | ( | void | ) | [static] |
Adds the message code statistics to the statistics framework
Definition at line 190 of file snmpstats.c.
References in_message_code_names, NULL, out_message_code_names, register_stat, shm_malloc(), and SNMPSTATS_MODULE_NAME.
Referenced by mod_init().
| int set_snmp_community | ( | modparam_t | type, | |
| void * | val | |||
| ) |
Handles setting of the snmp community string.
Definition at line 483 of file snmpstats.c.
References snmp_community, and stringHandlerSanityCheck().
| int set_snmpget_path | ( | modparam_t | type, | |
| void * | val | |||
| ) |
This function is called whenever the kamailio.cfg file specifies the snmpgetPath parameter. The function will set the snmpget_path parameter.
Definition at line 471 of file snmpstats.c.
References snmpget_path, and stringHandlerSanityCheck().
| static void sigchld_handler | ( | int | signal | ) | [static] |
The SNMPStats module forks off a child process to run an snmp command via execve(). We need a customized handler to catch and ignore its SIGCHLD when it terminates. We also need to make sure to forward other processes SIGCHLD's to Kamailio's usual SIGCHLD handler. We do this by resetting back Kamailio's own signal handlers after we caught our appropriate SIGCHLD.
Definition at line 306 of file snmpstats.c.
References NULL, old_sigchld_handler, and sysUpTime_pid.
Referenced by spawn_sysUpTime_child().
| static int spawn_sysUpTime_child | ( | void | ) | [static] |
The functions spawns a sysUpTime child. See the function definition below for a full description.
This function will spawn a child that retrieves the sysUpTime and stores the result in a file. This file will be read by the AgentX Sub-agent process to supply the openserSIPServiceStartTime time. This function never returns, but it will generated a SIGCHLD when it terminates. There must a SIGCHLD handler to ignore the SIGCHLD for only this process. (See sigchld_handler above).
Definition at line 355 of file snmpstats.c.
References LM_ERR, LM_INFO, NULL, old_sigchld_handler, sigchld_handler(), snmp_community, snmpget_path, SNMPGET_TEMP_FILE, SYSUPTIME_OID, and sysUpTime_pid.
Referenced by mod_child_init().
| char* in_message_code_names[] |
The following message codes are from Wikipedia at:
http://en.wikipedia.org/wiki/SIP_Responses
If there are more message codes added at a later time, they should be added here, and to out_message_code_names below.
The array is used to register the statistics keeping track of the number of messages received with the response code X.
Definition at line 137 of file snmpstats.c.
Referenced by register_message_code_statistics().
| stat_var** in_message_code_stats = NULL |
message_code_stat_array[0] will be the data source for message_code_array[0] message_code_stat_array[3] will be the data source for message_code_array[3] and so on.
Definition at line 186 of file snmpstats.c.
struct sigaction old_sigchld_handler [static] |
This module replaces the default SIGCHLD handler with our own, as explained in the documentation for sysUpTime_pid above. This structure holds the old handler so we can call and restore Kamailio's usual handler when appropriate
Definition at line 125 of file snmpstats.c.
Referenced by sigchld_handler(), and spawn_sysUpTime_child().
| char* out_message_code_names[] |
The following message codes are from Wikipedia at:
http://en.wikipedia.org/wiki/SIP_Responses
If there are more message codes added at a later time, they should be added here, and to in_message_code_names above.
The array is used to register the statistics keeping track of the number of messages send out with the response code X.
Definition at line 165 of file snmpstats.c.
Referenced by register_message_code_statistics().
| stat_var** out_message_code_stats = NULL |
Definition at line 187 of file snmpstats.c.
| char* snmp_community = NULL |
Definition at line 118 of file snmpstats.c.
Referenced by set_snmp_community(), and spawn_sysUpTime_child().
| char* snmpget_path = NULL |
Storage for the "snmpgetPath" and "snmpCommunity" kamailio.cfg parameters. The parameters are used to define what happens with the sysUpTime child.
Definition at line 117 of file snmpstats.c.
Referenced by set_snmpget_path(), and spawn_sysUpTime_child().
| MODULE_VERSION volatile pid_t sysUpTime_pid |
The module will fork off a child process to run an snmp command via execve(). We need a customized handler to ignore the SIGCHLD when the execve() finishes. We keep around the child process's pid for the customized handler.
Specifically, If the process that generated the SIGCHLD doesn't match this pid, we call Kamailio's default handlers. Otherwise, we just ignore SIGCHLD.
Definition at line 109 of file snmpstats.c.
Referenced by sigchld_handler(), and spawn_sysUpTime_child().
1.5.6