summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 998bb7d)
raw | patch | inline | side by side (parent: 998bb7d)
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | |
Thu, 11 Oct 2007 04:21:27 +0000 (04:21 +0000) | ||
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | |
Thu, 11 Oct 2007 04:21:27 +0000 (04:21 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1806 f882894a-f735-0410-b71e-b25c423dba1c
NEWS | patch | blob | history | |
plugins/check_ntp.c | patch | blob | history |
index 2cc9fbafbc314a04b871842e501c1569c5bb111c..361443b431de8defbbbcd77892dece6ec814043e 100644 (file)
--- a/NEWS
+++ b/NEWS
1.4.11 or 1.5 ??
Fix check_http regression in 1.4.10 where following redirects to
relative URLs on virtual hosts failed if both "-H" and "-I" were used
+ Add stratum thresholds support to check_ntp (feature request #1703823)
1.4.10 28th September 2007
Fix check_http buffer overflow vulnerability when following HTTP redirects
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index 6c7c1e7d630957bf16cf7d1dd591c50efdd97b2c..12334f777adbaa9adc07583100bd67b9d9f2f22d 100644 (file)
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
*
* License: GPL
* Copyright (c) 2006 sean finney <seanius@seanius.net>
-* Copyright (c) 2006 nagios-plugins team
+* Copyright (c) 2007 nagios-plugins team
*
* Last Modified: $Date$
*
const char *progname = "check_ntp";
const char *revision = "$Revision$";
-const char *copyright = "2006";
+const char *copyright = "2007";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
static char *server_address=NULL;
static int verbose=0;
-static int stratum=-1;
static char *owarn="60";
static char *ocrit="120";
+static short do_stratum=0;
+static char *swarn="16";
+static char *scrit="16";
static short do_jitter=0;
static char *jwarn="5000";
static char *jcrit="10000";
int process_arguments (int, char **);
thresholds *offset_thresholds = NULL;
thresholds *jitter_thresholds = NULL;
+thresholds *stratum_thresholds = NULL;
void print_help (void);
void print_usage (void);
* we don't waste time sitting around waiting for single packets.
* - we also "manually" handle resolving host names and connecting, because
* we have to do it in a way that our lazy macros don't handle currently :( */
-double offset_request(const char *host, int *status){
+double offset_request(const char *host, int *stratum, int *status){
int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0;
int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1;
time_t now_time=0, start_ts=0;
respnum=servers[i].num_responses++;
servers[i].offset[respnum]=calc_offset(&req[i], &recv_time);
if(verbose) {
- printf("offset %.10g\n", servers[i].offset[respnum]);
+ printf("offset %.10g, stratum %i\n", servers[i].offset[respnum], req[i].stratum);
}
servers[i].stratum=req[i].stratum;
servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp);
avg_offset+=servers[best_index].offset[j];
}
avg_offset/=servers[best_index].num_responses;
+ *stratum = servers[best_index].stratum;
}
/* cleanup */
{"use-ipv6", no_argument, 0, '6'},
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
+ {"swarn", required_argument, 0, 'W'},
+ {"scrit", required_argument, 0, 'C'},
{"jwarn", required_argument, 0, 'j'},
{"jcrit", required_argument, 0, 'k'},
{"timeout", required_argument, 0, 't'},
usage ("\n");
while (1) {
- c = getopt_long (argc, argv, "Vhv46w:c:j:k:t:H:", longopts, &option);
+ c = getopt_long (argc, argv, "Vhv46w:c:W:C:j:k:t:H:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
case 'c':
ocrit = optarg;
break;
+ case 'W':
+ do_stratum=1;
+ swarn = optarg;
+ break;
+ case 'C':
+ do_stratum=1;
+ scrit = optarg;
+ break;
case 'j':
do_jitter=1;
jwarn = optarg;
TRUE, 0, FALSE, 0);
}
+char *perfd_stratum (int stratum)
+{
+ return perfdata ("stratum", stratum, "",
+ do_stratum, (int)stratum_thresholds->warning->end,
+ do_stratum, (int)stratum_thresholds->critical->end,
+ TRUE, 0, TRUE, 16);
+}
+
int main(int argc, char *argv[]){
- int result, offset_result, jitter_result;
+ int result, offset_result, jitter_result, stratum;
double offset=0, jitter=0;
char *result_line, *perfdata_line;
set_thresholds(&offset_thresholds, owarn, ocrit);
set_thresholds(&jitter_thresholds, jwarn, jcrit);
+ set_thresholds(&stratum_thresholds, swarn, scrit);
/* initialize alarm signal handling */
signal (SIGALRM, socket_timeout_alarm_handler);
/* set socket timeout */
alarm (socket_timeout);
- offset = offset_request(server_address, &offset_result);
+ offset = offset_request(server_address, &stratum, &offset_result);
result = get_status(fabs(offset), offset_thresholds);
result = max_state(result, offset_result);
+ if(do_stratum)
+ result = max_state(result, get_status(stratum, stratum_thresholds));
/* If not told to check the jitter, we don't even send packets.
* jitter is checked using NTP control packets, which not all
asprintf(&result_line, "%s, jitter=%f", result_line, jitter);
asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter));
}
+ if (do_stratum) {
+ asprintf(&result_line, "%s, stratum=%i", result_line, stratum);
+ asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(stratum));
+ }
printf("%s|%s\n", result_line, perfdata_line);
if(server_address!=NULL) free(server_address);
print_usage();
printf (_(UT_HELP_VRSN));
printf (_(UT_HOST_PORT), 'p', "123");
- printf (" %s\n", "-w, --warning=DOUBLE");
+ printf (" %s\n", "-w, --warning=THRESHOLD");
printf (" %s\n", _("Offset to result in warning status (seconds)"));
- printf (" %s\n", "-c, --critical=DOUBLE");
+ printf (" %s\n", "-c, --critical=THRESHOLD");
printf (" %s\n", _("Offset to result in critical status (seconds)"));
- printf (" %s\n", "-j, --warning=DOUBLE");
- printf (" %s\n", _("Warning value for jitter"));
- printf (" %s\n", "-k, --critical=DOUBLE");
- printf (" %s\n", _("Critical value for jitter"));
+ printf (" %s\n", "-W, --warning=THRESHOLD");
+ printf (" %s\n", _("Warning threshold for stratum"));
+ printf (" %s\n", "-W, --critical=THRESHOLD");
+ printf (" %s\n", _("Critical threshold for stratum"));
+ printf (" %s\n", "-j, --warning=THRESHOLD");
+ printf (" %s\n", _("Warning threshold for jitter"));
+ printf (" %s\n", "-k, --critical=THRESHOLD");
+ printf (" %s\n", _("Critical threshold for jitter"));
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
printf (_(UT_VERBOSE));
+
+ printf("\n");
+ printf("%s\n", _("Notes:"));
+ printf(" %s\n", _("See:"));
+ printf(" %s\n", ("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT"));
+ printf(" %s\n", _("for THRESHOLD format and examples."));
+
printf (_(UT_SUPPORT));
}
print_usage(void)
{
printf (_("Usage:"));
- printf("%s -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n", progname);
+ printf(" %s -H <host> [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>]\n", progname);
+ printf(" [-j <warn>] [-k <crit>] [-v verbose]\n");
}