diff options
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r-- | plugins/check_snmp.c | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 2c62a23..62e6b8b 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -104,6 +104,8 @@ int errcode, excode; | |||
104 | 104 | ||
105 | char *server_address = NULL; | 105 | char *server_address = NULL; |
106 | char *community = NULL; | 106 | char *community = NULL; |
107 | char **contextargs = NULL; | ||
108 | char *context = NULL; | ||
107 | char **authpriv = NULL; | 109 | char **authpriv = NULL; |
108 | char *proto = NULL; | 110 | char *proto = NULL; |
109 | char *seclevel = NULL; | 111 | char *seclevel = NULL; |
@@ -128,6 +130,7 @@ size_t nunits = 0; | |||
128 | size_t unitv_size = OID_COUNT_STEP; | 130 | size_t unitv_size = OID_COUNT_STEP; |
129 | int numoids = 0; | 131 | int numoids = 0; |
130 | int numauthpriv = 0; | 132 | int numauthpriv = 0; |
133 | int numcontext = 0; | ||
131 | int verbose = 0; | 134 | int verbose = 0; |
132 | int usesnmpgetnext = FALSE; | 135 | int usesnmpgetnext = FALSE; |
133 | char *warning_thresholds = NULL; | 136 | char *warning_thresholds = NULL; |
@@ -297,8 +300,8 @@ main (int argc, char **argv) | |||
297 | snmpcmd = strdup (PATH_TO_SNMPGET); | 300 | snmpcmd = strdup (PATH_TO_SNMPGET); |
298 | } | 301 | } |
299 | 302 | ||
300 | /* 10 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */ | 303 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ |
301 | command_line = calloc (10 + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 304 | command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
302 | command_line[0] = snmpcmd; | 305 | command_line[0] = snmpcmd; |
303 | command_line[1] = strdup ("-Le"); | 306 | command_line[1] = strdup ("-Le"); |
304 | command_line[2] = strdup ("-t"); | 307 | command_line[2] = strdup ("-t"); |
@@ -310,23 +313,27 @@ main (int argc, char **argv) | |||
310 | command_line[8] = "-v"; | 313 | command_line[8] = "-v"; |
311 | command_line[9] = strdup (proto); | 314 | command_line[9] = strdup (proto); |
312 | 315 | ||
316 | for (i = 0; i < numcontext; i++) { | ||
317 | command_line[10 + i] = contextargs[i]; | ||
318 | } | ||
319 | |||
313 | for (i = 0; i < numauthpriv; i++) { | 320 | for (i = 0; i < numauthpriv; i++) { |
314 | command_line[10 + i] = authpriv[i]; | 321 | command_line[10 + numcontext + i] = authpriv[i]; |
315 | } | 322 | } |
316 | 323 | ||
317 | xasprintf (&command_line[10 + numauthpriv], "%s:%s", server_address, port); | 324 | xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); |
318 | 325 | ||
319 | /* This is just for display purposes, so it can remain a string */ | 326 | /* This is just for display purposes, so it can remain a string */ |
320 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s:%s", | 327 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", |
321 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", | 328 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", |
322 | server_address, port); | 329 | server_address, port); |
323 | 330 | ||
324 | for (i = 0; i < numoids; i++) { | 331 | for (i = 0; i < numoids; i++) { |
325 | command_line[10 + numauthpriv + 1 + i] = oids[i]; | 332 | command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; |
326 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 333 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
327 | } | 334 | } |
328 | 335 | ||
329 | command_line[10 + numauthpriv + 1 + numoids] = NULL; | 336 | command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; |
330 | 337 | ||
331 | if (verbose) | 338 | if (verbose) |
332 | printf ("%s\n", cl_hidden_auth); | 339 | printf ("%s\n", cl_hidden_auth); |
@@ -411,6 +418,9 @@ main (int argc, char **argv) | |||
411 | else if (strstr (response, "INTEGER: ")) { | 418 | else if (strstr (response, "INTEGER: ")) { |
412 | show = strstr (response, "INTEGER: ") + 9; | 419 | show = strstr (response, "INTEGER: ") + 9; |
413 | } | 420 | } |
421 | else if (strstr (response, "OID: ")) { | ||
422 | show = strstr (response, "OID: ") + 5; | ||
423 | } | ||
414 | else if (strstr (response, "STRING: ")) { | 424 | else if (strstr (response, "STRING: ")) { |
415 | show = strstr (response, "STRING: ") + 8; | 425 | show = strstr (response, "STRING: ") + 8; |
416 | conv = "%.10g"; | 426 | conv = "%.10g"; |
@@ -567,6 +577,18 @@ main (int argc, char **argv) | |||
567 | len = sizeof(perfstr)-strlen(perfstr)-1; | 577 | len = sizeof(perfstr)-strlen(perfstr)-1; |
568 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); | 578 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); |
569 | 579 | ||
580 | if (warning_thresholds) { | ||
581 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | ||
582 | strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | ||
583 | } | ||
584 | |||
585 | if (critical_thresholds) { | ||
586 | if (!warning_thresholds) | ||
587 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | ||
588 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | ||
589 | strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | ||
590 | } | ||
591 | |||
570 | if (type) | 592 | if (type) |
571 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); | 593 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); |
572 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 594 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
@@ -646,6 +668,7 @@ process_arguments (int argc, char **argv) | |||
646 | {"retries", required_argument, 0, 'e'}, | 668 | {"retries", required_argument, 0, 'e'}, |
647 | {"miblist", required_argument, 0, 'm'}, | 669 | {"miblist", required_argument, 0, 'm'}, |
648 | {"protocol", required_argument, 0, 'P'}, | 670 | {"protocol", required_argument, 0, 'P'}, |
671 | {"context", required_argument, 0, 'N'}, | ||
649 | {"seclevel", required_argument, 0, 'L'}, | 672 | {"seclevel", required_argument, 0, 'L'}, |
650 | {"secname", required_argument, 0, 'U'}, | 673 | {"secname", required_argument, 0, 'U'}, |
651 | {"authproto", required_argument, 0, 'a'}, | 674 | {"authproto", required_argument, 0, 'a'}, |
@@ -675,7 +698,7 @@ process_arguments (int argc, char **argv) | |||
675 | } | 698 | } |
676 | 699 | ||
677 | while (1) { | 700 | while (1) { |
678 | c = getopt_long (argc, argv, "nhvVOt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:x:A:X:", | 701 | c = getopt_long (argc, argv, "nhvVOt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:", |
679 | longopts, &option); | 702 | longopts, &option); |
680 | 703 | ||
681 | if (c == -1 || c == EOF) | 704 | if (c == -1 || c == EOF) |
@@ -713,6 +736,9 @@ process_arguments (int argc, char **argv) | |||
713 | case 'P': /* SNMP protocol version */ | 736 | case 'P': /* SNMP protocol version */ |
714 | proto = optarg; | 737 | proto = optarg; |
715 | break; | 738 | break; |
739 | case 'N': /* SNMPv3 context */ | ||
740 | context = optarg; | ||
741 | break; | ||
716 | case 'L': /* security level */ | 742 | case 'L': /* security level */ |
717 | seclevel = optarg; | 743 | seclevel = optarg; |
718 | break; | 744 | break; |
@@ -960,6 +986,13 @@ validate_arguments () | |||
960 | authpriv[1] = strdup (community); | 986 | authpriv[1] = strdup (community); |
961 | } | 987 | } |
962 | else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ | 988 | else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ |
989 | if (!(context == NULL)) { | ||
990 | numcontext = 2; | ||
991 | contextargs = calloc (numcontext, sizeof (char *)); | ||
992 | contextargs[0] = strdup ("-n"); | ||
993 | contextargs[1] = strdup (context); | ||
994 | } | ||
995 | |||
963 | if (seclevel == NULL) | 996 | if (seclevel == NULL) |
964 | xasprintf(&seclevel, "noAuthNoPriv"); | 997 | xasprintf(&seclevel, "noAuthNoPriv"); |
965 | 998 | ||
@@ -1103,6 +1136,8 @@ print_help (void) | |||
1103 | printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET")); | 1136 | printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET")); |
1104 | printf (" %s\n", "-P, --protocol=[1|2c|3]"); | 1137 | printf (" %s\n", "-P, --protocol=[1|2c|3]"); |
1105 | printf (" %s\n", _("SNMP protocol version")); | 1138 | printf (" %s\n", _("SNMP protocol version")); |
1139 | printf (" %s\n", "-N, --context=CONTEXT"); | ||
1140 | printf (" %s\n", _("SNMPv3 context")); | ||
1106 | printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); | 1141 | printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); |
1107 | printf (" %s\n", _("SNMPv3 securityLevel")); | 1142 | printf (" %s\n", _("SNMPv3 securityLevel")); |
1108 | printf (" %s\n", "-a, --authproto=[MD5|SHA]"); | 1143 | printf (" %s\n", "-a, --authproto=[MD5|SHA]"); |
@@ -1210,6 +1245,6 @@ print_usage (void) | |||
1210 | printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname); | 1245 | printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname); |
1211 | printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n"); | 1246 | printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n"); |
1212 | printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n"); | 1247 | printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n"); |
1213 | printf ("[-m miblist] [-P snmp version] [-L seclevel] [-U secname] [-a authproto]\n"); | 1248 | printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n"); |
1214 | printf ("[-A authpasswd] [-x privproto] [-X privpasswd]\n"); | 1249 | printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd]\n"); |
1215 | } | 1250 | } |