mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-03-23 19:03:04 -04:00
Merge 1a42bd8fe2 into 2d4f98f50b
This commit is contained in:
commit
33f4e6de71
10 changed files with 115 additions and 17 deletions
|
|
@ -184,7 +184,7 @@ if test "$enable_libtap" = "yes" ; then
|
|||
EXTRA_TEST="test_utils test_tcp test_cmd test_base64"
|
||||
AC_SUBST(EXTRA_TEST)
|
||||
|
||||
EXTRA_PLUGIN_TESTS="tests/test_check_swap tests/test_check_disk"
|
||||
EXTRA_PLUGIN_TESTS="tests/test_check_swap tests/test_check_disk tests/test_check_snmp"
|
||||
AC_SUBST(EXTRA_PLUGIN_TESTS)
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -53,13 +53,12 @@ EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_hpjd \
|
|||
|
||||
SUBDIRS = picohttpparser
|
||||
|
||||
np_test_scripts = tests/test_check_swap.t \
|
||||
tests/test_check_snmp.t \
|
||||
tests/test_check_disk.t
|
||||
np_test_scripts = tests/check_swap.t \
|
||||
tests/check_snmp.t \
|
||||
tests/check_disk.t
|
||||
|
||||
EXTRA_DIST = t \
|
||||
tests \
|
||||
$(np_test_scripts) \
|
||||
negate.d \
|
||||
check_swap.d \
|
||||
check_ldap.d \
|
||||
|
|
@ -190,6 +189,8 @@ tests_test_check_swap_LDADD = $(BASEOBJS) $(tap_ldflags) -ltap
|
|||
tests_test_check_swap_SOURCES = tests/test_check_swap.c check_swap.d/swap.c
|
||||
tests_test_check_snmp_LDADD = $(BASEOBJS) $(tap_ldflags) -ltap
|
||||
tests_test_check_snmp_SOURCES = tests/test_check_snmp.c check_snmp.d/check_snmp_helpers.c
|
||||
tests_test_check_snmp_LDFLAGS = $(AM_LDFLAGS) -lm `net-snmp-config --libs`
|
||||
tests_test_check_snmp_CFLAGS = $(AM_CFLAGS) `net-snmp-config --cflags`
|
||||
tests_test_check_disk_LDADD = $(BASEOBJS) $(tap_ldflags) check_disk.d/utils_disk.c -ltap
|
||||
tests_test_check_disk_SOURCES = tests/test_check_disk.c
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@
|
|||
#
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use NPTest;
|
||||
|
||||
my @PLUGINS1 = ('check_ntp_peer', 'check_ntp_time');
|
||||
my @PLUGINS1 = ('check_ntp_peer');
|
||||
my @PLUGINS2 = ('check_ntp_peer');
|
||||
|
||||
plan tests => (12 * scalar(@PLUGINS1)) + (6 * scalar(@PLUGINS2));
|
||||
87
plugins/t/check_ntp_time.t
Normal file
87
plugins/t/check_ntp_time.t
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#! /usr/bin/perl -w -I ..
|
||||
#
|
||||
# Testing NTP
|
||||
#
|
||||
#
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use NPTest;
|
||||
|
||||
my @PLUGINS1 = ('check_ntp_time');
|
||||
|
||||
plan tests => (12 * scalar(@PLUGINS1));
|
||||
|
||||
my $res;
|
||||
|
||||
my $ntp_service = getTestParameter( "NP_GOOD_NTP_SERVICE",
|
||||
"A host providing NTP service",
|
||||
"pool.ntp.org");
|
||||
|
||||
my $no_ntp_service = getTestParameter( "NP_NO_NTP_SERVICE",
|
||||
"A host NOT providing the NTP service",
|
||||
"localhost" );
|
||||
|
||||
my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
|
||||
"The hostname of system not responsive to network requests",
|
||||
"10.0.0.1" );
|
||||
|
||||
my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
|
||||
"An invalid (not known to DNS) hostname",
|
||||
"nosuchhost");
|
||||
|
||||
my $ntp_okmatch1 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
|
||||
my $ntp_warnmatch1 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
|
||||
my $ntp_critmatch1 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
|
||||
my $ntp_okmatch2 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2},\struechimers=[0-9]+/';
|
||||
my $ntp_warnmatch2 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}\s\(WARNING\),\struechimers=[0-9]+/';
|
||||
my $ntp_critmatch2 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+\s\(CRITICAL\),\sstratum=[0-9]{1,2},\struechimers=[0-9]+/';
|
||||
my $ntp_noresponse = '/(.*Socket timeout after \d+ seconds.*)|(.*No response from NTP server.*)/';
|
||||
my $ntp_nosuchhost = '/^check_ntp.*: Invalid hostname/address - ' . $hostname_invalid . '/';
|
||||
|
||||
|
||||
foreach my $plugin (@PLUGINS1) {
|
||||
SKIP: {
|
||||
skip "No NTP server defined", 6 unless $ntp_service;
|
||||
$res = NPTest->testCmd(
|
||||
"./$plugin -H $ntp_service -w 1000 -c 2000"
|
||||
);
|
||||
cmp_ok( $res->return_code, '==', 0, "$plugin: Good NTP result (simple check)" );
|
||||
like( $res->output, $ntp_okmatch1, "$plugin: Output match OK (simple check)" );
|
||||
|
||||
$res = NPTest->testCmd(
|
||||
"./$plugin -H $ntp_service -w 1000: -c 2000"
|
||||
);
|
||||
cmp_ok( $res->return_code, '==', 1, "$plugin: Warning NTP result (simple check)" );
|
||||
like( $res->output, $ntp_warnmatch1, "$plugin: Output match WARNING (simple check)" );
|
||||
|
||||
$res = NPTest->testCmd(
|
||||
"./$plugin -H $ntp_service -w 1000 -c 2000:"
|
||||
);
|
||||
cmp_ok( $res->return_code, '==', 2, "$plugin: Critical NTP result (simple check)" );
|
||||
like( $res->output, $ntp_critmatch1, "$plugin: Output match CRITICAL (simple check)" );
|
||||
}
|
||||
|
||||
SKIP: {
|
||||
skip "No bad NTP server defined", 1 unless $no_ntp_service;
|
||||
$res = NPTest->testCmd(
|
||||
"./$plugin -H $no_ntp_service -t 3"
|
||||
);
|
||||
cmp_ok( $res->return_code, '==', 2, "$plugin: No NTP service" );
|
||||
like( $res->output, $ntp_noresponse, "$plugin: Output match no NTP service" );
|
||||
}
|
||||
|
||||
$res = NPTest->testCmd(
|
||||
"./$plugin -H $host_nonresponsive -t 3"
|
||||
);
|
||||
cmp_ok( $res->return_code, '==', 2, "$plugin: Server not responding" );
|
||||
like( $res->output, $ntp_noresponse, "$plugin: Output match non-responsive" );
|
||||
|
||||
$res = NPTest->testCmd(
|
||||
"./$plugin -H $hostname_invalid"
|
||||
);
|
||||
cmp_ok( $res->return_code, '==', 3, "$plugin: Invalid hostname/address" );
|
||||
like( $res->output, $ntp_nosuchhost, "$plugin: Output match invalid hostname/address" );
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
if (! -e "./test_check_disk") {
|
||||
if (! -e "./tests/test_check_disk") {
|
||||
plan skip_all => "./test_check_disk not compiled - please enable libtap library to test";
|
||||
}
|
||||
exec "./test_check_disk";
|
||||
exec "./tests/test_check_disk";
|
||||
|
|
@ -275,3 +275,8 @@ like($res->output, '/.*4.20.*| iso.3.6.1.4.1.8072.3.2.67.19=4.20/', "Test multip
|
|||
$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -w 1");
|
||||
is($res->return_code, 1, "Test multiply RC + thresholds" );
|
||||
like($res->output, '/.*4.20.* | iso.3.6.1.4.1.8072.3.2.67.19=4.20+;1/', "Test multiply .1 output + thresholds" );
|
||||
|
||||
if (! -e "./tests/test_check_snmp") {
|
||||
plan skip_all => "./test_check_snmp not compiled - please enable libtap library to test";
|
||||
}
|
||||
exec "./tests/test_check_snmp";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
if (! -e "./test_check_swap") {
|
||||
if (! -e "./tests/test_check_swap") {
|
||||
plan skip_all => "./test_check_swap not compiled - please enable libtap library to test";
|
||||
}
|
||||
exec "./test_check_swap";
|
||||
exec "./tests/test_check_swap";
|
||||
BIN
plugins/tests/test_check_snmp
Executable file
BIN
plugins/tests/test_check_snmp
Executable file
Binary file not shown.
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "tap.h"
|
||||
#include "../../tap/tap.h"
|
||||
#include "../../config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
|
@ -26,6 +26,10 @@
|
|||
#include "utils_base.c"
|
||||
#include "../check_snmp.d/check_snmp_helpers.h"
|
||||
|
||||
int verbose = 0;
|
||||
void print_usage() {}
|
||||
const char *progname = "test_check_snmp";
|
||||
|
||||
char *_np_state_generate_key(int argc, char **argv);
|
||||
char *_np_state_calculate_location_prefix(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
use Test::More;
|
||||
if (! -e "./test_check_snmp") {
|
||||
plan skip_all => "./test_check_snmp not compiled - please enable libtap library to test";
|
||||
}
|
||||
exec "./test_check_snmp";
|
||||
Loading…
Reference in a new issue