Parcourir la source

Merge branch 'maint' of github.com-sreinhardt:nagios-plugins/nagios-plugins into maint

Spenser Reinhardt il y a 12 ans
Parent
commit
8ac131217e
7 fichiers modifiés avec 94 ajouts et 22 suppressions
  1. 2 0
      NEWS
  2. 2 0
      THANKS.in
  3. 1 1
      configure.in
  4. 20 2
      plugins/check_mysql.c
  5. 37 12
      plugins/check_ntp_peer.c
  6. 12 3
      plugins/check_ntp_time.c
  7. 20 4
      plugins/check_ssh.c

+ 2 - 0
NEWS

@@ -10,6 +10,7 @@ This file documents the major additions and syntax changes between releases.
 	New check_mysql_query -f/-g options for reading for mysql options file (awiddersheim)
 	check_mailq now supports nullmailer in the mailserver -M switch (Luca Corti)
 	New check_dig -r option for specifying number of retries (abrist)
+	check_ntp_peer - Added state output for each checked metric (abrist)
 
 	FIXES
 	Don't let e.g. check_http's -C option reset SSL version if e.g. -S 1 -C 5 is specified
@@ -25,6 +26,7 @@ This file documents the major additions and syntax changes between releases.
 	Fixed newlines in parse.ini output (dermoth)
 	check_dig: fix wrong IPv6 arguments order (Stéphane Bortzmeyer)
 	check_dig: now honors timeout value specified by switch -t (Jethro Carr) (abrist)
+	Configure option --enable-extra-opts is now enabled by default (dermoth)
 
 	WARNINGS
 	check_procs now ignores its parent process to avoid unexpected results when invoked via certain shells

+ 2 - 0
THANKS.in

@@ -310,3 +310,5 @@ Stéphane Bortzmeyer
 Luca Corti
 Jethro Carr
 Neil Prockter
+Patrick McAndrew
+Julius Kriukas

+ 1 - 1
configure.in

@@ -194,7 +194,7 @@ AC_ARG_ENABLE(extra-opts,
   AC_HELP_STRING([--enable-extra-opts],
 		[Enables parsing of plugins ini config files for extra options (default: no)]),
 	[enable_extra_opts=$enableval],
-	[enable_extra_opts=no])
+	[enable_extra_opts=yes])
 AM_CONDITIONAL([USE_PARSE_INI],[test "$enable_extra_opts" = "yes"])
 if test "$enable_extra_opts" = "yes" ; then
 	AC_DEFINE(NP_EXTRA_OPTS,[1],[Enable INI file parsing.])

+ 20 - 2
plugins/check_mysql.c

@@ -42,6 +42,7 @@ const char *email = "devel@nagios-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);
@@ -512,6 +527,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)"));
 

+ 37 - 12
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,19 @@ 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)
-		result = max_state_alt(result, get_status(num_truechimers, truechimer_thresholds));
+		tresult = get_status(num_truechimers, truechimer_thresholds);
+		result = max_state_alt(result, tresult);
 
 	if(do_stratum)
-		result = max_state_alt(result, get_status(stratum, stratum_thresholds));
+		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));
+		jresult = get_status(jitter, jitter_thresholds);
+		result = max_state_alt(result, jresult);
 
 	switch (result) {
 		case STATE_CRITICAL :
@@ -629,20 +633,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 +678,6 @@ int main(int argc, char *argv[]){
 	return result;
 }
 
-
-
 void print_help(void){
 	print_revision(progname, NP_VERSION);
 

+ 12 - 3
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;
@@ -399,7 +400,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]);
 				}
@@ -454,6 +455,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'},
@@ -467,7 +469,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;
 
@@ -503,6 +505,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;
@@ -615,6 +620,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);
 
@@ -627,6 +634,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);
 
@@ -641,6 +650,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);
 }
 

+ 20 - 4
plugins/check_ssh.c

@@ -46,6 +46,7 @@ const char *email = "devel@nagios-plugins.org";
 int port = -1;
 char *server_name = NULL;
 char *remote_version = NULL;
+char *remote_protocol = NULL;
 int verbose = FALSE;
 
 int process_arguments (int, char **);
@@ -53,7 +54,7 @@ int validate_arguments (void);
 void print_help (void);
 void print_usage (void);
 
-int ssh_connect (char *haddr, int hport, char *remote_version);
+int ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol);
 
 
 
@@ -78,7 +79,7 @@ main (int argc, char **argv)
 	alarm (socket_timeout);
 
 	/* ssh_connect exits if error is found */
-	result = ssh_connect (server_name, port, remote_version);
+	result = ssh_connect (server_name, port, remote_version, remote_protocol);
 
 	alarm (0);
 
@@ -105,6 +106,7 @@ process_arguments (int argc, char **argv)
 		{"timeout", required_argument, 0, 't'},
 		{"verbose", no_argument, 0, 'v'},
 		{"remote-version", required_argument, 0, 'r'},
+		{"remote-protcol", required_argument, 0, 'P'},
 		{0, 0, 0, 0}
 	};
 
@@ -116,7 +118,7 @@ process_arguments (int argc, char **argv)
 			strcpy (argv[c], "-t");
 
 	while (1) {
-		c = getopt_long (argc, argv, "+Vhv46t:r:H:p:", longopts, &option);
+		c = getopt_long (argc, argv, "+Vhv46t:r:H:p:P:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -152,6 +154,9 @@ process_arguments (int argc, char **argv)
 		case 'r':									/* remote version */
 			remote_version = optarg;
 			break;
+		case 'P':									/* remote version */
+			remote_protocol = optarg;
+			break;
 		case 'H':									/* host */
 			if (is_host (optarg) == FALSE)
 				usage2 (_("Invalid hostname/address"), optarg);
@@ -206,7 +211,7 @@ validate_arguments (void)
 
 
 int
-ssh_connect (char *haddr, int hport, char *remote_version)
+ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol)
 {
 	int sd;
 	int result;
@@ -255,6 +260,14 @@ ssh_connect (char *haddr, int hport, char *remote_version)
 			exit (STATE_WARNING);
 		}
 
+		if (remote_protocol && strcmp(remote_protocol, ssh_proto)) {
+			printf
+				(_("SSH WARNING - %s (protocol %s) protocol version mismatch, expected '%s'\n"),
+				 ssh_server, ssh_proto, remote_protocol);
+			close(sd);
+			exit (STATE_WARNING);
+		}
+
 		elapsed_time = (double)deltime(tv) / 1.0e6;
 
 		printf
@@ -298,6 +311,9 @@ print_help (void)
 	printf (" %s\n", "-r, --remote-version=STRING");
   printf ("    %s\n", _("Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)"));
 
+	printf (" %s\n", "-P, --remote-protocol=STRING");
+  printf ("    %s\n", _("Warn if protocol doesn't match expected protocol version (ex: 2.0)"));
+
 	printf (UT_VERBOSE);
 
 	printf (UT_SUPPORT);