diff options
Diffstat (limited to 'plugins/check_snmp.c')
| -rw-r--r-- | plugins/check_snmp.c | 87 |
1 files changed, 69 insertions, 18 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 2c62a230..abe54cfb 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
| @@ -41,7 +41,6 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 41 | #define DEFAULT_PORT "161" | 41 | #define DEFAULT_PORT "161" |
| 42 | #define DEFAULT_MIBLIST "ALL" | 42 | #define DEFAULT_MIBLIST "ALL" |
| 43 | #define DEFAULT_PROTOCOL "1" | 43 | #define DEFAULT_PROTOCOL "1" |
| 44 | #define DEFAULT_TIMEOUT 1 | ||
| 45 | #define DEFAULT_RETRIES 5 | 44 | #define DEFAULT_RETRIES 5 |
| 46 | #define DEFAULT_AUTH_PROTOCOL "MD5" | 45 | #define DEFAULT_AUTH_PROTOCOL "MD5" |
| 47 | #define DEFAULT_PRIV_PROTOCOL "DES" | 46 | #define DEFAULT_PRIV_PROTOCOL "DES" |
| @@ -104,6 +103,8 @@ int errcode, excode; | |||
| 104 | 103 | ||
| 105 | char *server_address = NULL; | 104 | char *server_address = NULL; |
| 106 | char *community = NULL; | 105 | char *community = NULL; |
| 106 | char **contextargs = NULL; | ||
| 107 | char *context = NULL; | ||
| 107 | char **authpriv = NULL; | 108 | char **authpriv = NULL; |
| 108 | char *proto = NULL; | 109 | char *proto = NULL; |
| 109 | char *seclevel = NULL; | 110 | char *seclevel = NULL; |
| @@ -128,6 +129,7 @@ size_t nunits = 0; | |||
| 128 | size_t unitv_size = OID_COUNT_STEP; | 129 | size_t unitv_size = OID_COUNT_STEP; |
| 129 | int numoids = 0; | 130 | int numoids = 0; |
| 130 | int numauthpriv = 0; | 131 | int numauthpriv = 0; |
| 132 | int numcontext = 0; | ||
| 131 | int verbose = 0; | 133 | int verbose = 0; |
| 132 | int usesnmpgetnext = FALSE; | 134 | int usesnmpgetnext = FALSE; |
| 133 | char *warning_thresholds = NULL; | 135 | char *warning_thresholds = NULL; |
| @@ -150,7 +152,7 @@ state_data *previous_state; | |||
| 150 | double *previous_value; | 152 | double *previous_value; |
| 151 | size_t previous_size = OID_COUNT_STEP; | 153 | size_t previous_size = OID_COUNT_STEP; |
| 152 | int perf_labels = 1; | 154 | int perf_labels = 1; |
| 153 | 155 | char* ip_version = ""; | |
| 154 | 156 | ||
| 155 | static char *fix_snmp_range(char *th) | 157 | static char *fix_snmp_range(char *th) |
| 156 | { | 158 | { |
| @@ -224,7 +226,7 @@ main (int argc, char **argv) | |||
| 224 | outbuff = strdup (""); | 226 | outbuff = strdup (""); |
| 225 | delimiter = strdup (" = "); | 227 | delimiter = strdup (" = "); |
| 226 | output_delim = strdup (DEFAULT_OUTPUT_DELIMITER); | 228 | output_delim = strdup (DEFAULT_OUTPUT_DELIMITER); |
| 227 | timeout_interval = DEFAULT_TIMEOUT; | 229 | timeout_interval = DEFAULT_SOCKET_TIMEOUT; |
| 228 | retries = DEFAULT_RETRIES; | 230 | retries = DEFAULT_RETRIES; |
| 229 | 231 | ||
| 230 | np_init( (char *) progname, argc, argv ); | 232 | np_init( (char *) progname, argc, argv ); |
| @@ -297,8 +299,8 @@ main (int argc, char **argv) | |||
| 297 | snmpcmd = strdup (PATH_TO_SNMPGET); | 299 | snmpcmd = strdup (PATH_TO_SNMPGET); |
| 298 | } | 300 | } |
| 299 | 301 | ||
| 300 | /* 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 */ |
| 301 | command_line = calloc (10 + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 303 | command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
| 302 | command_line[0] = snmpcmd; | 304 | command_line[0] = snmpcmd; |
| 303 | command_line[1] = strdup ("-Le"); | 305 | command_line[1] = strdup ("-Le"); |
| 304 | command_line[2] = strdup ("-t"); | 306 | command_line[2] = strdup ("-t"); |
| @@ -310,23 +312,27 @@ main (int argc, char **argv) | |||
| 310 | command_line[8] = "-v"; | 312 | command_line[8] = "-v"; |
| 311 | command_line[9] = strdup (proto); | 313 | command_line[9] = strdup (proto); |
| 312 | 314 | ||
| 315 | for (i = 0; i < numcontext; i++) { | ||
| 316 | command_line[10 + i] = contextargs[i]; | ||
| 317 | } | ||
| 318 | |||
| 313 | for (i = 0; i < numauthpriv; i++) { | 319 | for (i = 0; i < numauthpriv; i++) { |
| 314 | command_line[10 + i] = authpriv[i]; | 320 | command_line[10 + numcontext + i] = authpriv[i]; |
| 315 | } | 321 | } |
| 316 | 322 | ||
| 317 | xasprintf (&command_line[10 + numauthpriv], "%s:%s", server_address, port); | 323 | xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); |
| 318 | 324 | ||
| 319 | /* 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 */ |
| 320 | 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", |
| 321 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", | 327 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", |
| 322 | server_address, port); | 328 | server_address, port); |
| 323 | 329 | ||
| 324 | for (i = 0; i < numoids; i++) { | 330 | for (i = 0; i < numoids; i++) { |
| 325 | command_line[10 + numauthpriv + 1 + i] = oids[i]; | 331 | command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; |
| 326 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 332 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
| 327 | } | 333 | } |
| 328 | 334 | ||
| 329 | command_line[10 + numauthpriv + 1 + numoids] = NULL; | 335 | command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; |
| 330 | 336 | ||
| 331 | if (verbose) | 337 | if (verbose) |
| 332 | printf ("%s\n", cl_hidden_auth); | 338 | printf ("%s\n", cl_hidden_auth); |
| @@ -411,6 +417,9 @@ main (int argc, char **argv) | |||
| 411 | else if (strstr (response, "INTEGER: ")) { | 417 | else if (strstr (response, "INTEGER: ")) { |
| 412 | show = strstr (response, "INTEGER: ") + 9; | 418 | show = strstr (response, "INTEGER: ") + 9; |
| 413 | } | 419 | } |
| 420 | else if (strstr (response, "OID: ")) { | ||
| 421 | show = strstr (response, "OID: ") + 5; | ||
| 422 | } | ||
| 414 | else if (strstr (response, "STRING: ")) { | 423 | else if (strstr (response, "STRING: ")) { |
| 415 | show = strstr (response, "STRING: ") + 8; | 424 | show = strstr (response, "STRING: ") + 8; |
| 416 | conv = "%.10g"; | 425 | conv = "%.10g"; |
| @@ -459,6 +468,9 @@ main (int argc, char **argv) | |||
| 459 | /* Process this block for numeric comparisons */ | 468 | /* Process this block for numeric comparisons */ |
| 460 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ | 469 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ |
| 461 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { | 470 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { |
| 471 | if (verbose > 2) { | ||
| 472 | print_thresholds(" thresholds", thlds[i]); | ||
| 473 | } | ||
| 462 | ptr = strpbrk (show, "-0123456789"); | 474 | ptr = strpbrk (show, "-0123456789"); |
| 463 | if (ptr == NULL) | 475 | if (ptr == NULL) |
| 464 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); | 476 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); |
| @@ -569,6 +581,21 @@ main (int argc, char **argv) | |||
| 569 | 581 | ||
| 570 | if (type) | 582 | if (type) |
| 571 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); | 583 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); |
| 584 | |||
| 585 | if (warning_thresholds) { | ||
| 586 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | ||
| 587 | if(thlds[i]->warning && thlds[i]->warning->text) | ||
| 588 | strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 589 | } | ||
| 590 | |||
| 591 | if (critical_thresholds) { | ||
| 592 | if (!warning_thresholds) | ||
| 593 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | ||
| 594 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | ||
| 595 | if(thlds[i]->critical && thlds[i]->critical->text) | ||
| 596 | strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 597 | } | ||
| 598 | |||
| 572 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 599 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
| 573 | } | 600 | } |
| 574 | } | 601 | } |
| @@ -646,6 +673,7 @@ process_arguments (int argc, char **argv) | |||
| 646 | {"retries", required_argument, 0, 'e'}, | 673 | {"retries", required_argument, 0, 'e'}, |
| 647 | {"miblist", required_argument, 0, 'm'}, | 674 | {"miblist", required_argument, 0, 'm'}, |
| 648 | {"protocol", required_argument, 0, 'P'}, | 675 | {"protocol", required_argument, 0, 'P'}, |
| 676 | {"context", required_argument, 0, 'N'}, | ||
| 649 | {"seclevel", required_argument, 0, 'L'}, | 677 | {"seclevel", required_argument, 0, 'L'}, |
| 650 | {"secname", required_argument, 0, 'U'}, | 678 | {"secname", required_argument, 0, 'U'}, |
| 651 | {"authproto", required_argument, 0, 'a'}, | 679 | {"authproto", required_argument, 0, 'a'}, |
| @@ -658,6 +686,8 @@ process_arguments (int argc, char **argv) | |||
| 658 | {"offset", required_argument, 0, L_OFFSET}, | 686 | {"offset", required_argument, 0, L_OFFSET}, |
| 659 | {"invert-search", no_argument, 0, L_INVERT_SEARCH}, | 687 | {"invert-search", no_argument, 0, L_INVERT_SEARCH}, |
| 660 | {"perf-oids", no_argument, 0, 'O'}, | 688 | {"perf-oids", no_argument, 0, 'O'}, |
| 689 | {"ipv4", no_argument, 0, '4'}, | ||
| 690 | {"ipv6", no_argument, 0, '6'}, | ||
| 661 | {0, 0, 0, 0} | 691 | {0, 0, 0, 0} |
| 662 | }; | 692 | }; |
| 663 | 693 | ||
| @@ -675,7 +705,7 @@ process_arguments (int argc, char **argv) | |||
| 675 | } | 705 | } |
| 676 | 706 | ||
| 677 | while (1) { | 707 | 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:", | 708 | c = getopt_long (argc, argv, "nhvVO46t: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); | 709 | longopts, &option); |
| 680 | 710 | ||
| 681 | if (c == -1 || c == EOF) | 711 | if (c == -1 || c == EOF) |
| @@ -686,10 +716,10 @@ process_arguments (int argc, char **argv) | |||
| 686 | usage5 (); | 716 | usage5 (); |
| 687 | case 'h': /* help */ | 717 | case 'h': /* help */ |
| 688 | print_help (); | 718 | print_help (); |
| 689 | exit (STATE_OK); | 719 | exit (STATE_UNKNOWN); |
| 690 | case 'V': /* version */ | 720 | case 'V': /* version */ |
| 691 | print_revision (progname, NP_VERSION); | 721 | print_revision (progname, NP_VERSION); |
| 692 | exit (STATE_OK); | 722 | exit (STATE_UNKNOWN); |
| 693 | case 'v': /* verbose */ | 723 | case 'v': /* verbose */ |
| 694 | verbose++; | 724 | verbose++; |
| 695 | break; | 725 | break; |
| @@ -713,6 +743,9 @@ process_arguments (int argc, char **argv) | |||
| 713 | case 'P': /* SNMP protocol version */ | 743 | case 'P': /* SNMP protocol version */ |
| 714 | proto = optarg; | 744 | proto = optarg; |
| 715 | break; | 745 | break; |
| 746 | case 'N': /* SNMPv3 context */ | ||
| 747 | context = optarg; | ||
| 748 | break; | ||
| 716 | case 'L': /* security level */ | 749 | case 'L': /* security level */ |
| 717 | seclevel = optarg; | 750 | seclevel = optarg; |
| 718 | break; | 751 | break; |
| @@ -897,6 +930,13 @@ process_arguments (int argc, char **argv) | |||
| 897 | case 'O': | 930 | case 'O': |
| 898 | perf_labels=0; | 931 | perf_labels=0; |
| 899 | break; | 932 | break; |
| 933 | case '4': | ||
| 934 | break; | ||
| 935 | case '6': | ||
| 936 | xasprintf(&ip_version, "udp6:"); | ||
| 937 | if(verbose>2) | ||
| 938 | printf("IPv6 detected! Will pass \"udp6:\" to snmpget.\n"); | ||
| 939 | break; | ||
| 900 | } | 940 | } |
| 901 | } | 941 | } |
| 902 | 942 | ||
| @@ -960,6 +1000,13 @@ validate_arguments () | |||
| 960 | authpriv[1] = strdup (community); | 1000 | authpriv[1] = strdup (community); |
| 961 | } | 1001 | } |
| 962 | else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ | 1002 | else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ |
| 1003 | if (!(context == NULL)) { | ||
| 1004 | numcontext = 2; | ||
| 1005 | contextargs = calloc (numcontext, sizeof (char *)); | ||
| 1006 | contextargs[0] = strdup ("-n"); | ||
| 1007 | contextargs[1] = strdup (context); | ||
| 1008 | } | ||
| 1009 | |||
| 963 | if (seclevel == NULL) | 1010 | if (seclevel == NULL) |
| 964 | xasprintf(&seclevel, "noAuthNoPriv"); | 1011 | xasprintf(&seclevel, "noAuthNoPriv"); |
| 965 | 1012 | ||
| @@ -1095,6 +1142,7 @@ print_help (void) | |||
| 1095 | 1142 | ||
| 1096 | printf (UT_HELP_VRSN); | 1143 | printf (UT_HELP_VRSN); |
| 1097 | printf (UT_EXTRA_OPTS); | 1144 | printf (UT_EXTRA_OPTS); |
| 1145 | printf (UT_IPv46); | ||
| 1098 | 1146 | ||
| 1099 | printf (UT_HOST_PORT, 'p', DEFAULT_PORT); | 1147 | printf (UT_HOST_PORT, 'p', DEFAULT_PORT); |
| 1100 | 1148 | ||
| @@ -1103,6 +1151,8 @@ print_help (void) | |||
| 1103 | printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET")); | 1151 | printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET")); |
| 1104 | printf (" %s\n", "-P, --protocol=[1|2c|3]"); | 1152 | printf (" %s\n", "-P, --protocol=[1|2c|3]"); |
| 1105 | printf (" %s\n", _("SNMP protocol version")); | 1153 | printf (" %s\n", _("SNMP protocol version")); |
| 1154 | printf (" %s\n", "-N, --context=CONTEXT"); | ||
| 1155 | printf (" %s\n", _("SNMPv3 context")); | ||
| 1106 | printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); | 1156 | printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); |
| 1107 | printf (" %s\n", _("SNMPv3 securityLevel")); | 1157 | printf (" %s\n", _("SNMPv3 securityLevel")); |
| 1108 | printf (" %s\n", "-a, --authproto=[MD5|SHA]"); | 1158 | printf (" %s\n", "-a, --authproto=[MD5|SHA]"); |
| @@ -1116,7 +1166,7 @@ print_help (void) | |||
| 1116 | printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); | 1166 | printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); |
| 1117 | printf (" %s\n", "-U, --secname=USERNAME"); | 1167 | printf (" %s\n", "-U, --secname=USERNAME"); |
| 1118 | printf (" %s\n", _("SNMPv3 username")); | 1168 | printf (" %s\n", _("SNMPv3 username")); |
| 1119 | printf (" %s\n", "-A, --authpassword=PASSWORD"); | 1169 | printf (" %s\n", "-A, --authpasswd=PASSWORD"); |
| 1120 | printf (" %s\n", _("SNMPv3 authentication password")); | 1170 | printf (" %s\n", _("SNMPv3 authentication password")); |
| 1121 | printf (" %s\n", "-X, --privpasswd=PASSWORD"); | 1171 | printf (" %s\n", "-X, --privpasswd=PASSWORD"); |
| 1122 | printf (" %s\n", _("SNMPv3 privacy password")); | 1172 | printf (" %s\n", _("SNMPv3 privacy password")); |
| @@ -1163,8 +1213,9 @@ print_help (void) | |||
| 1163 | printf (" %s\n", _("Separates output on multiple OID requests")); | 1213 | printf (" %s\n", _("Separates output on multiple OID requests")); |
| 1164 | 1214 | ||
| 1165 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 1215 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
| 1216 | printf (" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5")); | ||
| 1166 | printf (" %s\n", "-e, --retries=INTEGER"); | 1217 | printf (" %s\n", "-e, --retries=INTEGER"); |
| 1167 | printf (" %s\n", _("Number of retries to be used in the requests")); | 1218 | printf (" %s%i\n", _("Number of retries to be used in the requests, default: "), DEFAULT_RETRIES); |
| 1168 | 1219 | ||
| 1169 | printf (" %s\n", "-O, --perf-oids"); | 1220 | printf (" %s\n", "-O, --perf-oids"); |
| 1170 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | 1221 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); |
| @@ -1210,6 +1261,6 @@ print_usage (void) | |||
| 1210 | printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname); | 1261 | 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"); | 1262 | 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"); | 1263 | 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"); | 1264 | printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n"); |
| 1214 | printf ("[-A authpasswd] [-x privproto] [-X privpasswd]\n"); | 1265 | printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [-4|6]\n"); |
| 1215 | } | 1266 | } |
