diff options
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r-- | plugins/check_snmp.c | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 2c62a23..9d966fa 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); |
@@ -567,6 +574,18 @@ main (int argc, char **argv) | |||
567 | len = sizeof(perfstr)-strlen(perfstr)-1; | 574 | len = sizeof(perfstr)-strlen(perfstr)-1; |
568 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); | 575 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); |
569 | 576 | ||
577 | if (warning_thresholds) { | ||
578 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | ||
579 | strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | ||
580 | } | ||
581 | |||
582 | if (critical_thresholds) { | ||
583 | if (!warning_thresholds) | ||
584 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | ||
585 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | ||
586 | strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | ||
587 | } | ||
588 | |||
570 | if (type) | 589 | if (type) |
571 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); | 590 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); |
572 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 591 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
@@ -646,6 +665,7 @@ process_arguments (int argc, char **argv) | |||
646 | {"retries", required_argument, 0, 'e'}, | 665 | {"retries", required_argument, 0, 'e'}, |
647 | {"miblist", required_argument, 0, 'm'}, | 666 | {"miblist", required_argument, 0, 'm'}, |
648 | {"protocol", required_argument, 0, 'P'}, | 667 | {"protocol", required_argument, 0, 'P'}, |
668 | {"context", required_argument, 0, 'N'}, | ||
649 | {"seclevel", required_argument, 0, 'L'}, | 669 | {"seclevel", required_argument, 0, 'L'}, |
650 | {"secname", required_argument, 0, 'U'}, | 670 | {"secname", required_argument, 0, 'U'}, |
651 | {"authproto", required_argument, 0, 'a'}, | 671 | {"authproto", required_argument, 0, 'a'}, |
@@ -675,7 +695,7 @@ process_arguments (int argc, char **argv) | |||
675 | } | 695 | } |
676 | 696 | ||
677 | while (1) { | 697 | 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:", | 698 | 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); | 699 | longopts, &option); |
680 | 700 | ||
681 | if (c == -1 || c == EOF) | 701 | if (c == -1 || c == EOF) |
@@ -713,6 +733,9 @@ process_arguments (int argc, char **argv) | |||
713 | case 'P': /* SNMP protocol version */ | 733 | case 'P': /* SNMP protocol version */ |
714 | proto = optarg; | 734 | proto = optarg; |
715 | break; | 735 | break; |
736 | case 'N': /* SNMPv3 context */ | ||
737 | context = optarg; | ||
738 | break; | ||
716 | case 'L': /* security level */ | 739 | case 'L': /* security level */ |
717 | seclevel = optarg; | 740 | seclevel = optarg; |
718 | break; | 741 | break; |
@@ -960,6 +983,13 @@ validate_arguments () | |||
960 | authpriv[1] = strdup (community); | 983 | authpriv[1] = strdup (community); |
961 | } | 984 | } |
962 | else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ | 985 | else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ |
986 | if (!(context == NULL)) { | ||
987 | numcontext = 2; | ||
988 | contextargs = calloc (numcontext, sizeof (char *)); | ||
989 | contextargs[0] = strdup ("-n"); | ||
990 | contextargs[1] = strdup (context); | ||
991 | } | ||
992 | |||
963 | if (seclevel == NULL) | 993 | if (seclevel == NULL) |
964 | xasprintf(&seclevel, "noAuthNoPriv"); | 994 | xasprintf(&seclevel, "noAuthNoPriv"); |
965 | 995 | ||
@@ -1103,6 +1133,8 @@ print_help (void) | |||
1103 | printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET")); | 1133 | printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET")); |
1104 | printf (" %s\n", "-P, --protocol=[1|2c|3]"); | 1134 | printf (" %s\n", "-P, --protocol=[1|2c|3]"); |
1105 | printf (" %s\n", _("SNMP protocol version")); | 1135 | printf (" %s\n", _("SNMP protocol version")); |
1136 | printf (" %s\n", "-N, --context=CONTEXT"); | ||
1137 | printf (" %s\n", _("SNMPv3 context")); | ||
1106 | printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); | 1138 | printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); |
1107 | printf (" %s\n", _("SNMPv3 securityLevel")); | 1139 | printf (" %s\n", _("SNMPv3 securityLevel")); |
1108 | printf (" %s\n", "-a, --authproto=[MD5|SHA]"); | 1140 | printf (" %s\n", "-a, --authproto=[MD5|SHA]"); |
@@ -1210,6 +1242,6 @@ print_usage (void) | |||
1210 | printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname); | 1242 | 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"); | 1243 | 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"); | 1244 | 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"); | 1245 | printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n"); |
1214 | printf ("[-A authpasswd] [-x privproto] [-X privpasswd]\n"); | 1246 | printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd]\n"); |
1215 | } | 1247 | } |