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