summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2007-04-15 06:44:46 (GMT)
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2007-04-15 06:44:46 (GMT)
commit6a564052eab2921b7027a259c5578319dbebde7c (patch)
tree317e102b6ab5380e8d51154f88caf0242ec166c3 /plugins
parent8899bc81940c07ade019022bca5c8f64cac64c66 (diff)
downloadmonitoring-plugins-6a564052eab2921b7027a259c5578319dbebde7c.tar.gz
Fix bug #1344584: Counter64 values not handled correctly
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1687 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_snmp.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index c43f1ef..741ad3e 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -3,7 +3,7 @@
3* Nagios check_snmp plugin 3* Nagios check_snmp plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2006 nagios-plugins team 6* Copyright (c) 1999-2007 nagios-plugins team
7* 7*
8* Last Modified: $Date$ 8* Last Modified: $Date$
9* 9*
@@ -11,7 +11,7 @@
11* 11*
12* This file contains the check_snmp plugin 12* This file contains the check_snmp plugin
13* 13*
14* Check status of remote machines and obtain sustem information via SNMP 14* Check status of remote machines and obtain system information via SNMP
15* 15*
16* 16*
17* License Information: 17* License Information:
@@ -36,7 +36,7 @@
36 36
37const char *progname = "check_snmp"; 37const char *progname = "check_snmp";
38const char *revision = "$Revision$"; 38const char *revision = "$Revision$";
39const char *copyright = "1999-2006"; 39const char *copyright = "1999-2007";
40const char *email = "nagiosplug-devel@lists.sourceforge.net"; 40const char *email = "nagiosplug-devel@lists.sourceforge.net";
41 41
42#include "common.h" 42#include "common.h"
@@ -84,8 +84,8 @@ int process_arguments (int, char **);
84int validate_arguments (void); 84int validate_arguments (void);
85char *clarify_message (char *); 85char *clarify_message (char *);
86int check_num (int); 86int check_num (int);
87int lu_getll (unsigned long *, char *); 87int llu_getll (unsigned long long *, char *);
88int lu_getul (unsigned long *, char *); 88int llu_getul (unsigned long long *, char *);
89char *thisarg (char *str); 89char *thisarg (char *str);
90char *nextarg (char *str); 90char *nextarg (char *str);
91void print_usage (void); 91void print_usage (void);
@@ -124,15 +124,15 @@ size_t nunits = 0;
124size_t unitv_size = 8; 124size_t unitv_size = 8;
125int verbose = FALSE; 125int verbose = FALSE;
126int usesnmpgetnext = FALSE; 126int usesnmpgetnext = FALSE;
127unsigned long lower_warn_lim[MAX_OIDS]; 127unsigned long long lower_warn_lim[MAX_OIDS];
128unsigned long upper_warn_lim[MAX_OIDS]; 128unsigned long long upper_warn_lim[MAX_OIDS];
129unsigned long lower_crit_lim[MAX_OIDS]; 129unsigned long long lower_crit_lim[MAX_OIDS];
130unsigned long upper_crit_lim[MAX_OIDS]; 130unsigned long long upper_crit_lim[MAX_OIDS];
131unsigned long response_value[MAX_OIDS]; 131unsigned long long response_value[MAX_OIDS];
132int check_warning_value = FALSE; 132int check_warning_value = FALSE;
133int check_critical_value = FALSE; 133int check_critical_value = FALSE;
134int retries = 0; 134int retries = 0;
135unsigned long eval_method[MAX_OIDS]; 135unsigned long long eval_method[MAX_OIDS];
136char *delimiter; 136char *delimiter;
137char *output_delim; 137char *output_delim;
138char *miblist = NULL; 138char *miblist = NULL;
@@ -268,6 +268,10 @@ main (int argc, char **argv)
268 show = strstr (response, "Counter32: ") + 11; 268 show = strstr (response, "Counter32: ") + 11;
269 strcpy(type, "c"); 269 strcpy(type, "c");
270 } 270 }
271 else if (strstr (response, "Counter64: ")) {
272 show = strstr (response, "Counter64: ") + 11;
273 strcpy(type, "c");
274 }
271 else if (strstr (response, "INTEGER: ")) 275 else if (strstr (response, "INTEGER: "))
272 show = strstr (response, "INTEGER: ") + 9; 276 show = strstr (response, "INTEGER: ") + 9;
273 else if (strstr (response, "STRING: ")) 277 else if (strstr (response, "STRING: "))
@@ -296,7 +300,7 @@ main (int argc, char **argv)
296 die (STATE_UNKNOWN,_("No valid data returned")); 300 die (STATE_UNKNOWN,_("No valid data returned"));
297 response_value[i] = strtoul (p2, NULL, 10); 301 response_value[i] = strtoul (p2, NULL, 10);
298 iresult = check_num (i); 302 iresult = check_num (i);
299 asprintf (&show, "%lu", response_value[i]); 303 asprintf (&show, "%llu", response_value[i]);
300 } 304 }
301 305
302 /* Process this block for string matching */ 306 /* Process this block for string matching */
@@ -501,9 +505,9 @@ process_arguments (int argc, char **argv)
501 if (strspn (optarg, "0123456789:,") < strlen (optarg)) 505 if (strspn (optarg, "0123456789:,") < strlen (optarg))
502 usage2 (_("Invalid critical threshold: %s\n"), optarg); 506 usage2 (_("Invalid critical threshold: %s\n"), optarg);
503 for (ptr = optarg; ptr && jj < MAX_OIDS; jj++) { 507 for (ptr = optarg; ptr && jj < MAX_OIDS; jj++) {
504 if (lu_getll (&lower_crit_lim[jj], ptr) == 1) 508 if (llu_getll (&lower_crit_lim[jj], ptr) == 1)
505 eval_method[jj] |= CRIT_LT; 509 eval_method[jj] |= CRIT_LT;
506 if (lu_getul (&upper_crit_lim[jj], ptr) == 1) 510 if (llu_getul (&upper_crit_lim[jj], ptr) == 1)
507 eval_method[jj] |= CRIT_GT; 511 eval_method[jj] |= CRIT_GT;
508 (ptr = index (ptr, ',')) ? ptr++ : ptr; 512 (ptr = index (ptr, ',')) ? ptr++ : ptr;
509 } 513 }
@@ -512,9 +516,9 @@ process_arguments (int argc, char **argv)
512 if (strspn (optarg, "0123456789:,") < strlen (optarg)) 516 if (strspn (optarg, "0123456789:,") < strlen (optarg))
513 usage2 (_("Invalid warning threshold: %s\n"), optarg); 517 usage2 (_("Invalid warning threshold: %s\n"), optarg);
514 for (ptr = optarg; ptr && ii < MAX_OIDS; ii++) { 518 for (ptr = optarg; ptr && ii < MAX_OIDS; ii++) {
515 if (lu_getll (&lower_warn_lim[ii], ptr) == 1) 519 if (llu_getll (&lower_warn_lim[ii], ptr) == 1)
516 eval_method[ii] |= WARN_LT; 520 eval_method[ii] |= WARN_LT;
517 if (lu_getul (&upper_warn_lim[ii], ptr) == 1) 521 if (llu_getul (&upper_warn_lim[ii], ptr) == 1)
518 eval_method[ii] |= WARN_GT; 522 eval_method[ii] |= WARN_GT;
519 (ptr = index (ptr, ',')) ? ptr++ : ptr; 523 (ptr = index (ptr, ',')) ? ptr++ : ptr;
520 } 524 }
@@ -819,14 +823,14 @@ check_num (int i)
819 823
820 824
821int 825int
822lu_getll (unsigned long *ll, char *str) 826llu_getll (unsigned long long *ll, char *str)
823{ 827{
824 char tmp[100]; 828 char tmp[100];
825 if (strchr (str, ':') == NULL) 829 if (strchr (str, ':') == NULL)
826 return 0; 830 return 0;
827 if (strchr (str, ',') != NULL && (strchr (str, ',') < strchr (str, ':'))) 831 if (strchr (str, ',') != NULL && (strchr (str, ',') < strchr (str, ':')))
828 return 0; 832 return 0;
829 if (sscanf (str, "%lu%[:]", ll, tmp) == 2) 833 if (sscanf (str, "%llu%[:]", ll, tmp) == 2)
830 return 1; 834 return 1;
831 return 0; 835 return 0;
832} 836}
@@ -834,14 +838,14 @@ lu_getll (unsigned long *ll, char *str)
834 838
835 839
836int 840int
837lu_getul (unsigned long *ul, char *str) 841llu_getul (unsigned long long *ul, char *str)
838{ 842{
839 char tmp[100]; 843 char tmp[100];
840 if (sscanf (str, "%lu%[^,]", ul, tmp) == 1) 844 if (sscanf (str, "%llu%[^,]", ul, tmp) == 1)
841 return 1; 845 return 1;
842 if (sscanf (str, ":%lu%[^,]", ul, tmp) == 1) 846 if (sscanf (str, ":%llu%[^,]", ul, tmp) == 1)
843 return 1; 847 return 1;
844 if (sscanf (str, "%*u:%lu%[^,]", ul, tmp) == 1) 848 if (sscanf (str, "%*u:%llu%[^,]", ul, tmp) == 1)
845 return 1; 849 return 1;
846 return 0; 850 return 0;
847} 851}