Browse code

Merge a5892ea2e3669c1ed0bf370adec404d02fdc7a36 into 8cd0a5ab8683c7a598499e6b1bbe1fc6a489f531

Marat authored on 09/09/2021 16:00:05 • GitHub committed on 09/09/2021 16:00:05
Showing 3 changed files
... ...
@@ -439,6 +439,32 @@ modparam("snmpstats", "snmpCommunity", "customCommunityString")
439 439
 		</example>
440 440
 	</section>
441 441
 
442
+	<section id ="snmpstats.p.snmpVersion">
443
+		<title><varname>snmpVersion</varname> (String)</title>
444
+
445
+		<para>
446
+		The SNMPStats module provides the kamailioSIPServiceStartTime scalar.
447
+		This scalar requires the SNMPStats module to perform a snmpget query
448
+		to the master agent.  You can use this parameter to set specific
449
+		SNMP version.
450
+		</para>
451
+
452
+		<para>
453
+		<emphasis>
454
+			Default value is <quote>3</quote>.
455
+		</emphasis>
456
+		</para>
457
+
458
+		<example>
459
+		<title>Setting the <varname>snmpVersion</varname> parameter</title>
460
+		<programlisting format="linespecific">
461
+...
462
+modparam("snmpstats", "snmpVersion", "2c")
463
+...
464
+		</programlisting>
465
+		</example>
466
+	</section>
467
+
442 468
 	<section id ="snmpstats.p.export_registrar">
443 469
 		<title><varname>export_registrar</varname> (int)</title>
444 470
 
... ...
@@ -145,6 +145,8 @@ static param_export_t mod_params[] = {
145 145
 			(void *)set_snmpget_path},
146 146
 	{"snmpCommunity", PARAM_STRING | USE_FUNC_PARAM,
147 147
 			(void *)set_snmp_community},
148
+	{"snmpVersion", PARAM_STRING | USE_FUNC_PARAM,
149
+			(void *)set_snmp_version},
148 150
 	{"export_registrar", INT_PARAM, &snmp_export_registrar},
149 151
 	{0, 0, 0}
150 152
 };
... ...
@@ -178,10 +180,11 @@ volatile pid_t sysUpTime_pid;
178 180
  * for a full description. */
179 181
 static int spawn_sysUpTime_child();
180 182
 
181
-/*! Storage for the "snmpgetPath" and "snmpCommunity" kamailio.cfg parameters.
183
+/*! Storage for the "snmpgetPath", "snmpCommunity" and "snmpVersion" kamailio.cfg parameters.
182 184
  * The parameters are used to define what happens with the sysUpTime child.  */
183 185
 char *snmpget_path = NULL;
184 186
 char *snmp_community = NULL;
187
+char *snmp_version = NULL;
185 188
 
186 189
 /*!
187 190
  * This module replaces the default SIGCHLD handler with our own, as explained
... ...
@@ -462,6 +465,7 @@ static int spawn_sysUpTime_child(void)
462 465
 	char *full_path_to_snmpget = NULL;
463 466
 
464 467
 	char *snmp_community_string = "public";
468
+	char *snmp_version_string = "3";
465 469
 
466 470
 	/* Set up a new SIGCHLD handler.  The handler will be responsible for
467 471
 	 * ignoring SIGCHLDs generated by our sysUpTime child process.  Every
... ...
@@ -509,8 +513,16 @@ static int spawn_sysUpTime_child(void)
509 513
 				snmp_community_string);
510 514
 	}
511 515
 
512
-	char *args[] = {"-Ov", "-c", snmp_community_string, "localhost",
513
-			SYSUPTIME_OID, (char *)0};
516
+	if(snmp_version != NULL) {
517
+		snmp_version_string = snmp_version;
518
+	} else {
519
+		LM_INFO("A snmpVersion parameter was not provided."
520
+				"  Defaulting to %s\n",
521
+				snmp_version_string);
522
+	}
523
+
524
+	char *args[] = {"snmpget", "-v", snmp_version_string, "-Ov", "-c",
525
+			snmp_community_string, "localhost", SYSUPTIME_OID, (char *)0};
514 526
 
515 527
 	/* Make sure we have a path to snmpget, so we can retrieve the
516 528
 	 * sysUpTime. */
... ...
@@ -586,3 +598,15 @@ int set_snmp_community(modparam_t type, void *val)
586 598
 
587 599
 	return 0;
588 600
 }
601
+
602
+/* Handles setting of the snmp version. */
603
+int set_snmp_version(modparam_t type, void *val)
604
+{
605
+	if(!stringHandlerSanityCheck(type, val, "snmpVersion")) {
606
+		return -1;
607
+	}
608
+
609
+	snmp_version = (char *)val;
610
+
611
+	return 0;
612
+}
... ...
@@ -159,4 +159,7 @@ int set_snmpget_path(modparam_t type, void *val);
159 159
 /*! Handles setting of the snmp community string. */
160 160
 int set_snmp_community(modparam_t type, void *val);
161 161
 
162
+/*! Handles setting of the snmp version. */
163
+int set_snmp_version(modparam_t type, void *val);
164
+
162 165
 #endif
163 166
\ No newline at end of file