packages: nagios-snmp-plugins/check_snmp_load.patch - reindent - fix report...

glen glen at pld-linux.org
Tue Sep 15 10:36:33 CEST 2009


Author: glen                         Date: Tue Sep 15 08:36:33 2009 GMT
Module: packages                      Tag: HEAD
---- Log message:
- reindent
- fix reporting when not all error levels are met

---- Files affected:
packages/nagios-snmp-plugins:
   check_snmp_load.patch (1.1 -> 1.2) 

---- Diffs:

================================================================
Index: packages/nagios-snmp-plugins/check_snmp_load.patch
diff -u packages/nagios-snmp-plugins/check_snmp_load.patch:1.1 packages/nagios-snmp-plugins/check_snmp_load.patch:1.2
--- packages/nagios-snmp-plugins/check_snmp_load.patch:1.1	Tue Sep 15 10:00:55 2009
+++ packages/nagios-snmp-plugins/check_snmp_load.patch	Tue Sep 15 10:36:27 2009
@@ -26,8 +26,8 @@
  check_snmp_swap.o: check_snmp_swap.c snmp_common.h
 +check_snmp_load.o: check_snmp_load.c snmp_common.h
 --- /dev/null	2006-03-28 14:00:37.000000000 +0300
-+++ nagios-snmp-plugins-1.2-load/check_snmp_load.c	2009-09-15 10:31:06.203940494 +0300
-@@ -0,0 +1,204 @@
++++ nagios-snmp-plugins-1.2/check_snmp_load.c	2009-09-15 11:34:52.330223445 +0300
+@@ -0,0 +1,191 @@
 +/*************************************************************************
 + *
 + * plugins for Nagios
@@ -64,171 +64,158 @@
 +
 +int main (int argc, char *argv[])
 +{
-+  static struct option long_options[] = {
-+    { "help",      no_argument,       0, 'h' },
-+    { "version",   no_argument,       0, 'V' },
-+    { "timeout",   required_argument, 0, 't' },
-+    { "community", required_argument, 0, 'C' },
-+    { "hostname",  required_argument, 0, 'H' },
-+    { "verbose",   no_argument,       0, 'v' },
-+    { 0, 0, 0, 0 },
-+  };
-+  int option_index = 0;
-+  int c;
++	static struct option long_options[] = {
++		{ "help",      no_argument,       0, 'h' },
++		{ "version",   no_argument,       0, 'V' },
++		{ "timeout",   required_argument, 0, 't' },
++		{ "community", required_argument, 0, 'C' },
++		{ "hostname",  required_argument, 0, 'H' },
++		{ "verbose",   no_argument,       0, 'v' },
++		{ 0, 0, 0, 0 },
++	};
++	int option_index = 0;
++	int c;
 +
-+  int ret = STATE_UNKNOWN;
++	int ret = STATE_UNKNOWN;
 +
-+  bn = strdup(basename(argv[0]));
-+  version = VERSION;
++	bn = strdup(basename(argv[0]));
++	version = VERSION;
 +
 +#define OPTS "?hVvt:c:w:C:H:"
-+  
-+  while(1)
-+  {
-+    c = getopt_long(argc, argv, OPTS, long_options, &option_index);
-+
-+    if(c == -1 || c == EOF)
-+      break;
-+
-+    switch(c)
-+    {
-+      case '?':
-+      case 'h':
-+        print_help();
-+        exit(STATE_UNKNOWN);
-+
-+      case 'V':
-+        print_version();
-+        exit(STATE_UNKNOWN);
-+
-+
-+      case 't':
-+        if(!is_integer(optarg))
-+        {
-+          printf("%s: Timeout interval (%s)must be integer!\n",
-+                 bn,
-+                 optarg);
-+          exit(STATE_UNKNOWN);
-+        }
-+        
-+        timeout = atoi(optarg);
-+        if(verbose)
-+          printf("%s: Timeout set to %d\n", bn, timeout);
-+        break;
-+
-+      case 'C':
-+        community = strdup(optarg);
-+
-+        if(verbose)
-+          printf("%s: Community set to %s\n", bn, community);
-+        
-+        break;
-+
-+      case 'H':
-+        hostname = strdup(optarg);
-+
-+        if(verbose)
-+          printf("%s: Hostname set to %s\n", bn, hostname);
-+
-+        break;
-+
-+      case 'v':
-+        verbose = 1;
-+        printf("%s: Verbose mode activated\n", bn);
-+        break;
-+    }
-+  }
-+
-+  if(!hostname || !community)
-+  {
-+    printf("%s: Hostname or Community missing!\n", bn);
-+    print_help();
-+    exit(STATE_UNKNOWN);
-+  }
 +
-+  ret = report_load();
++	while(1) {
++		c = getopt_long(argc, argv, OPTS, long_options, &option_index);
 +
-+  if(verbose)
-+    printf("%s: Returning %d\n", bn, ret);
++		if (c == -1 || c == EOF) {
++			break;
++		}
++
++		switch(c) {
++			case '?':
++			case 'h':
++				print_help();
++				exit(STATE_UNKNOWN);
++
++			case 'V':
++				print_version();
++				exit(STATE_UNKNOWN);
++
++			case 't':
++				if (!is_integer(optarg)) {
++					printf("%s: Timeout interval (%s)must be integer!\n",
++								 bn,
++								 optarg);
++					exit(STATE_UNKNOWN);
++				}
++
++				timeout = atoi(optarg);
++				if (verbose) {
++					printf("%s: Timeout set to %d\n", bn, timeout);
++				}
++				break;
++
++			case 'C':
++				community = strdup(optarg);
++
++				if (verbose) {
++					printf("%s: Community set to %s\n", bn, community);
++				}
++
++				break;
++
++			case 'H':
++				hostname = strdup(optarg);
++
++				if (verbose) {
++					printf("%s: Hostname set to %s\n", bn, hostname);
++				}
++
++				break;
++
++			case 'v':
++				verbose = 1;
++				printf("%s: Verbose mode activated\n", bn);
++				break;
++		}
++	}
++
++	if (!hostname || !community) {
++		printf("%s: Hostname or Community missing!\n", bn);
++		print_help();
++		exit(STATE_UNKNOWN);
++	}
++
++	ret = report_load();
++
++	if (verbose) {
++		printf("%s: Returning %d\n", bn, ret);
++	}
 +
-+  exit(ret);
++	exit(ret);
 +}
 +
-+static int report_load()
-+{
-+  int cnt;
++static int report_load() {
++	int cnt;
++	long *errors;
++	void *pnt;
++	int i, j;
++	int nerrors = 0;
++	char **errormsg = NULL;
++
++	if ((cnt = fetch_table(LOAD_INDEX_MIB, null_callback, NULL, 0)) < 0) {
++		printf("%s: Could not fetch mem index\n", bn);
++		return STATE_UNKNOWN;
++	}
++
++	if (!cnt) {
++		printf("%s: Not configured.\n", bn);
++		return STATE_WARNING;
++	}
++
++	if (!(errors = calloc(sizeof(long), cnt))) {
++		printf("%s: Could not allocate memory for information\n", bn);
++		return STATE_CRITICAL;
++	}
++
++	pnt = errors;
++	if (fetch_table(LOAD_ERRORFLAG_MIB, integer_callback, pnt, cnt) < 0) {
++		printf("%s: Could not fetch error list!\n", bn);
++		return STATE_UNKNOWN;
++	}
++
++	for (i = 0; i < cnt; i++) {
++		if (verbose) {
++			printf("%s: Got Flag %ld for %d\n", bn, errors[i], i);
++		}
++
++		if (errors[i]) {
++			nerrors++;
++		}
++	}
++
++	if (nerrors == 0) {
++		printf("Checked load for %d entries.\n", cnt);
++		return STATE_OK;
++	}
++
++	errormsg = calloc(sizeof(char **), cnt);
++	if (!errormsg) {
++		printf("%s: Could not allocate memory for error information\n", bn);
++		return STATE_CRITICAL;
++	}
++
++	pnt = errormsg;
++	if (fetch_table(LOAD_ERRORMSG_MIB, string_callback, pnt, cnt) < 0) {
++		printf("%s: Could not fetch error messages\n", bn);
++		return STATE_CRITICAL;
++	}
++
++	for (j = i = 0; i < cnt; i++) {
++		if (errors[i]) {
++			printf("%s%s", errormsg[i], j == nerrors - 1 ? "\n" : ", ");
++			j++;
++		}
++	}
 +
-+  long *errors;
-+  void *pnt;
-+  int i;
-+  int gotErrors = 0;
-+  char **errormsg = NULL;
-+
-+  
-+  if((cnt = fetch_table(LOAD_INDEX_MIB, null_callback, NULL, 0)) < 0)
-+  {
-+    printf("%s: Could not fetch mem index\n", bn);
-+    return STATE_UNKNOWN;
-+  }
-+
-+  if(!cnt)  // not configured
-+  {
-+    printf("%s: Not configure.\n", bn);
-+    return STATE_WARNING;
-+  }
-+  
-+
-+  if(!(errors  = calloc(sizeof(long), cnt)))
-+  {
-+    printf("%s: Could not allocate memory for information\n", bn);
-+    return STATE_CRITICAL;
-+  }
-+
-+  pnt = errors;
-+  if(fetch_table(LOAD_ERRORFLAG_MIB, integer_callback, pnt, cnt) < 0)
-+  {
-+    printf("%s: Could not fetch error list!\n", bn);
-+    return STATE_UNKNOWN;
-+  }
-+
-+  for(i=0; i<cnt; i++)
-+  {
-+    if(verbose)
-+      printf("%s: Got Flag %ld for %d\n", bn, errors[i], i);
-+
-+    if(errors[i])
-+    {
-+      gotErrors = 1;
-+      break;
-+    }
-+  }
-+
-+  errormsg = calloc(sizeof(char **), cnt);
-+  if(!errormsg)
-+  {
-+    printf("%s: Could not allocate memory for error information\n", bn);
-+    return STATE_CRITICAL;
-+  }
-+
-+  pnt = errormsg;
-+
-+  if(fetch_table(LOAD_ERRORMSG_MIB, string_callback, pnt, cnt) < 0)
-+  {
-+    printf("%s: Could not fetch error messages\n", bn);
-+    return STATE_CRITICAL;
-+  }
-+
-+  for(i=0; i < cnt; i++)
-+  {
-+    if(errors[i])
-+      printf("%s%s", errormsg[i], i == cnt - 1 ? "\n" : ", ");
-+  }
-+
-+  if(gotErrors == 0)
-+  {
-+	printf("Checked load for %d entries.\n", cnt);
-+    return STATE_OK;
-+  }
-+  
-+  return STATE_CRITICAL;
++	return STATE_CRITICAL;
 +}
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/nagios-snmp-plugins/check_snmp_load.patch?r1=1.1&r2=1.2&f=u



More information about the pld-cvs-commit mailing list