summaryrefslogtreecommitdiffstats
path: root/plugins/check_snmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r--plugins/check_snmp.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 2d9861b..7c5d0ec 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -144,6 +144,25 @@ double previous_value[MAX_OIDS];
144int perf_labels = 1; 144int perf_labels = 1;
145 145
146 146
147static char *fix_snmp_range(char *th)
148{
149 double left, right;
150 char *colon, *ret;
151 if (!(colon = strchr(th, ':')))
152 return th;
153 *colon = 0;
154
155 left = strtod(th, NULL);
156 right = strtod(colon + 1, NULL);
157 if (right >= left) {
158 return th;
159 }
160 ret = malloc(strlen(th) + strlen(colon + 1) + 2);
161 sprintf(ret, "@%s:%s", colon + 1, th);
162 free(th);
163 return ret;
164}
165
147int 166int
148main (int argc, char **argv) 167main (int argc, char **argv)
149{ 168{
@@ -181,8 +200,8 @@ main (int argc, char **argv)
181 bindtextdomain (PACKAGE, LOCALEDIR); 200 bindtextdomain (PACKAGE, LOCALEDIR);
182 textdomain (PACKAGE); 201 textdomain (PACKAGE);
183 202
184 labels = malloc (labels_size); 203 labels = malloc (labels_size * sizeof(*labels));
185 unitv = malloc (unitv_size); 204 unitv = malloc (unitv_size * sizeof(*unitv));
186 for (i = 0; i < MAX_OIDS; i++) 205 for (i = 0; i < MAX_OIDS; i++)
187 eval_method[i] = CHECK_UNDEF; 206 eval_method[i] = CHECK_UNDEF;
188 207
@@ -228,6 +247,10 @@ main (int argc, char **argv)
228 for (i=0; i<numoids; i++) { 247 for (i=0; i<numoids; i++) {
229 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; 248 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL;
230 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; 249 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL;
250 /* translate "2:1" to "@1:2" for backwards compatibility */
251 w = w ? fix_snmp_range(w) : NULL;
252 c = c ? fix_snmp_range(c) : NULL;
253
231 /* Skip empty thresholds, while avoiding segfault */ 254 /* Skip empty thresholds, while avoiding segfault */
232 set_thresholds(&thlds[i], 255 set_thresholds(&thlds[i],
233 w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL, 256 w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL,
@@ -396,7 +419,7 @@ main (int argc, char **argv)
396 show = strstr (response, "Timeticks: "); 419 show = strstr (response, "Timeticks: ");
397 } 420 }
398 else 421 else
399 show = response; 422 show = response + 3;
400 423
401 iresult = STATE_DEPENDENT; 424 iresult = STATE_DEPENDENT;
402 425
@@ -405,7 +428,7 @@ main (int argc, char **argv)
405 if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { 428 if (thlds[i]->warning || thlds[i]->critical || calculate_rate) {
406 ptr = strpbrk (show, "0123456789"); 429 ptr = strpbrk (show, "0123456789");
407 if (ptr == NULL) 430 if (ptr == NULL)
408 die (STATE_UNKNOWN,_("No valid data returned")); 431 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
409 response_value[i] = strtod (ptr, NULL); 432 response_value[i] = strtod (ptr, NULL);
410 433
411 if(calculate_rate) { 434 if(calculate_rate) {
@@ -745,9 +768,9 @@ process_arguments (int argc, char **argv)
745 break; 768 break;
746 case 'l': /* label */ 769 case 'l': /* label */
747 nlabels++; 770 nlabels++;
748 if (nlabels >= labels_size) { 771 if (nlabels > labels_size) {
749 labels_size += 8; 772 labels_size += 8;
750 labels = realloc (labels, labels_size); 773 labels = realloc (labels, labels_size * sizeof(*labels));
751 if (labels == NULL) 774 if (labels == NULL)
752 die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels); 775 die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels);
753 } 776 }
@@ -757,13 +780,13 @@ process_arguments (int argc, char **argv)
757 if (ptr[0] == '\'') 780 if (ptr[0] == '\'')
758 labels[nlabels - 1] = ptr + 1; 781 labels[nlabels - 1] = ptr + 1;
759 while (ptr && (ptr = nextarg (ptr))) { 782 while (ptr && (ptr = nextarg (ptr))) {
760 if (nlabels >= labels_size) { 783 nlabels++;
784 if (nlabels > labels_size) {
761 labels_size += 8; 785 labels_size += 8;
762 labels = realloc (labels, labels_size); 786 labels = realloc (labels, labels_size * sizeof(*labels));
763 if (labels == NULL) 787 if (labels == NULL)
764 die (STATE_UNKNOWN, _("Could not reallocate labels\n")); 788 die (STATE_UNKNOWN, _("Could not reallocate labels\n"));
765 } 789 }
766 nlabels++;
767 ptr = thisarg (ptr); 790 ptr = thisarg (ptr);
768 if (ptr[0] == '\'') 791 if (ptr[0] == '\'')
769 labels[nlabels - 1] = ptr + 1; 792 labels[nlabels - 1] = ptr + 1;
@@ -774,9 +797,9 @@ process_arguments (int argc, char **argv)
774 case 'u': /* units */ 797 case 'u': /* units */
775 units = optarg; 798 units = optarg;
776 nunits++; 799 nunits++;
777 if (nunits >= unitv_size) { 800 if (nunits > unitv_size) {
778 unitv_size += 8; 801 unitv_size += 8;
779 unitv = realloc (unitv, unitv_size); 802 unitv = realloc (unitv, unitv_size * sizeof(*unitv));
780 if (unitv == NULL) 803 if (unitv == NULL)
781 die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits); 804 die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits);
782 } 805 }
@@ -786,9 +809,9 @@ process_arguments (int argc, char **argv)
786 if (ptr[0] == '\'') 809 if (ptr[0] == '\'')
787 unitv[nunits - 1] = ptr + 1; 810 unitv[nunits - 1] = ptr + 1;
788 while (ptr && (ptr = nextarg (ptr))) { 811 while (ptr && (ptr = nextarg (ptr))) {
789 if (nunits >= unitv_size) { 812 if (nunits > unitv_size) {
790 unitv_size += 8; 813 unitv_size += 8;
791 unitv = realloc (unitv, unitv_size); 814 unitv = realloc (unitv, unitv_size * sizeof(*unitv));
792 if (units == NULL) 815 if (units == NULL)
793 die (STATE_UNKNOWN, _("Could not realloc() units\n")); 816 die (STATE_UNKNOWN, _("Could not realloc() units\n"));
794 } 817 }