aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--doc/developer-guidelines.sgml41
-rw-r--r--perlmods/install_order10
-rw-r--r--plugins/check_disk.c21
-rw-r--r--plugins/check_snmp.c94
-rw-r--r--plugins/t/check_snmp.t293
-rw-r--r--plugins/t/check_tcp.t2
-rwxr-xr-xtest.pl.in2
-rwxr-xr-xtools/build_perl_modules1
9 files changed, 275 insertions, 191 deletions
diff --git a/NEWS b/NEWS
index 1668dc4e..0261e491 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ This file documents the major additions and syntax changes between releases.
Added -4/-6 options to check_dig (Ville Mattila)
New check_oracle --connect option to perform real login
New check_nagios -t option to override the default timeout
+ New check_disk -f/--freespace-ignore-reserved option to ignore space reserved for root
New check_disk -N/--include-type option to limit the filesystem types to check
Allow for building the plugins in parallel
Add --without-{dbi,ldap,radius} options to ./configure
@@ -29,6 +30,7 @@ This file documents the major additions and syntax changes between releases.
New check_mysql -f option to specify a client options file
New check_mysql -g option to specify a client options group
New check_snmp --offset option to allow for adding/substracting an offset value to sensor data
+ Let check_snmp support an arbitrary number of OIDs
Let check_ide_smart support NetBSD
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 @@
</author>
</authorgroup>
- <pubdate>2009</pubdate>
+ <pubdate>2013</pubdate>
<title>Nagios plug-in development guidelines</title>
<revhistory>
@@ -22,7 +22,7 @@
</revhistory>
<copyright>
- <year>2000 - 2009</year>
+ <year>2000 - 2013</year>
<holder>Nagios Plugins Development Team</holder>
</copyright>
@@ -34,7 +34,7 @@
the plug-in developers and encourage the standarization of the
different kind of plug-ins: C, shell, perl, python, etc.</para>
- <para>Nagios Plug-in Development Guidelines Copyright (C) 2000-2009
+ <para>Nagios Plug-in Development Guidelines Copyright (C) 2000-2013
(Nagios Plugins Team)</para>
<para>Permission is granted to make and distribute verbatim
@@ -83,10 +83,18 @@
STDOUT and not print to STDERR.</para>
<section><title>Print only one line of text</title>
- <para>Nagios will only grab the first line of text from STDOUT
- when it notifies contacts about potential problems. If you print
- multiple lines, you're out of luck (though this will be a feature of
- Nagios 3). Remember, keep your output short and to the point.</para>
+ <para>Starting with version 3, Nagios will process plugins' multiline
+ output, which should be formatted as:</para>
+ <literallayout>
+ SERVICE STATUS: First line of output | First part of performance data
+ Any number of subsequent lines of output, but note that buffers
+ may have a limited size | Second part of performance data, which
+ may have continuation lines, too
+ </literallayout>
+ <para>Note, however, that the default configs still do not include
+ the output's continuation lines into the notifications sent when
+ Nagios notifies contacts about potential problems.
+ Thus, keep your output short and to the point.</para>
<para>Output should be in the format:</para>
<literallayout>
@@ -269,10 +277,6 @@
<entry>@10:20</entry>
<entry>&ge; 10 and &le; 20, (inside the range of {10 .. 20})</entry>
</row>
- <row>
- <entry>10</entry>
- <entry>&lt; 0 or &gt; 10, (outside the range of {0 .. 10})</entry>
- </row>
</tbody>
</tgroup>
</table>
@@ -319,10 +323,14 @@
</section>
<section><title>Performance data</title>
- <para>Performance data is defined by Nagios as "everything after the | of the plugin output" -
- please refer to Nagios documentation for information on capturing this data to logfiles.
- However, it is the responsibility of the plugin writer to ensure the
- performance data is in a "Nagios plugins" format.
+ <para>Nagios 3 and newer will concatenate the parts following a "|" in a) the first
+ line output by the plugin, and b) in the second to last line, into a string it
+ passes to whatever performance data processing it has configured. (Note that it
+ currently does not insert additional whitespace between both, so the plugin needs
+ to provide some to prevent the last pair of a) and the first of b) getting run
+ together.) Please refer to the Nagios documentation for information on how to
+ configure such processing. However, it is the responsibility of the plugin writer
+ to ensure the performance data is in a "Nagios plugins" format.
This is the expected format:</para>
<literallayout>
@@ -351,7 +359,8 @@
<listitem><para>min and max are not required if UOM=%</para>
</listitem>
<listitem><para>value, min and max in class [-0-9.]. Must all be the
- same UOM</para>
+ same UOM. value may be a literal "U" instead, this would indicate that the
+ actual value couldn't be determined</para>
</listitem>
<listitem><para>warn and crit are in the range format (see
<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 @@
default:
Test-Simple
Perl-OSType
-parent
-version
-Try-Tiny
-Module-Metadata
-Module-Runtime
Module-Implementation
+Module-Metadata
+version
Module-Build
+Module-Runtime
+parent
+Try-Tiny
Params-Validate
Math-Calc-Units
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;
int erronly = FALSE;
int display_mntp = FALSE;
int exact_match = FALSE;
+int freespace_ignore_reserved = FALSE;
char *warn_freespace_units = NULL;
char *crit_freespace_units = NULL;
char *warn_freespace_percent = NULL;
@@ -431,6 +432,7 @@ process_arguments (int argc, char **argv)
{"eregi-partition", required_argument, 0, 'R'},
{"ereg-path", required_argument, 0, 'r'},
{"ereg-partition", required_argument, 0, 'r'},
+ {"freespace-ignore-reserved", no_argument, 0, 'f'},
{"ignore-ereg-path", required_argument, 0, 'i'},
{"ignore-ereg-partition", required_argument, 0, 'i'},
{"ignore-eregi-path", required_argument, 0, 'I'},
@@ -459,7 +461,7 @@ process_arguments (int argc, char **argv)
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option);
+ c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option);
if (c == -1 || c == EOF)
break;
@@ -616,6 +618,9 @@ process_arguments (int argc, char **argv)
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n"));
exact_match = TRUE;
break;
+ case 'f':
+ freespace_ignore_reserved = TRUE;
+ break;
case 'g':
if (path_selected)
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n"));
@@ -881,6 +886,8 @@ print_help (void)
printf (" %s\n", _("For paths or partitions specified with -p, only check for exact paths"));
printf (" %s\n", "-e, --errors-only");
printf (" %s\n", _("Display only devices/mountpoints with errors"));
+ printf (" %s\n", "-f, --freespace-ignore-reserved");
+ printf (" %s\n", _("Don't account root-reserved blocks into freespace in perfdata"));
printf (" %s\n", "-g, --group=NAME");
printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together"));
printf (" %s\n", "-k, --kilobytes");
@@ -933,7 +940,7 @@ print_usage (void)
{
printf ("%s\n", _("Usage:"));
printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname);
- printf ("[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
+ printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n");
}
@@ -1006,13 +1013,19 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
void
get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
- p->total = fsp->fsu_blocks;
/* 2007-12-08 - Workaround for Gnulib reporting insanely high available
* space on BSD (the actual value should be negative but fsp->fsu_bavail
* is unsigned) */
p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail;
p->available_to_root = fsp->fsu_bfree;
- p->used = p->total - p->available_to_root;
+ p->used = fsp->fsu_blocks - fsp->fsu_bfree;
+ if (freespace_ignore_reserved) {
+ /* option activated : we substract the root-reserved space from the total */
+ p->total = fsp->fsu_blocks - p->available_to_root + p->available;
+ } else {
+ /* default behaviour : take all the blocks into account */
+ p->total = fsp->fsu_blocks;
+ }
p->dused_units = p->used*fsp->fsu_blocksize/mult;
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";
#define WARN_STRING 16
#define WARN_REGEX 32
-#define MAX_OIDS 8
+#define OID_COUNT_STEP 8
/* Longopts only arguments */
#define L_CALCULATE_RATE CHAR_MAX+1
@@ -112,6 +112,7 @@ char *privproto = NULL;
char *authpasswd = NULL;
char *privpasswd = NULL;
char **oids = NULL;
+size_t oids_size = NULL;
char *label;
char *units;
char *port;
@@ -121,19 +122,22 @@ int invert_search=0;
char **labels = NULL;
char **unitv = NULL;
size_t nlabels = 0;
-size_t labels_size = 8;
+size_t labels_size = OID_COUNT_STEP;
size_t nunits = 0;
-size_t unitv_size = 8;
+size_t unitv_size = OID_COUNT_STEP;
int numoids = 0;
int numauthpriv = 0;
int verbose = 0;
int usesnmpgetnext = FALSE;
char *warning_thresholds = NULL;
char *critical_thresholds = NULL;
-thresholds *thlds[MAX_OIDS];
-double response_value[MAX_OIDS];
+thresholds **thlds;
+size_t thlds_size = OID_COUNT_STEP;
+double *response_value;
+size_t response_size = OID_COUNT_STEP;
int retries = 0;
-int eval_method[MAX_OIDS];
+int *eval_method;
+size_t eval_size = OID_COUNT_STEP;
char *delimiter;
char *output_delim;
char *miblist = NULL;
@@ -142,7 +146,8 @@ int calculate_rate = 0;
double offset = 0.0;
int rate_multiplier = 1;
state_data *previous_state;
-double previous_value[MAX_OIDS];
+double *previous_value;
+size_t previous_size = OID_COUNT_STEP;
int perf_labels = 1;
@@ -150,16 +155,18 @@ static char *fix_snmp_range(char *th)
{
double left, right;
char *colon, *ret;
- if (!(colon = strchr(th, ':')))
+
+ if ((colon = strchr(th, ':')) == NULL || *(colon + 1) == '\0')
return th;
- *colon = 0;
left = strtod(th, NULL);
right = strtod(colon + 1, NULL);
- if (right >= left) {
+ if (right >= left)
return th;
- }
- ret = malloc(strlen(th) + strlen(colon + 1) + 2);
+
+ if ((ret = malloc(strlen(th) + 2)) == NULL)
+ die(STATE_UNKNOWN, _("Cannot malloc"));
+ *colon = '\0';
sprintf(ret, "@%s:%s", colon + 1, th);
free(th);
return ret;
@@ -204,8 +211,11 @@ main (int argc, char **argv)
labels = malloc (labels_size * sizeof(*labels));
unitv = malloc (unitv_size * sizeof(*unitv));
- for (i = 0; i < MAX_OIDS; i++)
- eval_method[i] = CHECK_UNDEF;
+ thlds = malloc (thlds_size * sizeof(*thlds));
+ response_value = malloc (response_size * sizeof(*response_value));
+ previous_value = malloc (previous_size * sizeof(*previous_value));
+ eval_method = calloc (eval_size, sizeof(*eval_method));
+ oids = calloc(oids_size, sizeof (char *));
label = strdup ("SNMP");
units = strdup ("");
@@ -223,13 +233,14 @@ main (int argc, char **argv)
np_set_args(argc, argv);
+ time(&current_time);
+
if (process_arguments (argc, argv) == ERROR)
usage4 (_("Could not parse arguments"));
if(calculate_rate) {
if (!strcmp(label, "SNMP"))
label = strdup("SNMP RATE");
- time(&current_time);
i=0;
previous_state = np_state_read();
if(previous_state!=NULL) {
@@ -238,6 +249,10 @@ main (int argc, char **argv)
while((ap = strsep(&previous_string, ":")) != NULL) {
if(verbose>2)
printf("State for %d=%s\n", i, ap);
+ while (i >= previous_size) {
+ previous_size += OID_COUNT_STEP;
+ previous_value = realloc(previous_value, previous_size * sizeof(*previous_value));
+ }
previous_value[i++]=strtod(ap,NULL);
}
}
@@ -253,6 +268,11 @@ main (int argc, char **argv)
w = w ? fix_snmp_range(w) : NULL;
c = c ? fix_snmp_range(c) : NULL;
+ while (i >= thlds_size) {
+ thlds_size += OID_COUNT_STEP;
+ thlds = realloc(thlds, thlds_size * sizeof(*thlds));
+ }
+
/* Skip empty thresholds, while avoiding segfault */
set_thresholds(&thlds[i],
w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL,
@@ -432,6 +452,10 @@ main (int argc, char **argv)
ptr = strpbrk (show, "0123456789");
if (ptr == NULL)
die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
+ while (i >= response_size) {
+ response_size += OID_COUNT_STEP;
+ response_value = realloc(response_value, response_size * sizeof(*response_value));
+ }
response_value[i] = strtod (ptr, NULL) + offset;
if(calculate_rate) {
@@ -459,7 +483,7 @@ main (int argc, char **argv)
}
/* Process this block for string matching */
- else if (eval_method[i] & CRIT_STRING) {
+ else if (eval_size > i && eval_method[i] & CRIT_STRING) {
if (strcmp (show, string_value))
iresult = (invert_search==0) ? STATE_CRITICAL : STATE_OK;
else
@@ -467,7 +491,7 @@ main (int argc, char **argv)
}
/* Process this block for regex matching */
- else if (eval_method[i] & CRIT_REGEX) {
+ else if (eval_size > i && eval_method[i] & CRIT_REGEX) {
excode = regexec (&preg, response, 10, pmatch, eflags);
if (excode == 0) {
iresult = (invert_search==0) ? STATE_OK : STATE_CRITICAL;
@@ -485,9 +509,9 @@ main (int argc, char **argv)
/* Process this block for existence-nonexistence checks */
/* TV: Should this be outside of this else block? */
else {
- if (eval_method[i] & CRIT_PRESENT)
+ if (eval_size > i && eval_method[i] & CRIT_PRESENT)
iresult = STATE_CRITICAL;
- else if (eval_method[i] & WARN_PRESENT)
+ else if (eval_size > i && eval_method[i] & WARN_PRESENT)
iresult = STATE_WARNING;
else if (response && iresult == STATE_DEPENDENT)
iresult = STATE_OK;
@@ -727,23 +751,36 @@ process_arguments (int argc, char **argv)
*/
needmibs = TRUE;
}
- if (!oids) oids = calloc(MAX_OIDS, sizeof (char *));
- for (ptr = strtok(optarg, ", "); ptr != NULL && j < MAX_OIDS; ptr = strtok(NULL, ", "), j++) {
+ for (ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", "), j++) {
+ while (j >= oids_size) {
+ oids_size += OID_COUNT_STEP;
+ oids = realloc(oids, oids_size * sizeof (*oids));
+ }
oids[j] = strdup(ptr);
}
numoids = j;
if (c == 'E' || c == 'e') {
jj++;
ii++;
+ while (j+1 >= eval_size) {
+ eval_size += OID_COUNT_STEP;
+ eval_method = realloc(eval_method, eval_size * sizeof(*eval_method));
+ memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8);
+ }
+ if (c == 'E')
+ eval_method[j+1] |= WARN_PRESENT;
+ else if (c == 'e')
+ eval_method[j+1] |= CRIT_PRESENT;
}
- if (c == 'E')
- eval_method[j+1] |= WARN_PRESENT;
- else if (c == 'e')
- eval_method[j+1] |= CRIT_PRESENT;
break;
case 's': /* string or substring */
strncpy (string_value, optarg, sizeof (string_value) - 1);
string_value[sizeof (string_value) - 1] = 0;
+ while (jj >= eval_size) {
+ eval_size += OID_COUNT_STEP;
+ eval_method = realloc(eval_method, eval_size * sizeof(*eval_method));
+ memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8);
+ }
eval_method[jj++] = CRIT_STRING;
ii++;
break;
@@ -759,6 +796,11 @@ process_arguments (int argc, char **argv)
printf (_("Could Not Compile Regular Expression"));
return ERROR;
}
+ while (jj >= eval_size) {
+ eval_size += OID_COUNT_STEP;
+ eval_method = realloc(eval_method, eval_size * sizeof(*eval_method));
+ memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8);
+ }
eval_method[jj++] = CRIT_REGEX;
ii++;
break;
@@ -1125,7 +1167,7 @@ print_help (void)
printf ("\n");
printf ("%s\n", _("Notes:"));
printf (" %s\n", _("- Multiple OIDs (and labels) may be indicated by a comma or space-delimited "));
- printf (" %s %i %s\n", _("list (lists with internal spaces must be quoted). Maximum:"), MAX_OIDS, _("OIDs."));
+ printf (" %s\n", _("list (lists with internal spaces must be quoted)."));
printf(" -%s", UT_THRESHOLDS_NOTES);
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;
use Test::More;
use NPTest;
-my $tests = 8+42+2+2;
-plan tests => $tests;
+BEGIN {
+ plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp";
+ plan tests => 60;
+}
+
my $res;
+my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost",
+ "A host providing an SNMP Service");
+
+my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
+ "The SNMP Community string for SNMP Testing (assumes snmp v1)" );
+
+my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
+ "The hostname of system not responsive to network requests" );
+
+my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
+ "An invalid (not known to DNS) hostname" );
+
+$res = NPTest->testCmd( "./check_snmp -t 1" );
+is( $res->return_code, 3, "No host name" );
+is( $res->output, "No host specified" );
+
+$res = NPTest->testCmd( "./check_snmp -H fakehostname" );
+is( $res->return_code, 3, "No OIDs specified" );
+is( $res->output, "No OIDs specified" );
+
+$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 --seclevel=rubbish" );
+is( $res->return_code, 3, "Invalid seclevel" );
+like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" );
+
+$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" );
+is( $res->return_code, 3, "Invalid protocol" );
+like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
+
+SKIP: {
+ skip "no snmp host defined", 38 if ( ! $host_snmp );
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
+ cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
+ like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK");
+ $res->output =~ /^SNMP OK - (\d+)/;
+ my $value = $1;
+ cmp_ok( $value, ">", 0, "Got a time value" );
+ like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it");
+
+
+ # some more threshold tests
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1");
+ cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" );
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:");
+ cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" );
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c ~:1");
+ cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" );
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:10");
+ cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" );
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c \@1:10");
+ cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" );
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 10:1");
+ cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" );
+
+
+ $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:");
+ cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" );
+ like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
+ cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
+ unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0");
+ cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" );
+ like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0");
+ cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" );
+ like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
+ cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
+ like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
+ cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
+ like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
+ cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
+ like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2");
+ cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" );
+ like($res->output, "/^SNMP OK - 2 1/", "Got two values back" );
+ like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
+ like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
+
+ $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");
+ cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" );
+ like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" );
+ like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
+ like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
+
+ $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:");
+ cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses");
+ like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0");
+ cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds");
+ like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3");
+ $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/;
+ my $lower = $1 - 0.05;
+ my $higher = $1 + 0.05;
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher");
+ cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments");
+
+ $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");
+ cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold");
+ 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");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''");
+ cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2");
+ cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check");
+ like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,");
+ cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds");
+ like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'");
+ cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold");
+ like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric");
+
+ $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0");
+ cmp_ok( $res->return_code, '==', 0, "Timetick used as a string");
+ 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");
+}
+
+# These checks need a complete command line. An invalid community is used so
+# the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway
SKIP: {
- skip "check_snmp is not compiled", $tests if ( ! -x "./check_snmp" );
-
- my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost",
- "A host providing an SNMP Service");
-
- my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
- "The SNMP Community string for SNMP Testing (assumes snmp v1)" );
-
- my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
- "The hostname of system not responsive to network requests" );
-
- my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
- "An invalid (not known to DNS) hostname" );
-
- $res = NPTest->testCmd( "./check_snmp -t 1" );
- is( $res->return_code, 3, "No host name" );
- is( $res->output, "No host specified" );
-
- $res = NPTest->testCmd( "./check_snmp -H fakehostname" );
- is( $res->return_code, 3, "No OIDs specified" );
- is( $res->output, "No OIDs specified" );
-
- $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 --seclevel=rubbish" );
- is( $res->return_code, 3, "Invalid seclevel" );
- like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" );
-
- $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" );
- is( $res->return_code, 3, "Invalid protocol" );
- like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
-
- SKIP: {
- skip "no snmp host defined", 38 if ( ! $host_snmp );
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
- cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
- like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK");
- $res->output =~ /^SNMP OK - (\d+)/;
- my $value = $1;
- cmp_ok( $value, ">", 0, "Got a time value" );
- like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it");
-
- $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:");
- cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" );
- like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
- cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
- unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0");
- cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" );
- like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0");
- cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" );
- like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
- cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
- like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
- cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
- like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
- cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
- like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2");
- cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" );
- like($res->output, "/^SNMP OK - 2 1/", "Got two values back" );
- like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
- like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
-
- $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");
- cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" );
- like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" );
- like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
- like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
-
- $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:");
- cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses");
- like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0");
- cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds");
- like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3");
- $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/;
- my $lower = $1 - 0.05;
- my $higher = $1 + 0.05;
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher");
- cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments");
-
- $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");
- cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold");
- 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");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''");
- cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2");
- cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check");
- like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,");
- cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds");
- like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'");
- cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold");
- like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric");
-
- $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0");
- cmp_ok( $res->return_code, '==', 0, "Timetick used as a string");
- 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");
- }
-
- # These checks need a complete command line. An invalid community is used so
- # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway
- SKIP: {
- skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
- $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
- cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
- like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem");
- }
-
- SKIP: {
- skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
- $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
- cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
- like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host");
- }
+ skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
+ $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
+ cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
+ like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem");
+}
+SKIP: {
+ skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
+ $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
+ cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
+ like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host");
}
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
$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 );
$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 );
$t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 );
-$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 0 );
+$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 1 );
$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 );
$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 );
$t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 );
diff --git a/test.pl.in b/test.pl.in
index 3834d3c3..85ac19da 100755
--- a/test.pl.in
+++ b/test.pl.in
@@ -44,6 +44,4 @@ if ( ! scalar( @tests ) )
use Test::Harness;
-$Test::Harness::verbose=1;
-
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) {
# Don't compile if already done - this is because of invocating this
# script at different stages
+ print "******************** $tarball\n";
if ( $built_modules{$dir} || !-f "$dir/Makefile" && !-f "$dir/Build" ) {
$built_modules{$dir}++;
my @missing;