From a5892ea2e3669c1ed0bf370adec404d02fdc7a36 Mon Sep 17 00:00:00 2001 From: Marat Gareev Date: Tue, 7 Sep 2021 20:36:36 +0300 Subject: [PATCH] snmpstats: add parameter to specify SNMP version --- src/modules/snmpstats/doc/snmpstats_admin.xml | 26 ++++++++++++++++ src/modules/snmpstats/snmpstats.c | 30 +++++++++++++++++-- src/modules/snmpstats/snmpstats_globals.h | 3 ++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/modules/snmpstats/doc/snmpstats_admin.xml b/src/modules/snmpstats/doc/snmpstats_admin.xml index a6a4f1e3b43..870a8630a09 100644 --- a/src/modules/snmpstats/doc/snmpstats_admin.xml +++ b/src/modules/snmpstats/doc/snmpstats_admin.xml @@ -439,6 +439,32 @@ modparam("snmpstats", "snmpCommunity", "customCommunityString") +
+ <varname>snmpVersion</varname> (String) + + + The SNMPStats module provides the kamailioSIPServiceStartTime scalar. + This scalar requires the SNMPStats module to perform a snmpget query + to the master agent. You can use this parameter to set specific + SNMP version. + + + + + Default value is 3. + + + + + Setting the <varname>snmpVersion</varname> parameter + +... +modparam("snmpstats", "snmpVersion", "2c") +... + + +
+
<varname>export_registrar</varname> (int) diff --git a/src/modules/snmpstats/snmpstats.c b/src/modules/snmpstats/snmpstats.c index a9d8b1fc88d..4fae5dad09f 100644 --- a/src/modules/snmpstats/snmpstats.c +++ b/src/modules/snmpstats/snmpstats.c @@ -145,6 +145,8 @@ static param_export_t mod_params[] = { (void *)set_snmpget_path}, {"snmpCommunity", PARAM_STRING | USE_FUNC_PARAM, (void *)set_snmp_community}, + {"snmpVersion", PARAM_STRING | USE_FUNC_PARAM, + (void *)set_snmp_version}, {"export_registrar", INT_PARAM, &snmp_export_registrar}, {0, 0, 0} }; @@ -178,10 +180,11 @@ volatile pid_t sysUpTime_pid; * for a full description. */ static int spawn_sysUpTime_child(); -/*! Storage for the "snmpgetPath" and "snmpCommunity" kamailio.cfg parameters. +/*! Storage for the "snmpgetPath", "snmpCommunity" and "snmpVersion" kamailio.cfg parameters. * The parameters are used to define what happens with the sysUpTime child. */ char *snmpget_path = NULL; char *snmp_community = NULL; +char *snmp_version = NULL; /*! * This module replaces the default SIGCHLD handler with our own, as explained @@ -462,6 +465,7 @@ static int spawn_sysUpTime_child(void) char *full_path_to_snmpget = NULL; char *snmp_community_string = "public"; + char *snmp_version_string = "3"; /* Set up a new SIGCHLD handler. The handler will be responsible for * ignoring SIGCHLDs generated by our sysUpTime child process. Every @@ -509,8 +513,16 @@ static int spawn_sysUpTime_child(void) snmp_community_string); } - char *args[] = {"-Ov", "-c", snmp_community_string, "localhost", - SYSUPTIME_OID, (char *)0}; + if(snmp_version != NULL) { + snmp_version_string = snmp_version; + } else { + LM_INFO("A snmpVersion parameter was not provided." + " Defaulting to %s\n", + snmp_version_string); + } + + char *args[] = {"snmpget", "-v", snmp_version_string, "-Ov", "-c", + snmp_community_string, "localhost", SYSUPTIME_OID, (char *)0}; /* Make sure we have a path to snmpget, so we can retrieve the * sysUpTime. */ @@ -586,3 +598,15 @@ int set_snmp_community(modparam_t type, void *val) return 0; } + +/* Handles setting of the snmp version. */ +int set_snmp_version(modparam_t type, void *val) +{ + if(!stringHandlerSanityCheck(type, val, "snmpVersion")) { + return -1; + } + + snmp_version = (char *)val; + + return 0; +} diff --git a/src/modules/snmpstats/snmpstats_globals.h b/src/modules/snmpstats/snmpstats_globals.h index f40e65d42b8..3a01e7ef70c 100644 --- a/src/modules/snmpstats/snmpstats_globals.h +++ b/src/modules/snmpstats/snmpstats_globals.h @@ -159,4 +159,7 @@ int set_snmpget_path(modparam_t type, void *val); /*! Handles setting of the snmp community string. */ int set_snmp_community(modparam_t type, void *val); +/*! Handles setting of the snmp version. */ +int set_snmp_version(modparam_t type, void *val); + #endif \ No newline at end of file