diff options
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | doc/developer-guidelines.sgml | 41 | ||||
-rw-r--r-- | perlmods/install_order | 10 | ||||
-rw-r--r-- | plugins/check_disk.c | 21 | ||||
-rw-r--r-- | plugins/check_snmp.c | 94 | ||||
-rw-r--r-- | plugins/t/check_snmp.t | 293 | ||||
-rw-r--r-- | plugins/t/check_tcp.t | 2 | ||||
-rwxr-xr-x | test.pl.in | 2 | ||||
-rwxr-xr-x | tools/build_perl_modules | 1 |
9 files changed, 275 insertions, 191 deletions
@@ -9,6 +9,7 @@ This file documents the major additions and syntax changes between releases. | |||
9 | Added -4/-6 options to check_dig (Ville Mattila) | 9 | Added -4/-6 options to check_dig (Ville Mattila) |
10 | New check_oracle --connect option to perform real login | 10 | New check_oracle --connect option to perform real login |
11 | New check_nagios -t option to override the default timeout | 11 | New check_nagios -t option to override the default timeout |
12 | New check_disk -f/--freespace-ignore-reserved option to ignore space reserved for root | ||
12 | New check_disk -N/--include-type option to limit the filesystem types to check | 13 | New check_disk -N/--include-type option to limit the filesystem types to check |
13 | Allow for building the plugins in parallel | 14 | Allow for building the plugins in parallel |
14 | Add --without-{dbi,ldap,radius} options to ./configure | 15 | Add --without-{dbi,ldap,radius} options to ./configure |
@@ -29,6 +30,7 @@ This file documents the major additions and syntax changes between releases. | |||
29 | New check_mysql -f option to specify a client options file | 30 | New check_mysql -f option to specify a client options file |
30 | New check_mysql -g option to specify a client options group | 31 | New check_mysql -g option to specify a client options group |
31 | New check_snmp --offset option to allow for adding/substracting an offset value to sensor data | 32 | New check_snmp --offset option to allow for adding/substracting an offset value to sensor data |
33 | Let check_snmp support an arbitrary number of OIDs | ||
32 | Let check_ide_smart support NetBSD | 34 | Let check_ide_smart support NetBSD |
33 | 35 | ||
34 | FIXES | 36 | FIXES |
diff --git a/doc/developer-guidelines.sgml b/doc/developer-guidelines.sgml index e7754f4e..eb5b0391 100644 --- a/doc/developer-guidelines.sgml +++ b/doc/developer-guidelines.sgml | |||
@@ -11,7 +11,7 @@ | |||
11 | </author> | 11 | </author> |
12 | </authorgroup> | 12 | </authorgroup> |
13 | 13 | ||
14 | <pubdate>2009</pubdate> | 14 | <pubdate>2013</pubdate> |
15 | <title>Nagios plug-in development guidelines</title> | 15 | <title>Nagios plug-in development guidelines</title> |
16 | 16 | ||
17 | <revhistory> | 17 | <revhistory> |
@@ -22,7 +22,7 @@ | |||
22 | </revhistory> | 22 | </revhistory> |
23 | 23 | ||
24 | <copyright> | 24 | <copyright> |
25 | <year>2000 - 2009</year> | 25 | <year>2000 - 2013</year> |
26 | <holder>Nagios Plugins Development Team</holder> | 26 | <holder>Nagios Plugins Development Team</holder> |
27 | </copyright> | 27 | </copyright> |
28 | 28 | ||
@@ -34,7 +34,7 @@ | |||
34 | the plug-in developers and encourage the standarization of the | 34 | the plug-in developers and encourage the standarization of the |
35 | different kind of plug-ins: C, shell, perl, python, etc.</para> | 35 | different kind of plug-ins: C, shell, perl, python, etc.</para> |
36 | 36 | ||
37 | <para>Nagios Plug-in Development Guidelines Copyright (C) 2000-2009 | 37 | <para>Nagios Plug-in Development Guidelines Copyright (C) 2000-2013 |
38 | (Nagios Plugins Team)</para> | 38 | (Nagios Plugins Team)</para> |
39 | 39 | ||
40 | <para>Permission is granted to make and distribute verbatim | 40 | <para>Permission is granted to make and distribute verbatim |
@@ -83,10 +83,18 @@ | |||
83 | STDOUT and not print to STDERR.</para> | 83 | STDOUT and not print to STDERR.</para> |
84 | 84 | ||
85 | <section><title>Print only one line of text</title> | 85 | <section><title>Print only one line of text</title> |
86 | <para>Nagios will only grab the first line of text from STDOUT | 86 | <para>Starting with version 3, Nagios will process plugins' multiline |
87 | when it notifies contacts about potential problems. If you print | 87 | output, which should be formatted as:</para> |
88 | multiple lines, you're out of luck (though this will be a feature of | 88 | <literallayout> |
89 | Nagios 3). Remember, keep your output short and to the point.</para> | 89 | SERVICE STATUS: First line of output | First part of performance data |
90 | Any number of subsequent lines of output, but note that buffers | ||
91 | may have a limited size | Second part of performance data, which | ||
92 | may have continuation lines, too | ||
93 | </literallayout> | ||
94 | <para>Note, however, that the default configs still do not include | ||
95 | the output's continuation lines into the notifications sent when | ||
96 | Nagios notifies contacts about potential problems. | ||
97 | Thus, keep your output short and to the point.</para> | ||
90 | 98 | ||
91 | <para>Output should be in the format:</para> | 99 | <para>Output should be in the format:</para> |
92 | <literallayout> | 100 | <literallayout> |
@@ -269,10 +277,6 @@ | |||
269 | <entry>@10:20</entry> | 277 | <entry>@10:20</entry> |
270 | <entry>≥ 10 and ≤ 20, (inside the range of {10 .. 20})</entry> | 278 | <entry>≥ 10 and ≤ 20, (inside the range of {10 .. 20})</entry> |
271 | </row> | 279 | </row> |
272 | <row> | ||
273 | <entry>10</entry> | ||
274 | <entry>< 0 or > 10, (outside the range of {0 .. 10})</entry> | ||
275 | </row> | ||
276 | </tbody> | 280 | </tbody> |
277 | </tgroup> | 281 | </tgroup> |
278 | </table> | 282 | </table> |
@@ -319,10 +323,14 @@ | |||
319 | </section> | 323 | </section> |
320 | 324 | ||
321 | <section><title>Performance data</title> | 325 | <section><title>Performance data</title> |
322 | <para>Performance data is defined by Nagios as "everything after the | of the plugin output" - | 326 | <para>Nagios 3 and newer will concatenate the parts following a "|" in a) the first |
323 | please refer to Nagios documentation for information on capturing this data to logfiles. | 327 | line output by the plugin, and b) in the second to last line, into a string it |
324 | However, it is the responsibility of the plugin writer to ensure the | 328 | passes to whatever performance data processing it has configured. (Note that it |
325 | performance data is in a "Nagios plugins" format. | 329 | currently does not insert additional whitespace between both, so the plugin needs |
330 | to provide some to prevent the last pair of a) and the first of b) getting run | ||
331 | together.) Please refer to the Nagios documentation for information on how to | ||
332 | configure such processing. However, it is the responsibility of the plugin writer | ||
333 | to ensure the performance data is in a "Nagios plugins" format. | ||
326 | This is the expected format:</para> | 334 | This is the expected format:</para> |
327 | 335 | ||
328 | <literallayout> | 336 | <literallayout> |
@@ -351,7 +359,8 @@ | |||
351 | <listitem><para>min and max are not required if UOM=%</para> | 359 | <listitem><para>min and max are not required if UOM=%</para> |
352 | </listitem> | 360 | </listitem> |
353 | <listitem><para>value, min and max in class [-0-9.]. Must all be the | 361 | <listitem><para>value, min and max in class [-0-9.]. Must all be the |
354 | same UOM</para> | 362 | same UOM. value may be a literal "U" instead, this would indicate that the |
363 | actual value couldn't be determined</para> | ||
355 | </listitem> | 364 | </listitem> |
356 | <listitem><para>warn and crit are in the range format (see | 365 | <listitem><para>warn and crit are in the range format (see |
357 | <xref linkend="thresholdformat">). Must be the same UOM</para> | 366 | <xref linkend="thresholdformat">). Must be the same UOM</para> |
diff --git a/perlmods/install_order b/perlmods/install_order index 7f07348e..c44c8723 100644 --- a/perlmods/install_order +++ b/perlmods/install_order | |||
@@ -2,13 +2,13 @@ | |||
2 | default: | 2 | default: |
3 | Test-Simple | 3 | Test-Simple |
4 | Perl-OSType | 4 | Perl-OSType |
5 | parent | ||
6 | version | ||
7 | Try-Tiny | ||
8 | Module-Metadata | ||
9 | Module-Runtime | ||
10 | Module-Implementation | 5 | Module-Implementation |
6 | Module-Metadata | ||
7 | version | ||
11 | Module-Build | 8 | Module-Build |
9 | Module-Runtime | ||
10 | parent | ||
11 | Try-Tiny | ||
12 | Params-Validate | 12 | Params-Validate |
13 | Math-Calc-Units | 13 | Math-Calc-Units |
14 | Class-Accessor | 14 | Class-Accessor |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 4ea03935..47dc0adc 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -138,6 +138,7 @@ int verbose = 0; | |||
138 | int erronly = FALSE; | 138 | int erronly = FALSE; |
139 | int display_mntp = FALSE; | 139 | int display_mntp = FALSE; |
140 | int exact_match = FALSE; | 140 | int exact_match = FALSE; |
141 | int freespace_ignore_reserved = FALSE; | ||
141 | char *warn_freespace_units = NULL; | 142 | char *warn_freespace_units = NULL; |
142 | char *crit_freespace_units = NULL; | 143 | char *crit_freespace_units = NULL; |
143 | char *warn_freespace_percent = NULL; | 144 | char *warn_freespace_percent = NULL; |
@@ -431,6 +432,7 @@ process_arguments (int argc, char **argv) | |||
431 | {"eregi-partition", required_argument, 0, 'R'}, | 432 | {"eregi-partition", required_argument, 0, 'R'}, |
432 | {"ereg-path", required_argument, 0, 'r'}, | 433 | {"ereg-path", required_argument, 0, 'r'}, |
433 | {"ereg-partition", required_argument, 0, 'r'}, | 434 | {"ereg-partition", required_argument, 0, 'r'}, |
435 | {"freespace-ignore-reserved", no_argument, 0, 'f'}, | ||
434 | {"ignore-ereg-path", required_argument, 0, 'i'}, | 436 | {"ignore-ereg-path", required_argument, 0, 'i'}, |
435 | {"ignore-ereg-partition", required_argument, 0, 'i'}, | 437 | {"ignore-ereg-partition", required_argument, 0, 'i'}, |
436 | {"ignore-eregi-path", required_argument, 0, 'I'}, | 438 | {"ignore-eregi-path", required_argument, 0, 'I'}, |
@@ -459,7 +461,7 @@ process_arguments (int argc, char **argv) | |||
459 | strcpy (argv[c], "-t"); | 461 | strcpy (argv[c], "-t"); |
460 | 462 | ||
461 | while (1) { | 463 | while (1) { |
462 | c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option); | 464 | c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option); |
463 | 465 | ||
464 | if (c == -1 || c == EOF) | 466 | if (c == -1 || c == EOF) |
465 | break; | 467 | break; |
@@ -616,6 +618,9 @@ process_arguments (int argc, char **argv) | |||
616 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n")); | 618 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n")); |
617 | exact_match = TRUE; | 619 | exact_match = TRUE; |
618 | break; | 620 | break; |
621 | case 'f': | ||
622 | freespace_ignore_reserved = TRUE; | ||
623 | break; | ||
619 | case 'g': | 624 | case 'g': |
620 | if (path_selected) | 625 | if (path_selected) |
621 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n")); | 626 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n")); |
@@ -881,6 +886,8 @@ print_help (void) | |||
881 | printf (" %s\n", _("For paths or partitions specified with -p, only check for exact paths")); | 886 | printf (" %s\n", _("For paths or partitions specified with -p, only check for exact paths")); |
882 | printf (" %s\n", "-e, --errors-only"); | 887 | printf (" %s\n", "-e, --errors-only"); |
883 | printf (" %s\n", _("Display only devices/mountpoints with errors")); | 888 | printf (" %s\n", _("Display only devices/mountpoints with errors")); |
889 | printf (" %s\n", "-f, --freespace-ignore-reserved"); | ||
890 | printf (" %s\n", _("Don't account root-reserved blocks into freespace in perfdata")); | ||
884 | printf (" %s\n", "-g, --group=NAME"); | 891 | printf (" %s\n", "-g, --group=NAME"); |
885 | printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together")); | 892 | printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together")); |
886 | printf (" %s\n", "-k, --kilobytes"); | 893 | printf (" %s\n", "-k, --kilobytes"); |
@@ -933,7 +940,7 @@ print_usage (void) | |||
933 | { | 940 | { |
934 | printf ("%s\n", _("Usage:")); | 941 | printf ("%s\n", _("Usage:")); |
935 | printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname); | 942 | printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname); |
936 | printf ("[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); | 943 | printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); |
937 | printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); | 944 | printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); |
938 | } | 945 | } |
939 | 946 | ||
@@ -1006,13 +1013,19 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1006 | 1013 | ||
1007 | void | 1014 | void |
1008 | get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | 1015 | get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { |
1009 | p->total = fsp->fsu_blocks; | ||
1010 | /* 2007-12-08 - Workaround for Gnulib reporting insanely high available | 1016 | /* 2007-12-08 - Workaround for Gnulib reporting insanely high available |
1011 | * space on BSD (the actual value should be negative but fsp->fsu_bavail | 1017 | * space on BSD (the actual value should be negative but fsp->fsu_bavail |
1012 | * is unsigned) */ | 1018 | * is unsigned) */ |
1013 | p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail; | 1019 | p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail; |
1014 | p->available_to_root = fsp->fsu_bfree; | 1020 | p->available_to_root = fsp->fsu_bfree; |
1015 | p->used = p->total - p->available_to_root; | 1021 | p->used = fsp->fsu_blocks - fsp->fsu_bfree; |
1022 | if (freespace_ignore_reserved) { | ||
1023 | /* option activated : we substract the root-reserved space from the total */ | ||
1024 | p->total = fsp->fsu_blocks - p->available_to_root + p->available; | ||
1025 | } else { | ||
1026 | /* default behaviour : take all the blocks into account */ | ||
1027 | p->total = fsp->fsu_blocks; | ||
1028 | } | ||
1016 | 1029 | ||
1017 | p->dused_units = p->used*fsp->fsu_blocksize/mult; | 1030 | p->dused_units = p->used*fsp->fsu_blocksize/mult; |
1018 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; | 1031 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 7c3bc4b9..bae38300 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -57,7 +57,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
57 | #define WARN_STRING 16 | 57 | #define WARN_STRING 16 |
58 | #define WARN_REGEX 32 | 58 | #define WARN_REGEX 32 |
59 | 59 | ||
60 | #define MAX_OIDS 8 | 60 | #define OID_COUNT_STEP 8 |
61 | 61 | ||
62 | /* Longopts only arguments */ | 62 | /* Longopts only arguments */ |
63 | #define L_CALCULATE_RATE CHAR_MAX+1 | 63 | #define L_CALCULATE_RATE CHAR_MAX+1 |
@@ -112,6 +112,7 @@ char *privproto = NULL; | |||
112 | char *authpasswd = NULL; | 112 | char *authpasswd = NULL; |
113 | char *privpasswd = NULL; | 113 | char *privpasswd = NULL; |
114 | char **oids = NULL; | 114 | char **oids = NULL; |
115 | size_t oids_size = NULL; | ||
115 | char *label; | 116 | char *label; |
116 | char *units; | 117 | char *units; |
117 | char *port; | 118 | char *port; |
@@ -121,19 +122,22 @@ int invert_search=0; | |||
121 | char **labels = NULL; | 122 | char **labels = NULL; |
122 | char **unitv = NULL; | 123 | char **unitv = NULL; |
123 | size_t nlabels = 0; | 124 | size_t nlabels = 0; |
124 | size_t labels_size = 8; | 125 | size_t labels_size = OID_COUNT_STEP; |
125 | size_t nunits = 0; | 126 | size_t nunits = 0; |
126 | size_t unitv_size = 8; | 127 | size_t unitv_size = OID_COUNT_STEP; |
127 | int numoids = 0; | 128 | int numoids = 0; |
128 | int numauthpriv = 0; | 129 | int numauthpriv = 0; |
129 | int verbose = 0; | 130 | int verbose = 0; |
130 | int usesnmpgetnext = FALSE; | 131 | int usesnmpgetnext = FALSE; |
131 | char *warning_thresholds = NULL; | 132 | char *warning_thresholds = NULL; |
132 | char *critical_thresholds = NULL; | 133 | char *critical_thresholds = NULL; |
133 | thresholds *thlds[MAX_OIDS]; | 134 | thresholds **thlds; |
134 | double response_value[MAX_OIDS]; | 135 | size_t thlds_size = OID_COUNT_STEP; |
136 | double *response_value; | ||
137 | size_t response_size = OID_COUNT_STEP; | ||
135 | int retries = 0; | 138 | int retries = 0; |
136 | int eval_method[MAX_OIDS]; | 139 | int *eval_method; |
140 | size_t eval_size = OID_COUNT_STEP; | ||
137 | char *delimiter; | 141 | char *delimiter; |
138 | char *output_delim; | 142 | char *output_delim; |
139 | char *miblist = NULL; | 143 | char *miblist = NULL; |
@@ -142,7 +146,8 @@ int calculate_rate = 0; | |||
142 | double offset = 0.0; | 146 | double offset = 0.0; |
143 | int rate_multiplier = 1; | 147 | int rate_multiplier = 1; |
144 | state_data *previous_state; | 148 | state_data *previous_state; |
145 | double previous_value[MAX_OIDS]; | 149 | double *previous_value; |
150 | size_t previous_size = OID_COUNT_STEP; | ||
146 | int perf_labels = 1; | 151 | int perf_labels = 1; |
147 | 152 | ||
148 | 153 | ||
@@ -150,16 +155,18 @@ static char *fix_snmp_range(char *th) | |||
150 | { | 155 | { |
151 | double left, right; | 156 | double left, right; |
152 | char *colon, *ret; | 157 | char *colon, *ret; |
153 | if (!(colon = strchr(th, ':'))) | 158 | |
159 | if ((colon = strchr(th, ':')) == NULL || *(colon + 1) == '\0') | ||
154 | return th; | 160 | return th; |
155 | *colon = 0; | ||
156 | 161 | ||
157 | left = strtod(th, NULL); | 162 | left = strtod(th, NULL); |
158 | right = strtod(colon + 1, NULL); | 163 | right = strtod(colon + 1, NULL); |
159 | if (right >= left) { | 164 | if (right >= left) |
160 | return th; | 165 | return th; |
161 | } | 166 | |
162 | ret = malloc(strlen(th) + strlen(colon + 1) + 2); | 167 | if ((ret = malloc(strlen(th) + 2)) == NULL) |
168 | die(STATE_UNKNOWN, _("Cannot malloc")); | ||
169 | *colon = '\0'; | ||
163 | sprintf(ret, "@%s:%s", colon + 1, th); | 170 | sprintf(ret, "@%s:%s", colon + 1, th); |
164 | free(th); | 171 | free(th); |
165 | return ret; | 172 | return ret; |
@@ -204,8 +211,11 @@ main (int argc, char **argv) | |||
204 | 211 | ||
205 | labels = malloc (labels_size * sizeof(*labels)); | 212 | labels = malloc (labels_size * sizeof(*labels)); |
206 | unitv = malloc (unitv_size * sizeof(*unitv)); | 213 | unitv = malloc (unitv_size * sizeof(*unitv)); |
207 | for (i = 0; i < MAX_OIDS; i++) | 214 | thlds = malloc (thlds_size * sizeof(*thlds)); |
208 | eval_method[i] = CHECK_UNDEF; | 215 | response_value = malloc (response_size * sizeof(*response_value)); |
216 | previous_value = malloc (previous_size * sizeof(*previous_value)); | ||
217 | eval_method = calloc (eval_size, sizeof(*eval_method)); | ||
218 | oids = calloc(oids_size, sizeof (char *)); | ||
209 | 219 | ||
210 | label = strdup ("SNMP"); | 220 | label = strdup ("SNMP"); |
211 | units = strdup (""); | 221 | units = strdup (""); |
@@ -223,13 +233,14 @@ main (int argc, char **argv) | |||
223 | 233 | ||
224 | np_set_args(argc, argv); | 234 | np_set_args(argc, argv); |
225 | 235 | ||
236 | time(¤t_time); | ||
237 | |||
226 | if (process_arguments (argc, argv) == ERROR) | 238 | if (process_arguments (argc, argv) == ERROR) |
227 | usage4 (_("Could not parse arguments")); | 239 | usage4 (_("Could not parse arguments")); |
228 | 240 | ||
229 | if(calculate_rate) { | 241 | if(calculate_rate) { |
230 | if (!strcmp(label, "SNMP")) | 242 | if (!strcmp(label, "SNMP")) |
231 | label = strdup("SNMP RATE"); | 243 | label = strdup("SNMP RATE"); |
232 | time(¤t_time); | ||
233 | i=0; | 244 | i=0; |
234 | previous_state = np_state_read(); | 245 | previous_state = np_state_read(); |
235 | if(previous_state!=NULL) { | 246 | if(previous_state!=NULL) { |
@@ -238,6 +249,10 @@ main (int argc, char **argv) | |||
238 | while((ap = strsep(&previous_string, ":")) != NULL) { | 249 | while((ap = strsep(&previous_string, ":")) != NULL) { |
239 | if(verbose>2) | 250 | if(verbose>2) |
240 | printf("State for %d=%s\n", i, ap); | 251 | printf("State for %d=%s\n", i, ap); |
252 | while (i >= previous_size) { | ||
253 | previous_size += OID_COUNT_STEP; | ||
254 | previous_value = realloc(previous_value, previous_size * sizeof(*previous_value)); | ||
255 | } | ||
241 | previous_value[i++]=strtod(ap,NULL); | 256 | previous_value[i++]=strtod(ap,NULL); |
242 | } | 257 | } |
243 | } | 258 | } |
@@ -253,6 +268,11 @@ main (int argc, char **argv) | |||
253 | w = w ? fix_snmp_range(w) : NULL; | 268 | w = w ? fix_snmp_range(w) : NULL; |
254 | c = c ? fix_snmp_range(c) : NULL; | 269 | c = c ? fix_snmp_range(c) : NULL; |
255 | 270 | ||
271 | while (i >= thlds_size) { | ||
272 | thlds_size += OID_COUNT_STEP; | ||
273 | thlds = realloc(thlds, thlds_size * sizeof(*thlds)); | ||
274 | } | ||
275 | |||
256 | /* Skip empty thresholds, while avoiding segfault */ | 276 | /* Skip empty thresholds, while avoiding segfault */ |
257 | set_thresholds(&thlds[i], | 277 | set_thresholds(&thlds[i], |
258 | w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL, | 278 | w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL, |
@@ -432,6 +452,10 @@ main (int argc, char **argv) | |||
432 | ptr = strpbrk (show, "0123456789"); | 452 | ptr = strpbrk (show, "0123456789"); |
433 | if (ptr == NULL) | 453 | if (ptr == NULL) |
434 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); | 454 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); |
455 | while (i >= response_size) { | ||
456 | response_size += OID_COUNT_STEP; | ||
457 | response_value = realloc(response_value, response_size * sizeof(*response_value)); | ||
458 | } | ||
435 | response_value[i] = strtod (ptr, NULL) + offset; | 459 | response_value[i] = strtod (ptr, NULL) + offset; |
436 | 460 | ||
437 | if(calculate_rate) { | 461 | if(calculate_rate) { |
@@ -459,7 +483,7 @@ main (int argc, char **argv) | |||
459 | } | 483 | } |
460 | 484 | ||
461 | /* Process this block for string matching */ | 485 | /* Process this block for string matching */ |
462 | else if (eval_method[i] & CRIT_STRING) { | 486 | else if (eval_size > i && eval_method[i] & CRIT_STRING) { |
463 | if (strcmp (show, string_value)) | 487 | if (strcmp (show, string_value)) |
464 | iresult = (invert_search==0) ? STATE_CRITICAL : STATE_OK; | 488 | iresult = (invert_search==0) ? STATE_CRITICAL : STATE_OK; |
465 | else | 489 | else |
@@ -467,7 +491,7 @@ main (int argc, char **argv) | |||
467 | } | 491 | } |
468 | 492 | ||
469 | /* Process this block for regex matching */ | 493 | /* Process this block for regex matching */ |
470 | else if (eval_method[i] & CRIT_REGEX) { | 494 | else if (eval_size > i && eval_method[i] & CRIT_REGEX) { |
471 | excode = regexec (&preg, response, 10, pmatch, eflags); | 495 | excode = regexec (&preg, response, 10, pmatch, eflags); |
472 | if (excode == 0) { | 496 | if (excode == 0) { |
473 | iresult = (invert_search==0) ? STATE_OK : STATE_CRITICAL; | 497 | iresult = (invert_search==0) ? STATE_OK : STATE_CRITICAL; |
@@ -485,9 +509,9 @@ main (int argc, char **argv) | |||
485 | /* Process this block for existence-nonexistence checks */ | 509 | /* Process this block for existence-nonexistence checks */ |
486 | /* TV: Should this be outside of this else block? */ | 510 | /* TV: Should this be outside of this else block? */ |
487 | else { | 511 | else { |
488 | if (eval_method[i] & CRIT_PRESENT) | 512 | if (eval_size > i && eval_method[i] & CRIT_PRESENT) |
489 | iresult = STATE_CRITICAL; | 513 | iresult = STATE_CRITICAL; |
490 | else if (eval_method[i] & WARN_PRESENT) | 514 | else if (eval_size > i && eval_method[i] & WARN_PRESENT) |
491 | iresult = STATE_WARNING; | 515 | iresult = STATE_WARNING; |
492 | else if (response && iresult == STATE_DEPENDENT) | 516 | else if (response && iresult == STATE_DEPENDENT) |
493 | iresult = STATE_OK; | 517 | iresult = STATE_OK; |
@@ -727,23 +751,36 @@ process_arguments (int argc, char **argv) | |||
727 | */ | 751 | */ |
728 | needmibs = TRUE; | 752 | needmibs = TRUE; |
729 | } | 753 | } |
730 | if (!oids) oids = calloc(MAX_OIDS, sizeof (char *)); | 754 | for (ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", "), j++) { |
731 | for (ptr = strtok(optarg, ", "); ptr != NULL && j < MAX_OIDS; ptr = strtok(NULL, ", "), j++) { | 755 | while (j >= oids_size) { |
756 | oids_size += OID_COUNT_STEP; | ||
757 | oids = realloc(oids, oids_size * sizeof (*oids)); | ||
758 | } | ||
732 | oids[j] = strdup(ptr); | 759 | oids[j] = strdup(ptr); |
733 | } | 760 | } |
734 | numoids = j; | 761 | numoids = j; |
735 | if (c == 'E' || c == 'e') { | 762 | if (c == 'E' || c == 'e') { |
736 | jj++; | 763 | jj++; |
737 | ii++; | 764 | ii++; |
765 | while (j+1 >= eval_size) { | ||
766 | eval_size += OID_COUNT_STEP; | ||
767 | eval_method = realloc(eval_method, eval_size * sizeof(*eval_method)); | ||
768 | memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); | ||
769 | } | ||
770 | if (c == 'E') | ||
771 | eval_method[j+1] |= WARN_PRESENT; | ||
772 | else if (c == 'e') | ||
773 | eval_method[j+1] |= CRIT_PRESENT; | ||
738 | } | 774 | } |
739 | if (c == 'E') | ||
740 | eval_method[j+1] |= WARN_PRESENT; | ||
741 | else if (c == 'e') | ||
742 | eval_method[j+1] |= CRIT_PRESENT; | ||
743 | break; | 775 | break; |
744 | case 's': /* string or substring */ | 776 | case 's': /* string or substring */ |
745 | strncpy (string_value, optarg, sizeof (string_value) - 1); | 777 | strncpy (string_value, optarg, sizeof (string_value) - 1); |
746 | string_value[sizeof (string_value) - 1] = 0; | 778 | string_value[sizeof (string_value) - 1] = 0; |
779 | while (jj >= eval_size) { | ||
780 | eval_size += OID_COUNT_STEP; | ||
781 | eval_method = realloc(eval_method, eval_size * sizeof(*eval_method)); | ||
782 | memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); | ||
783 | } | ||
747 | eval_method[jj++] = CRIT_STRING; | 784 | eval_method[jj++] = CRIT_STRING; |
748 | ii++; | 785 | ii++; |
749 | break; | 786 | break; |
@@ -759,6 +796,11 @@ process_arguments (int argc, char **argv) | |||
759 | printf (_("Could Not Compile Regular Expression")); | 796 | printf (_("Could Not Compile Regular Expression")); |
760 | return ERROR; | 797 | return ERROR; |
761 | } | 798 | } |
799 | while (jj >= eval_size) { | ||
800 | eval_size += OID_COUNT_STEP; | ||
801 | eval_method = realloc(eval_method, eval_size * sizeof(*eval_method)); | ||
802 | memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); | ||
803 | } | ||
762 | eval_method[jj++] = CRIT_REGEX; | 804 | eval_method[jj++] = CRIT_REGEX; |
763 | ii++; | 805 | ii++; |
764 | break; | 806 | break; |
@@ -1125,7 +1167,7 @@ print_help (void) | |||
1125 | printf ("\n"); | 1167 | printf ("\n"); |
1126 | printf ("%s\n", _("Notes:")); | 1168 | printf ("%s\n", _("Notes:")); |
1127 | printf (" %s\n", _("- Multiple OIDs (and labels) may be indicated by a comma or space-delimited ")); | 1169 | printf (" %s\n", _("- Multiple OIDs (and labels) may be indicated by a comma or space-delimited ")); |
1128 | printf (" %s %i %s\n", _("list (lists with internal spaces must be quoted). Maximum:"), MAX_OIDS, _("OIDs.")); | 1170 | printf (" %s\n", _("list (lists with internal spaces must be quoted).")); |
1129 | 1171 | ||
1130 | printf(" -%s", UT_THRESHOLDS_NOTES); | 1172 | printf(" -%s", UT_THRESHOLDS_NOTES); |
1131 | 1173 | ||
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index 04bf500b..6de5f299 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
@@ -8,145 +8,164 @@ use strict; | |||
8 | use Test::More; | 8 | use Test::More; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $tests = 8+42+2+2; | 11 | BEGIN { |
12 | plan tests => $tests; | 12 | plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp"; |
13 | plan tests => 60; | ||
14 | } | ||
15 | |||
13 | my $res; | 16 | my $res; |
14 | 17 | ||
18 | my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost", | ||
19 | "A host providing an SNMP Service"); | ||
20 | |||
21 | my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", | ||
22 | "The SNMP Community string for SNMP Testing (assumes snmp v1)" ); | ||
23 | |||
24 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
25 | "The hostname of system not responsive to network requests" ); | ||
26 | |||
27 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
28 | "An invalid (not known to DNS) hostname" ); | ||
29 | |||
30 | $res = NPTest->testCmd( "./check_snmp -t 1" ); | ||
31 | is( $res->return_code, 3, "No host name" ); | ||
32 | is( $res->output, "No host specified" ); | ||
33 | |||
34 | $res = NPTest->testCmd( "./check_snmp -H fakehostname" ); | ||
35 | is( $res->return_code, 3, "No OIDs specified" ); | ||
36 | is( $res->output, "No OIDs specified" ); | ||
37 | |||
38 | $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 --seclevel=rubbish" ); | ||
39 | is( $res->return_code, 3, "Invalid seclevel" ); | ||
40 | like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" ); | ||
41 | |||
42 | $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" ); | ||
43 | is( $res->return_code, 3, "Invalid protocol" ); | ||
44 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); | ||
45 | |||
46 | SKIP: { | ||
47 | skip "no snmp host defined", 38 if ( ! $host_snmp ); | ||
48 | |||
49 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | ||
50 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); | ||
51 | like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK"); | ||
52 | $res->output =~ /^SNMP OK - (\d+)/; | ||
53 | my $value = $1; | ||
54 | cmp_ok( $value, ">", 0, "Got a time value" ); | ||
55 | like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it"); | ||
56 | |||
57 | |||
58 | # some more threshold tests | ||
59 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1"); | ||
60 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" ); | ||
61 | |||
62 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:"); | ||
63 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" ); | ||
64 | |||
65 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c ~:1"); | ||
66 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" ); | ||
67 | |||
68 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:10"); | ||
69 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" ); | ||
70 | |||
71 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c \@1:10"); | ||
72 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" ); | ||
73 | |||
74 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 10:1"); | ||
75 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" ); | ||
76 | |||
77 | |||
78 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:"); | ||
79 | cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" ); | ||
80 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); | ||
81 | |||
82 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); | ||
83 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); | ||
84 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); | ||
85 | |||
86 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0"); | ||
87 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" ); | ||
88 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
89 | |||
90 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0"); | ||
91 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" ); | ||
92 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
93 | |||
94 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); | ||
95 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); | ||
96 | like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); | ||
97 | |||
98 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); | ||
99 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); | ||
100 | like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); | ||
101 | |||
102 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); | ||
103 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); | ||
104 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); | ||
105 | |||
106 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); | ||
107 | cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" ); | ||
108 | like($res->output, "/^SNMP OK - 2 1/", "Got two values back" ); | ||
109 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | ||
110 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | ||
111 | |||
112 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2"); | ||
113 | cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" ); | ||
114 | like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" ); | ||
115 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | ||
116 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | ||
117 | |||
118 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:"); | ||
119 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses"); | ||
120 | like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses"); | ||
121 | |||
122 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0"); | ||
123 | cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds"); | ||
124 | like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format"); | ||
125 | |||
126 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3"); | ||
127 | $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/; | ||
128 | my $lower = $1 - 0.05; | ||
129 | my $higher = $1 + 0.05; | ||
130 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher"); | ||
131 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments"); | ||
132 | |||
133 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2"); | ||
134 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold"); | ||
135 | like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds"); | ||
136 | |||
137 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''"); | ||
138 | cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash"); | ||
139 | |||
140 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2"); | ||
141 | cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check"); | ||
142 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed"); | ||
143 | |||
144 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,"); | ||
145 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); | ||
146 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed"); | ||
147 | |||
148 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'"); | ||
149 | cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold"); | ||
150 | like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric"); | ||
151 | |||
152 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0"); | ||
153 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | ||
154 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); | ||
155 | } | ||
156 | |||
157 | # These checks need a complete command line. An invalid community is used so | ||
158 | # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway | ||
15 | SKIP: { | 159 | SKIP: { |
16 | skip "check_snmp is not compiled", $tests if ( ! -x "./check_snmp" ); | 160 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); |
17 | 161 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | |
18 | my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost", | 162 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); |
19 | "A host providing an SNMP Service"); | 163 | like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem"); |
20 | 164 | } | |
21 | my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", | ||
22 | "The SNMP Community string for SNMP Testing (assumes snmp v1)" ); | ||
23 | |||
24 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
25 | "The hostname of system not responsive to network requests" ); | ||
26 | |||
27 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
28 | "An invalid (not known to DNS) hostname" ); | ||
29 | |||
30 | $res = NPTest->testCmd( "./check_snmp -t 1" ); | ||
31 | is( $res->return_code, 3, "No host name" ); | ||
32 | is( $res->output, "No host specified" ); | ||
33 | |||
34 | $res = NPTest->testCmd( "./check_snmp -H fakehostname" ); | ||
35 | is( $res->return_code, 3, "No OIDs specified" ); | ||
36 | is( $res->output, "No OIDs specified" ); | ||
37 | |||
38 | $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 --seclevel=rubbish" ); | ||
39 | is( $res->return_code, 3, "Invalid seclevel" ); | ||
40 | like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" ); | ||
41 | |||
42 | $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" ); | ||
43 | is( $res->return_code, 3, "Invalid protocol" ); | ||
44 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); | ||
45 | |||
46 | SKIP: { | ||
47 | skip "no snmp host defined", 38 if ( ! $host_snmp ); | ||
48 | |||
49 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | ||
50 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); | ||
51 | like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK"); | ||
52 | $res->output =~ /^SNMP OK - (\d+)/; | ||
53 | my $value = $1; | ||
54 | cmp_ok( $value, ">", 0, "Got a time value" ); | ||
55 | like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it"); | ||
56 | |||
57 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:"); | ||
58 | cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" ); | ||
59 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); | ||
60 | |||
61 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); | ||
62 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); | ||
63 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); | ||
64 | |||
65 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0"); | ||
66 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" ); | ||
67 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
68 | |||
69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0"); | ||
70 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" ); | ||
71 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
72 | |||
73 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); | ||
74 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); | ||
75 | like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); | ||
76 | |||
77 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); | ||
78 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); | ||
79 | like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); | ||
80 | |||
81 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); | ||
82 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); | ||
83 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); | ||
84 | |||
85 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); | ||
86 | cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" ); | ||
87 | like($res->output, "/^SNMP OK - 2 1/", "Got two values back" ); | ||
88 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | ||
89 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | ||
90 | |||
91 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2"); | ||
92 | cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" ); | ||
93 | like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" ); | ||
94 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | ||
95 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | ||
96 | |||
97 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:"); | ||
98 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses"); | ||
99 | like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses"); | ||
100 | |||
101 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0"); | ||
102 | cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds"); | ||
103 | like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format"); | ||
104 | |||
105 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3"); | ||
106 | $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/; | ||
107 | my $lower = $1 - 0.05; | ||
108 | my $higher = $1 + 0.05; | ||
109 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher"); | ||
110 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments"); | ||
111 | |||
112 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2"); | ||
113 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold"); | ||
114 | like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds"); | ||
115 | |||
116 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''"); | ||
117 | cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash"); | ||
118 | |||
119 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2"); | ||
120 | cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check"); | ||
121 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed"); | ||
122 | |||
123 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,"); | ||
124 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); | ||
125 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed"); | ||
126 | |||
127 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'"); | ||
128 | cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold"); | ||
129 | like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric"); | ||
130 | |||
131 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0"); | ||
132 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | ||
133 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); | ||
134 | } | ||
135 | |||
136 | # These checks need a complete command line. An invalid community is used so | ||
137 | # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway | ||
138 | SKIP: { | ||
139 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); | ||
140 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | ||
141 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | ||
142 | like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem"); | ||
143 | } | ||
144 | |||
145 | SKIP: { | ||
146 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); | ||
147 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | ||
148 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | ||
149 | like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host"); | ||
150 | } | ||
151 | 165 | ||
166 | SKIP: { | ||
167 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); | ||
168 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | ||
169 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | ||
170 | like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host"); | ||
152 | } | 171 | } |
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t index d6808bf2..c100cadd 100644 --- a/plugins/t/check_tcp.t +++ b/plugins/t/check_tcp.t | |||
@@ -32,7 +32,7 @@ $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 | |||
32 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); | 32 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); |
33 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); | 33 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); |
34 | $t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 ); | 34 | $t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 ); |
35 | $t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 0 ); | 35 | $t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 1 ); |
36 | $t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 ); | 36 | $t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 ); |
37 | $t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 ); | 37 | $t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 ); |
38 | $t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 ); | 38 | $t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 ); |
@@ -44,6 +44,4 @@ if ( ! scalar( @tests ) ) | |||
44 | 44 | ||
45 | use Test::Harness; | 45 | use Test::Harness; |
46 | 46 | ||
47 | $Test::Harness::verbose=1; | ||
48 | |||
49 | runtests( @tests ); | 47 | runtests( @tests ); |
diff --git a/tools/build_perl_modules b/tools/build_perl_modules index 9b0c3c20..5a57a471 100755 --- a/tools/build_perl_modules +++ b/tools/build_perl_modules | |||
@@ -188,6 +188,7 @@ foreach my $tarball (@tarballs) { | |||
188 | 188 | ||
189 | # Don't compile if already done - this is because of invocating this | 189 | # Don't compile if already done - this is because of invocating this |
190 | # script at different stages | 190 | # script at different stages |
191 | print "******************** $tarball\n"; | ||
191 | if ( $built_modules{$dir} || !-f "$dir/Makefile" && !-f "$dir/Build" ) { | 192 | if ( $built_modules{$dir} || !-f "$dir/Makefile" && !-f "$dir/Build" ) { |
192 | $built_modules{$dir}++; | 193 | $built_modules{$dir}++; |
193 | my @missing; | 194 | my @missing; |