aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS8
-rw-r--r--THANKS.in6
-rw-r--r--configure.ac7
-rw-r--r--lib/utils_base.c15
-rwxr-xr-xplugins-scripts/check_ifstatus.pl59
-rw-r--r--plugins-scripts/t/check_disk_smb.t2
-rw-r--r--plugins/check_by_ssh.c3
-rw-r--r--plugins/check_dig.c9
-rw-r--r--plugins/check_disk.c16
-rw-r--r--plugins/check_dns.c22
-rw-r--r--plugins/check_hpjd.c30
-rw-r--r--plugins/check_mysql.c22
-rw-r--r--plugins/check_ntp_peer.c58
-rw-r--r--plugins/check_ntp_time.c15
-rw-r--r--plugins/netutils.c15
-rw-r--r--plugins/sslutils.c9
-rw-r--r--plugins/t/NPTest.cache.travis2
-rw-r--r--plugins/t/check_dns.t14
-rw-r--r--plugins/t/check_hpjd.t35
-rw-r--r--plugins/t/check_ntp.t4
-rw-r--r--plugins/t/negate.t5
-rwxr-xr-xplugins/tests/check_http.t8
-rwxr-xr-xplugins/tests/check_snmp.t11
-rwxr-xr-xtest.pl.in2
-rwxr-xr-xtools/generate-change-log2
25 files changed, 289 insertions, 90 deletions
diff --git a/NEWS b/NEWS
index 8109f803..73af0c06 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,12 @@
This file documents the major additions and syntax changes between releases.
-2.0.1 ...
+2.1
+ ENHANCEMENTS
+ New check_hpjd -p option for port specification (abrist)
+ New ./configure --with-qmail-qstat-command option to specify the path to
+ qmail-qstat(8)
+ New check_ifstatus -n option to ignore interfaces by name
+
FIXES
Fix check_jabber to work with Openfire servers
diff --git a/THANKS.in b/THANKS.in
index 7e3295b8..75ecd56c 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -323,5 +323,11 @@ Eric J. Mislivec
Jean-Claude Computing
Andy Brist
Mikael Falkvidd
+Patric Wust
+Julius Kriukas
+Patrick McAndrew
+Alexander Wittig
+Jason Benguerel
+Matthew Kent
Frederic Krueger
Simon Meggle
diff --git a/configure.ac b/configure.ac
index f6ead580..1fa7472b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1478,9 +1478,12 @@ else
fi
AC_PATH_PROG(PATH_TO_QMAIL_QSTAT,qmail-qstat)
-if test -x "$PATH_TO_QMAIL_QSTAT"
+AC_ARG_WITH(qmail_qstat_command,
+ ACX_HELP_STRING([--with-qmail-qstat-command=PATH],
+ [sets path to qmail-qstat]), PATH_TO_QMAIL_QSTAT=$withval)
+if test -n "$PATH_TO_QMAIL_QSTAT"
then
- AC_DEFINE_UNQUOTED(PATH_TO_MAILQ,"$PATH_TO_QMAIL_QSTAT",[path to qmail-qstat])
+ AC_DEFINE_UNQUOTED(PATH_TO_QMAIL_QSTAT,"$PATH_TO_QMAIL_QSTAT",[path to qmail-qstat])
else
AC_MSG_WARN([Could not find qmail-qstat or eqivalent])
fi
diff --git a/lib/utils_base.c b/lib/utils_base.c
index addf26bd..4fb6375d 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -446,6 +446,7 @@ void np_enable_state(char *keyname, int expected_data_version) {
char *temp_filename = NULL;
char *temp_keyname = NULL;
char *p=NULL;
+ int ret;
if(this_monitoring_plugin==NULL)
die(STATE_UNKNOWN, _("This requires np_init to be called"));
@@ -476,9 +477,13 @@ void np_enable_state(char *keyname, int expected_data_version) {
this_state->state_data=NULL;
/* Calculate filename */
- asprintf(&temp_filename, "%s/%lu/%s/%s",
+ ret = xasprintf(&temp_filename, "%s/%lu/%s/%s",
_np_state_calculate_location_prefix(), (unsigned long)geteuid(),
this_monitoring_plugin->plugin_name, this_state->name);
+ if (ret < 0)
+ die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
+ strerror(errno));
+
this_state->_filename=temp_filename;
this_monitoring_plugin->state = this_state;
@@ -614,8 +619,8 @@ void np_state_write_string(time_t data_time, char *data_string) {
/* If file doesn't currently exist, create directories */
if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) {
- asprintf(&directories, "%s", this_monitoring_plugin->state->_filename);
- if(directories==NULL)
+ result = xasprintf(&directories, "%s", this_monitoring_plugin->state->_filename);
+ if(result < 0)
die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
strerror(errno));
@@ -633,8 +638,8 @@ void np_state_write_string(time_t data_time, char *data_string) {
np_free(directories);
}
- asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename);
- if(temp_file==NULL)
+ result = xasprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename);
+ if(result < 0)
die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
strerror(errno));
diff --git a/plugins-scripts/check_ifstatus.pl b/plugins-scripts/check_ifstatus.pl
index fb17d983..9aa25151 100755
--- a/plugins-scripts/check_ifstatus.pl
+++ b/plugins-scripts/check_ifstatus.pl
@@ -9,6 +9,7 @@
# Added -u option (4/2003)
# Added -M option (10/2003)
# Added SNMPv3 support (10/2003)
+# Added -n option (07/2014)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -95,8 +96,10 @@ my $ifXTable;
my $opt_h ;
my $opt_V ;
my $opt_u;
+my $opt_n;
my $opt_x ;
my %excluded ;
+my %unused_names ;
my @unused_ports ;
my %session_opts;
@@ -171,27 +174,30 @@ alarm(0);
foreach $key (keys %ifStatus) {
# skip unused interfaces
- if (!defined($ifStatus{$key}{'notInUse'})) {
+ my $ifName = $ifStatus{$key}{$snmpIfDescr};
+
+ if (!defined($ifStatus{$key}{'notInUse'}) || !grep(/^${ifName}/, @unused_ports )) {
# check only if interface is administratively up
- if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
-
- # check only if interface type is not listed in %excluded
- if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
- if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;}
- if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
- $ifdown++ ;
- if (defined $ifXTable) {
- $ifmessage .= sprintf("%s: down -> %s<BR>",
- $ifStatus{$key}{$snmpIfName},
- $ifStatus{$key}{$snmpIfAlias});
- }else{
- $ifmessage .= sprintf("%s: down <BR>",
- $ifStatus{$key}{$snmpIfDescr});
- }
+ if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
+ #check only if interface is not excluded
+ if (!defined $unused_names{$ifStatus{$key}{$snmpIfDescr}} ) {
+ # check only if interface type is not listed in %excluded
+ if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
+ if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ; }
+ if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
+ $ifdown++ ;
+ if (defined $ifXTable) {
+ $ifmessage .= sprintf("%s: down -> %s<BR>\n", $ifStatus{$key}{$snmpIfName}, $ifStatus{$key}{$snmpIfAlias});
+ }else{
+ $ifmessage .= sprintf("%s: down <BR>\n",$ifStatus{$key}{$snmpIfDescr});
+ }
+ }
+ if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
+ } else {
+ $ifexclude++;
}
- if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
- }else{
- $ifexclude++;
+ } else {
+ $ifunused++;
}
}
@@ -221,7 +227,7 @@ foreach $key (keys %ifStatus) {
$ifexclude,
$ifunused);
}
-my $perfdata = sprintf("up=%d,down=%d,dormant=%d,excluded=%d,unused=%d",$ifup,$ifdown,$ifdormant,$ifexclude,$ifunused);
+my $perfdata = sprintf("up=%d down=%d dormant=%d excluded=%d unused=%d",$ifup,$ifdown,$ifdormant,$ifexclude,$ifunused);
print ("$state: $answer |$perfdata\n");
exit $ERRORS{$state};
@@ -259,6 +265,8 @@ sub print_help() {
printf " the descriptive name. Do not use if you don't know what this is. \n";
printf " -x (--exclude) A comma separated list of ifType values that should be excluded \n";
printf " from the report (default for an empty list is PPP(23).\n";
+ printf " -n (--unused_ports_by_name) A comma separated list of ifDescr values that should be excluded \n";
+ printf " from the report (default is an empty exclusion list).\n";
printf " -u (--unused_ports) A comma separated list of ifIndex values that should be excluded \n";
printf " from the report (default is an empty exclusion list).\n";
printf " See the IANAifType-MIB for a list of interface types.\n";
@@ -299,6 +307,7 @@ sub process_arguments() {
"I" => \$ifXTable, "ifmib" => \$ifXTable,
"x:s" => \$opt_x, "exclude:s" => \$opt_x,
"u=s" => \$opt_u, "unused_ports=s" => \$opt_u,
+ "n=s" => \$opt_n, "unused_ports_by_name=s" => \$opt_n,
"M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize,
"t=i" => \$timeout, "timeout=i" => \$timeout,
);
@@ -406,6 +415,16 @@ sub process_arguments() {
}
}
+ # Excluded interface descriptors
+ if (defined $opt_n) {
+ my @unused = split(/,/,$opt_n);
+ if ( @unused ) {
+ foreach $key (@unused) {
+ $unused_names{$key} = 1;
+ }
+ }
+ }
+
# Excluded interface ports (ifIndex) - management reasons
if ($opt_u) {
@unused_ports = split(/,/,$opt_u);
diff --git a/plugins-scripts/t/check_disk_smb.t b/plugins-scripts/t/check_disk_smb.t
index 831f3887..c2e8bbb2 100644
--- a/plugins-scripts/t/check_disk_smb.t
+++ b/plugins-scripts/t/check_disk_smb.t
@@ -90,7 +90,7 @@ SKIP: {
SKIP: {
skip "no non responsive host defined", 1 if ( ! $host_nonresponsive );
$res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -s np_foobar ");
- cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
+ cmp_ok( $res->return_code, '>=', 2, "Exit CRITICAL/UNKNOWN with non responsive host" );
}
}
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 58f333d3..a877f888 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -169,7 +169,8 @@ process_arguments (int argc, char **argv)
{"verbose", no_argument, 0, 'v'},
{"fork", no_argument, 0, 'f'},
{"timeout", required_argument, 0, 't'},
- {"host", required_argument, 0, 'H'},
+ {"host", required_argument, 0, 'H'}, /* backward compatibility */
+ {"hostname", required_argument, 0, 'H'},
{"port", required_argument,0,'p'},
{"output", required_argument, 0, 'O'},
{"name", required_argument, 0, 'n'},
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index d9481f2d..d899b119 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -94,8 +94,8 @@ main (int argc, char **argv)
timeout_interval_dig = timeout_interval / number_tries + number_tries;
/* get the command to run */
- xasprintf (&command_line, "%s @%s -p %d %s -t %s %s %s +tries=%d +time=%d",
- PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args, query_transport, number_tries, timeout_interval_dig);
+ xasprintf (&command_line, "%s %s %s -p %d @%s %s %s +tries=%d +time=%d",
+ PATH_TO_DIG, dig_args, query_transport, server_port, dns_server, query_address, record_type, number_tries, timeout_interval_dig);
alarm (timeout_interval);
gettimeofday (&tv, NULL);
@@ -296,7 +296,10 @@ process_arguments (int argc, char **argv)
dns_server = argv[c];
}
else {
- dns_server = strdup ("127.0.0.1");
+ if (strcmp(query_transport,"-6") == 0)
+ dns_server = strdup("::1");
+ else
+ dns_server = strdup ("127.0.0.1");
}
}
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 925dfa82..0d73a4f1 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -171,6 +171,7 @@ main (int argc, char **argv)
char *details;
char *perf;
char *preamble;
+ char *flag_header;
double inode_space_pct;
double warning_high_tide;
double critical_high_tide;
@@ -353,18 +354,23 @@ main (int argc, char **argv)
if (disk_result==STATE_OK && erronly && !verbose)
continue;
- xasprintf (&output, "%s %s %.0f %s (%.0f%%",
- output,
+ if(disk_result && verbose >= 1) {
+ xasprintf(&flag_header, " %s [", state_text (disk_result));
+ } else {
+ xasprintf(&flag_header, "");
+ }
+ xasprintf (&output, "%s%s %s %.0f %s (%.0f%%",
+ output, flag_header,
(!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
path->dfree_units,
units,
path->dfree_pct);
if (path->dused_inodes_percent < 0) {
- xasprintf(&output, "%s inode=-);", output);
+ xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
} else {
- xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent );
+ xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
}
-
+ free(flag_header);
/* TODO: Need to do a similar debug line
xasprintf (&details, _("%s\n\
%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 31a953d7..22121226 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -136,6 +136,28 @@ main (int argc, char **argv)
}
}
+ /* bug ID: 2946553 - Older versions of bind will use all available dns
+ servers, we have to match the one specified */
+ if (strstr (chld_out.line[i], "Server:") && strlen(dns_server) > 0) {
+ temp_buffer = strchr (chld_out.line[i], ':');
+ temp_buffer++;
+
+ /* Strip leading tabs */
+ for (; *temp_buffer != '\0' && *temp_buffer == '\t'; temp_buffer++)
+ /* NOOP */;
+
+ strip(temp_buffer);
+ if (temp_buffer==NULL || strlen(temp_buffer)==0) {
+ die (STATE_CRITICAL,
+ _("DNS CRITICAL - '%s' returned empty server string\n"),
+ NSLOOKUP_COMMAND);
+ }
+
+ if (strcmp(temp_buffer, dns_server) != 0) {
+ die (STATE_CRITICAL, _("DNS CRITICAL - No response from DNS %s\n"), dns_server);
+ }
+ }
+
/* the server is responding, we just got the host name... */
if (strstr (chld_out.line[i], "Name:"))
parse_address = TRUE;
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 1e7605ba..5fe06984 100644
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
@@ -39,7 +39,7 @@ const char *email = "devel@monitoring-plugins.org";
#include "netutils.h"
#define DEFAULT_COMMUNITY "public"
-
+#define DEFAULT_PORT "161"
const char *option_summary = "-H host [-C community]\n";
@@ -66,6 +66,7 @@ void print_usage (void);
char *community = NULL;
char *address = NULL;
+char *port = NULL;
int
main (int argc, char **argv)
@@ -119,8 +120,8 @@ main (int argc, char **argv)
HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY);
/* get the command to run */
- sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s %s", PATH_TO_SNMPGET, community,
- address, query_string);
+ sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%hd %s", PATH_TO_SNMPGET, community,
+ address, port, query_string);
/* run the command */
child_process = spopen (command_line);
@@ -313,7 +314,7 @@ process_arguments (int argc, char **argv)
{"community", required_argument, 0, 'C'},
/* {"critical", required_argument,0,'c'}, */
/* {"warning", required_argument,0,'w'}, */
-/* {"port", required_argument,0,'P'}, */
+ {"port", required_argument,0,'p'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
@@ -324,7 +325,7 @@ process_arguments (int argc, char **argv)
while (1) {
- c = getopt_long (argc, argv, "+hVH:C:", longopts, &option);
+ c = getopt_long (argc, argv, "+hVH:C:p:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
@@ -341,6 +342,12 @@ process_arguments (int argc, char **argv)
case 'C': /* community */
community = strscpy (community, optarg);
break;
+ case 'p':
+ if (!is_intpos(optarg))
+ usage2 (_("Port must be a positive short integer"), optarg);
+ else
+ port = atoi(optarg);
+ break;
case 'V': /* version */
print_revision (progname, NP_VERSION);
exit (STATE_OK);
@@ -369,6 +376,13 @@ process_arguments (int argc, char **argv)
community = strdup (DEFAULT_COMMUNITY);
}
+ if (port == NULL) {
+ if (argv[c] != NULL )
+ port = argv[c];
+ else
+ port = atoi (DEFAULT_PORT);
+ }
+
return validate_arguments ();
}
@@ -402,6 +416,10 @@ print_help (void)
printf (" %s", _("The SNMP community name "));
printf (_("(default=%s)"), DEFAULT_COMMUNITY);
printf ("\n");
+ printf (" %s\n", "-p, --port=STRING");
+ printf (" %s", _("Specify the port to check "));
+ printf (_("(default=%s)"), DEFAULT_PORT);
+ printf ("\n");
printf (UT_SUPPORT);
}
@@ -412,5 +430,5 @@ void
print_usage (void)
{
printf ("%s\n", _("Usage:"));
- printf ("%s -H host [-C community]\n", progname);
+ printf ("%s -H host [-C community] [-p port]\n", progname);
}
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 4f09e5f8..216626bc 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -42,6 +42,7 @@ const char *email = "devel@monitoring-plugins.org";
#include "netutils.h"
#include <mysql.h>
+#include <mysqld_error.h>
#include <errmsg.h>
char *db_user = NULL;
@@ -59,6 +60,7 @@ char *opt_file = NULL;
char *opt_group = NULL;
unsigned int db_port = MYSQL_PORT;
int check_slave = 0, warn_sec = 0, crit_sec = 0;
+int ignore_auth = 0;
int verbose = 0;
static double warning_time = 0;
@@ -136,7 +138,16 @@ main (int argc, char **argv)
mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers);
/* establish a connection to the server and error checking */
if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) {
- if (mysql_errno (&mysql) == CR_UNKNOWN_HOST)
+ if (ignore_auth && mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR)
+ {
+ printf("MySQL OK - Version: %s (protocol %d)\n",
+ mysql_get_server_info(&mysql),
+ mysql_get_proto_info(&mysql)
+ );
+ mysql_close (&mysql);
+ return STATE_OK;
+ }
+ else if (mysql_errno (&mysql) == CR_UNKNOWN_HOST)
die (STATE_WARNING, "%s\n", mysql_error (&mysql));
else if (mysql_errno (&mysql) == CR_VERSION_ERROR)
die (STATE_WARNING, "%s\n", mysql_error (&mysql));
@@ -341,6 +352,7 @@ process_arguments (int argc, char **argv)
{"critical", required_argument, 0, 'c'},
{"warning", required_argument, 0, 'w'},
{"check-slave", no_argument, 0, 'S'},
+ {"ignore-auth", no_argument, 0, 'n'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
@@ -357,7 +369,7 @@ process_arguments (int argc, char **argv)
return ERROR;
while (1) {
- c = getopt_long (argc, argv, "hlvVSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option);
+ c = getopt_long (argc, argv, "hlvVnSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option);
if (c == -1 || c == EOF)
break;
@@ -419,6 +431,9 @@ process_arguments (int argc, char **argv)
case 'S':
check_slave = 1; /* check-slave */
break;
+ case 'n':
+ ignore_auth = 1; /* ignore-auth */
+ break;
case 'w':
warning = optarg;
warning_time = strtod (warning, NULL);
@@ -506,6 +521,9 @@ print_help (void)
printf (UT_EXTRA_OPTS);
printf (UT_HOST_PORT, 'P', myport);
+ printf (" %s\n", "-n, --ignore-auth");
+ printf (" %s\n", _("Ignore authentication failure and check for mysql connectivity only"));
+
printf (" %s\n", "-s, --socket=STRING");
printf (" %s\n", _("Use the specified socket (has no effect if -H is used)"));
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c
index 8dc19788..44424af5 100644
--- a/plugins/check_ntp_peer.c
+++ b/plugins/check_ntp_peer.c
@@ -560,7 +560,7 @@ char *perfd_truechimers (int num_truechimers)
}
int main(int argc, char *argv[]){
- int result, offset_result, stratum, num_truechimers;
+ int result, offset_result, stratum, num_truechimers, oresult, jresult, sresult, tresult;
double offset=0, jitter=0;
char *result_line, *perfdata_line;
@@ -597,15 +597,22 @@ int main(int argc, char *argv[]){
result = STATE_UNKNOWN;
result = max_state_alt(result, get_status(fabs(offset), offset_thresholds));
}
+ oresult = result;
+
+ if(do_truechimers) {
+ tresult = get_status(num_truechimers, truechimer_thresholds);
+ result = max_state_alt(result, tresult);
+ }
- if(do_truechimers)
- result = max_state_alt(result, get_status(num_truechimers, truechimer_thresholds));
-
- if(do_stratum)
- result = max_state_alt(result, get_status(stratum, stratum_thresholds));
+ if(do_stratum) {
+ sresult = get_status(stratum, stratum_thresholds);
+ result = max_state_alt(result, sresult);
+ }
- if(do_jitter)
- result = max_state_alt(result, get_status(jitter, jitter_thresholds));
+ if(do_jitter) {
+ jresult = get_status(jitter, jitter_thresholds);
+ result = max_state_alt(result, jresult);
+ }
switch (result) {
case STATE_CRITICAL :
@@ -629,20 +636,43 @@ int main(int argc, char *argv[]){
if(offset_result == STATE_UNKNOWN){
xasprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
xasprintf(&perfdata_line, "");
+ } else if (oresult == STATE_WARNING) {
+ xasprintf(&result_line, "%s %s %.10g secs (WARNING)", result_line, _("Offset"), offset);
+ } else if (oresult == STATE_CRITICAL) {
+ xasprintf(&result_line, "%s %s %.10g secs (CRITICAL)", result_line, _("Offset"), offset);
} else {
xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
- xasprintf(&perfdata_line, "%s", perfd_offset(offset));
- }
+ }
+ xasprintf(&perfdata_line, "%s", perfd_offset(offset));
+
if (do_jitter) {
- xasprintf(&result_line, "%s, jitter=%f", result_line, jitter);
+ if (jresult == STATE_WARNING) {
+ xasprintf(&result_line, "%s, jitter=%f (WARNING)", result_line, jitter);
+ } else if (jresult == STATE_CRITICAL) {
+ xasprintf(&result_line, "%s, jitter=%f (CRITICAL)", result_line, jitter);
+ } else {
+ xasprintf(&result_line, "%s, jitter=%f", result_line, jitter);
+ }
xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter));
}
if (do_stratum) {
- xasprintf(&result_line, "%s, stratum=%i", result_line, stratum);
+ if (sresult == STATE_WARNING) {
+ xasprintf(&result_line, "%s, stratum=%i (WARNING)", result_line, stratum);
+ } else if (sresult == STATE_CRITICAL) {
+ xasprintf(&result_line, "%s, stratum=%i (CRITICAL)", result_line, stratum);
+ } else {
+ xasprintf(&result_line, "%s, stratum=%i", result_line, stratum);
+ }
xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
}
if (do_truechimers) {
- xasprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers);
+ if (tresult == STATE_WARNING) {
+ xasprintf(&result_line, "%s, truechimers=%i (WARNING)", result_line, num_truechimers);
+ } else if (tresult == STATE_CRITICAL) {
+ xasprintf(&result_line, "%s, truechimers=%i (CRITICAL)", result_line, num_truechimers);
+ } else {
+ xasprintf(&result_line, "%s, truechimers=%i", result_line, num_truechimers);
+ }
xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_truechimers(num_truechimers));
}
printf("%s|%s\n", result_line, perfdata_line);
@@ -651,8 +681,6 @@ int main(int argc, char *argv[]){
return result;
}
-
-
void print_help(void){
print_revision(progname, NP_VERSION);
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c
index 72dffbd8..e344f8b7 100644
--- a/plugins/check_ntp_time.c
+++ b/plugins/check_ntp_time.c
@@ -48,6 +48,7 @@ static int verbose=0;
static int quiet=0;
static char *owarn="60";
static char *ocrit="120";
+static int time_offset=0;
int process_arguments (int, char **);
thresholds *offset_thresholds = NULL;
@@ -400,7 +401,7 @@ double offset_request(const char *host, int *status){
gettimeofday(&recv_time, NULL);
DBG(print_ntp_message(&req[i]));
respnum=servers[i].num_responses++;
- servers[i].offset[respnum]=calc_offset(&req[i], &recv_time);
+ servers[i].offset[respnum]=calc_offset(&req[i], &recv_time)+time_offset;
if(verbose) {
printf("offset %.10g\n", servers[i].offset[respnum]);
}
@@ -455,6 +456,7 @@ int process_arguments(int argc, char **argv){
{"use-ipv4", no_argument, 0, '4'},
{"use-ipv6", no_argument, 0, '6'},
{"quiet", no_argument, 0, 'q'},
+ {"time-offset", optional_argument, 0, 'o'},
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"timeout", required_argument, 0, 't'},
@@ -468,7 +470,7 @@ int process_arguments(int argc, char **argv){
usage ("\n");
while (1) {
- c = getopt_long (argc, argv, "Vhv46qw:c:t:H:p:", longopts, &option);
+ c = getopt_long (argc, argv, "Vhv46qw:c:t:H:p:o:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
@@ -504,6 +506,9 @@ int process_arguments(int argc, char **argv){
case 't':
socket_timeout=atoi(optarg);
break;
+ case 'o':
+ time_offset=atoi(optarg);
+ break;
case '4':
address_family = AF_INET;
break;
@@ -616,6 +621,8 @@ void print_help(void){
printf (" %s\n", _("Offset to result in warning status (seconds)"));
printf (" %s\n", "-c, --critical=THRESHOLD");
printf (" %s\n", _("Offset to result in critical status (seconds)"));
+ printf (" %s\n", "-o, --time_offset=INTEGER");
+ printf (" %s\n", _("Expected offset of the ntp server relative to local server (seconds)"));
printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
printf (UT_VERBOSE);
@@ -628,6 +635,8 @@ void print_help(void){
printf("%s\n", _("Notes:"));
printf(" %s\n", _("If you'd rather want to monitor an NTP server, please use"));
printf(" %s\n", _("check_ntp_peer."));
+ printf(" %s\n", _("--time-offset is usefull for compensating for servers with known"));
+ printf(" %s\n", _("and expected clock skew."));
printf("\n");
printf(UT_THRESHOLDS_NOTES);
@@ -642,6 +651,6 @@ void
print_usage(void)
{
printf ("%s\n", _("Usage:"));
- printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose]\n", progname);
+ printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose] [-o <time offset>]\n", progname);
}
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 00440465..83f8942f 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -167,11 +167,12 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
char port_str[6], host[MAX_HOST_ADDRESS_LENGTH];
size_t len;
int socktype, result;
+ short is_socket = (host_name[0] == '/');
socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
/* as long as it doesn't start with a '/', it's assumed a host or ip */
- if(host_name[0] != '/'){
+ if (!is_socket){
memset (&hints, 0, sizeof (hints));
hints.ai_family = address_family;
hints.ai_protocol = proto;
@@ -253,7 +254,11 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
return econn_refuse_state;
break;
case STATE_CRITICAL: /* user did not set econn_refuse_state */
- printf ("%s\n", strerror(errno));
+ if (is_socket)
+ printf("connect to file socket %s: %s\n", host_name, strerror(errno));
+ else
+ printf("connect to address %s and port %d: %s\n",
+ host_name, port, strerror(errno));
return econn_refuse_state;
break;
default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */
@@ -262,7 +267,11 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
}
}
else {
- printf ("%s\n", strerror(errno));
+ if (is_socket)
+ printf("connect to file socket %s: %s\n", host_name, strerror(errno));
+ else
+ printf("connect to address %s and port %d: %s\n",
+ host_name, port, strerror(errno));
return STATE_CRITICAL;
}
}
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index 687bffb7..d0ae4741 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -153,7 +153,8 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
struct tm stamp;
float time_left;
int days_left;
- char timestamp[17] = "";
+ char timestamp[50] = "";
+ time_t tm_t;
certificate=SSL_get_peer_certificate(s);
if (!certificate) {
@@ -211,10 +212,8 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
time_left = difftime(timegm(&stamp), time(NULL));
days_left = time_left / 86400;
- snprintf
- (timestamp, 17, "%02d/%02d/%04d %02d:%02d",
- stamp.tm_mon + 1,
- stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
+ tm_t = mktime (&stamp);
+ strftime(timestamp, 50, "%c", localtime(&tm_t));
if (days_left > 0 && days_left <= days_till_exp_warn) {
printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp);
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis
index c1007deb..4ebfb90e 100644
--- a/plugins/t/NPTest.cache.travis
+++ b/plugins/t/NPTest.cache.travis
@@ -14,6 +14,8 @@
'NP_HOST_SNMP' => '',
'NP_HOST_TCP_FTP' => '',
'NP_HOST_TCP_HPJD' => '',
+ 'NP_HOST_HPJD_PORT_INVALID' => '161',
+ 'NP_HOST_HPJD_PORT_VALID' => '',
'NP_HOST_TCP_HTTP' => 'localhost',
'NP_HOST_TCP_HTTP2' => 'labs.consol.de',
'NP_HOST_TCP_IMAP' => 'imap.web.de',
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index 4ff553f7..035e7682 100644
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
@@ -10,7 +10,7 @@ use NPTest;
plan skip_all => "check_dns not compiled" unless (-x "check_dns");
-plan tests => 14;
+plan tests => 16;
my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
@@ -43,6 +43,12 @@ my $dns_server = getTestParameter(
"A non default (remote) DNS server",
);
+my $host_nonresponsive = getTestParameter(
+ "NP_HOST_NONRESPONSIVE",
+ "The hostname of system not responsive to network requests",
+ "10.0.0.1",
+ );
+
my $res;
$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
@@ -54,7 +60,7 @@ cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
-like( $res->output, "/\|time=[\d\.]+s;0.0*;5\.0*;0\.0*/", "Output performance data OK" );
+like( $res->output, '/\|time=[\d\.]+s;0.0*;5\.0*;0\.0*/', "Output performance data OK" );
$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
@@ -66,6 +72,10 @@ like ( $res->output, $successOutput, "Output OK" );
$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
+$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -s $host_nonresponsive -t 2");
+cmp_ok( $res->return_code, '==', 2, "Got no answer from unresponsive server");
+like ( $res->output, "/CRITICAL - /", "Output OK");
+
$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
cmp_ok( $res->return_code, '==', 0, "Got expected address");
diff --git a/plugins/t/check_hpjd.t b/plugins/t/check_hpjd.t
index 10ded54a..4d64852a 100644
--- a/plugins/t/check_hpjd.t
+++ b/plugins/t/check_hpjd.t
@@ -10,7 +10,6 @@ use NPTest;
plan skip_all => "check_hpjd not compiled" unless (-x "check_hpjd");
-plan tests => 5;
my $successOutput = '/^Printer ok - /';
my $failureOutput = '/Timeout: No [Rr]esponse from /';
@@ -20,31 +19,53 @@ my $host_tcp_hpjd = getTestParameter(
"A host (usually a printer) providing the HP-JetDirect Services"
);
+my $host_hpjd_port_invalid = getTestParameter(
+ "NP_HOST_HPJD_PORT_INVALID",
+ "A port that HP-JetDirect Services is not listening on",
+ "162"
+ );
+
+my $host_hpjd_port_valid = getTestParameter(
+ "NP_HOST_HPJD_PORT_VALID",
+ "The port that HP-JetDirect Services is currently listening on",
+ "161"
+ );
+
my $host_nonresponsive = getTestParameter(
"NP_HOST_NONRESPONSIVE",
"The hostname of system not responsive to network requests",
- "10.0.0.1",
+ "10.0.0.1"
);
my $hostname_invalid = getTestParameter(
"NP_HOSTNAME_INVALID",
"An invalid (not known to DNS) hostname",
- "nosuchhost",
+ "nosuchhost"
);
+my $tests = $host_tcp_hpjd ? 9 : 5;
+plan tests => $tests;
my $res;
SKIP: {
skip "No HP JetDirect defined", 2 unless $host_tcp_hpjd;
- $res = NPTest->testCmd("./check_hpjd $host_tcp_hpjd");
- cmp_ok( $res->return_code, '==', 0, "Jetdirect responding" );
+ $res = NPTest->testCmd("./check_hpjd -H $host_tcp_hpjd");
+ cmp_ok( $res->return_code, 'eq', 0, "Jetdirect responding" );
like ( $res->output, $successOutput, "Output correct" );
+
+ $res = NPTest->testCmd("./check_hpjd -H $host_tcp_hpjd -p $host_hpjd_port_valid");
+ cmp_ok( $res->return_code, 'eq', 0, "Jetdirect responding on port $host_hpjd_port_valid" );
+ like ( $res->output, $successOutput, "Output correct" );
+
+ $res = NPTest->testCmd("./check_hpjd -H $host_tcp_hpjd -p $host_hpjd_port_invalid");
+ cmp_ok( $res->return_code, 'eq', 2, "Jetdirect not responding on port $host_hpjd_port_invalid" );
+ like ( $res->output, $failureOutput, "Output correct" );
}
-$res = NPTest->testCmd("./check_hpjd $host_nonresponsive");
+$res = NPTest->testCmd("./check_hpjd -H $host_nonresponsive");
cmp_ok( $res->return_code, 'eq', 2, "Host not responding");
like ( $res->output, $failureOutput, "Output OK" );
-$res = NPTest->testCmd("./check_hpjd $hostname_invalid");
+$res = NPTest->testCmd("./check_hpjd -H $hostname_invalid");
cmp_ok( $res->return_code, 'eq', 3, "Hostname invalid");
diff --git a/plugins/t/check_ntp.t b/plugins/t/check_ntp.t
index 74d890fa..b8fc8fdf 100644
--- a/plugins/t/check_ntp.t
+++ b/plugins/t/check_ntp.t
@@ -35,8 +35,8 @@ 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},\struechimers=[0-9]+/';
-my $ntp_critmatch2 = '/^NTP\sCRITICAL:\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 = '/^(CRITICAL - Socket timeout after 3 seconds)|(NTP CRITICAL: No response from NTP server)$/';
my $ntp_nosuchhost = '/^check_ntp.*: Invalid hostname/address - ' . $hostname_invalid . '/';
diff --git a/plugins/t/negate.t b/plugins/t/negate.t
index f18acc39..d96a109b 100644
--- a/plugins/t/negate.t
+++ b/plugins/t/negate.t
@@ -6,6 +6,7 @@
use strict;
use Test::More;
+use Cwd;
use NPTest;
# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops
@@ -13,7 +14,7 @@ plan tests => 88;
my $res;
-my $PWD = $ENV{PWD};
+my $PWD = getcwd();
$res = NPTest->testCmd( "./negate" );
is( $res->return_code, 3, "Not enough parameters");
@@ -50,7 +51,7 @@ is( $res->output, "OK: a dummy okay", "The quoted string is passed through to su
$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" );
is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')");
-$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' );
+$res = NPTest->testCmd( './negate '.$PWD.'/check_dummy 0 \'$$ a dummy okay\'' );
is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' );
my %state = (
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 225b449f..d93a0ecf 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -186,21 +186,21 @@ SKIP: {
$result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
- is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on 03/03/2019 21:41.', "output ok" );
+ is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:00 2019.', "output ok" );
$result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
- like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
+ like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" );
# Expired cert tests
$result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" );
- like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
+ like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:00 2019\)./', "output ok" );
$result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
is( $result->output,
- 'CRITICAL - Certificate \'Ton Voon\' expired on 03/05/2009 00:13.',
+ 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:00 2009.',
"output ok" );
}
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index aace9bcc..2fd033d2 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -20,7 +20,16 @@ if ($@) {
plan skip_all => "Missing required module for test: $@";
} else {
if (-x "./check_snmp") {
- plan tests => $tests;
+ # check if snmpd has perl support
+ my $test = `snmpd -c tests/conf/snmpd.conf -C -r -H 2>&1`;
+ if(!defined $test) {
+ plan skip_all => "snmpd required";
+ }
+ elsif($test =~ m/Warning: Unknown token: perl/) {
+ plan skip_all => "snmpd has no perl support";
+ } else {
+ plan tests => $tests;
+ }
} else {
plan skip_all => "No check_snmp compiled";
}
diff --git a/test.pl.in b/test.pl.in
index 01a97ec0..2f2c44f2 100755
--- a/test.pl.in
+++ b/test.pl.in
@@ -9,6 +9,8 @@ use Getopt::Long;
use NPTest qw(DetermineTestHarnessDirectory TestsFrom);
+$ENV{LC_ALL} = 'C';
+
my @tstdir;
if ( ! GetOptions( "testdir:s" => \@tstdir ) )
diff --git a/tools/generate-change-log b/tools/generate-change-log
index 3a6b38e7..ad19ce96 100755
--- a/tools/generate-change-log
+++ b/tools/generate-change-log
@@ -19,6 +19,7 @@ use Text::Wrap;
# The lines will have a length of no more than $columns - 1.
$Text::Wrap::columns = 81;
+$Text::Wrap::huge = 'overflow';
if (system('git rev-parse --git-dir >/dev/null 2>&1') != 0) {
print "Not a Git repository, so I won't update the ChangeLog.\n";
@@ -51,6 +52,7 @@ while ($git_log =~ /$regex/gm) {
$prev_date = $commit{date};
$prev_name = $commit{name};
$prev_email = $commit{email};
+ $commit{message} =~ s/\s*Signed\-off\-by.*$//sgmx;
my @files = split(/\n/, $commit{files});
my @message = map { s/^ {4}//; $_ } split(/\n/, $commit{message});