Module: kamailio Branch: master Commit: 9f3b344a737f2bf8628be1126e4aa6145963b9bc URL: https://github.com/kamailio/kamailio/commit/9f3b344a737f2bf8628be1126e4aa614...
Author: Marat Gareev maratkin94@gmail.com Committer: Henning Westerholt hw@skalatan.de Date: 2021-09-09T21:42:56+02:00
snmpstats: add parameter to specify SNMP version
---
Modified: src/modules/snmpstats/doc/snmpstats_admin.xml Modified: src/modules/snmpstats/snmpstats.c Modified: src/modules/snmpstats/snmpstats_globals.h
---
Diff: https://github.com/kamailio/kamailio/commit/9f3b344a737f2bf8628be1126e4aa614... Patch: https://github.com/kamailio/kamailio/commit/9f3b344a737f2bf8628be1126e4aa614...
---
diff --git a/src/modules/snmpstats/doc/snmpstats_admin.xml b/src/modules/snmpstats/doc/snmpstats_admin.xml index a6a4f1e3b4..870a8630a0 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") </example> </section>
+ <section id ="snmpstats.p.snmpVersion"> + <title><varname>snmpVersion</varname> (String)</title> + + <para> + 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. + </para> + + <para> + <emphasis> + Default value is <quote>3</quote>. + </emphasis> + </para> + + <example> + <title>Setting the <varname>snmpVersion</varname> parameter</title> + <programlisting format="linespecific"> +... +modparam("snmpstats", "snmpVersion", "2c") +... + </programlisting> + </example> + </section> + <section id ="snmpstats.p.export_registrar"> <title><varname>export_registrar</varname> (int)</title>
diff --git a/src/modules/snmpstats/snmpstats.c b/src/modules/snmpstats/snmpstats.c index a9d8b1fc88..4fae5dad09 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 f40e65d42b..3a01e7ef70 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