[Nagiosplug-checkins] nagiosplug/plugins check_snmp.c,1.53,1.54

Harper Mann harpermann at users.sourceforge.net
Tue Apr 5 14:28:48 CEST 2005


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10733

Modified Files:
	check_snmp.c 
Log Message:
This is a first cut at adding performance data to check_snmp.  I wasn't sure
how to handle UOM so only values that return SNMP type Counter32: are labled
with "c".  All other values have a blank UOM.  I also left off warn, crit, 
max and min values in the performance data until we come up with a way to 
handle them.


Index: check_snmp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_snmp.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- check_snmp.c	21 Jan 2005 01:03:56 -0000	1.53
+++ check_snmp.c	5 Apr 2005 21:26:56 -0000	1.54
@@ -82,6 +82,7 @@
 regmatch_t pmatch[10];
 char timestamp[10] = "";
 char errbuf[MAX_INPUT_BUFFER];
+char perfstr[MAX_INPUT_BUFFER];
 int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
 int eflags = 0;
 int errcode, excode;
@@ -136,6 +137,7 @@
 	char *ptr = NULL;
 	char *p2 = NULL;
 	char *show = NULL;
+	char type[8];
 
 	setlocale (LC_ALL, "");
 	bindtextdomain (PACKAGE, LOCALEDIR);
@@ -153,7 +155,7 @@
 	port = strdup (DEFAULT_PORT);
 	outbuff = strdup ("");
 	output = strdup ("");
-	delimiter = strdup (DEFAULT_DELIMITER);
+	delimiter = strdup (" = ");
 	output_delim = strdup (DEFAULT_OUTPUT_DELIMITER);
 	miblist = strdup (DEFAULT_MIBLIST);
 	timeout_interval = DEFAULT_TIMEOUT;
@@ -189,9 +191,14 @@
 
 	ptr = output;
 
+	strcat(perfstr, "| ");
 	while (ptr) {
+		char *foo;
+
+		foo = strstr (ptr, delimiter);
+		strncat(perfstr, ptr, foo-ptr);
+		ptr = foo; 
 
-		ptr = strstr (ptr, delimiter);
 		if (ptr == NULL)
 			break;
 
@@ -227,8 +234,10 @@
 			show = strstr (response, "Gauge: ") + 7;
 		else if (strstr (response, "Gauge32: "))
 			show = strstr (response, "Gauge32: ") + 9;
-		else if (strstr (response, "Counter32: "))
+		else if (strstr (response, "Counter32: ")) {
 			show = strstr (response, "Counter32: ") + 11;
+			strcpy(type, "c");
+		}
 		else if (strstr (response, "INTEGER: "))
 			show = strstr (response, "INTEGER: ") + 9;
 		else if (strstr (response, "STRING: "))
@@ -317,7 +326,11 @@
 
 		i++;
 
-	}															/* end while (ptr) */
+		char *str[MAX_INPUT_BUFFER];
+		asprintf(str, "=%s%s;;;; ", show, type ? type : "");
+		strcat(perfstr, *str);
+
+	}	/* end while (ptr) */
 
 	if (found == 0)
 		die (STATE_UNKNOWN,
@@ -339,7 +352,7 @@
 /* 	if (nunits == 1 || i == 1) */
 /* 		printf ("%s %s -%s %s\n", label, state_text (result), outbuff, units); */
 /* 	else */
-	printf ("%s %s -%s\n", label, state_text (result), outbuff);
+	printf ("%s %s -%s %s \n", label, state_text (result), outbuff, perfstr);
 
 	return result;
 }





More information about the Commits mailing list