Imported Upstream version 1.4.11
This commit is contained in:
parent
cff68b4c0a
commit
1d1585cd09
72 changed files with 16170 additions and 13657 deletions
|
@ -4,9 +4,9 @@
|
|||
*
|
||||
* 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: 2007-09-26 05:16:21 +0100 (Wed, 26 Sep 2007) $
|
||||
* Last Modified: $Date: 2007-12-11 05:57:35 +0000 (Tue, 11 Dec 2007) $
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
|
@ -32,13 +32,13 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: check_ntp.c 1799 2007-09-26 04:16:21Z dermoth $
|
||||
$Id: check_ntp.c 1861 2007-12-11 05:57:35Z dermoth $
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
const char *progname = "check_ntp";
|
||||
const char *revision = "$Revision: 1799 $";
|
||||
const char *copyright = "2006";
|
||||
const char *revision = "$Revision: 1861 $";
|
||||
const char *copyright = "2007";
|
||||
const char *email = "nagiosplug-devel@lists.sourceforge.net";
|
||||
|
||||
#include "common.h"
|
||||
|
@ -47,13 +47,16 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
|
|||
|
||||
static char *server_address=NULL;
|
||||
static int verbose=0;
|
||||
static double owarn=60;
|
||||
static double ocrit=120;
|
||||
static short do_offset=0;
|
||||
static char *owarn="60";
|
||||
static char *ocrit="120";
|
||||
static short do_jitter=0;
|
||||
static double jwarn=5000;
|
||||
static double jcrit=10000;
|
||||
static char *jwarn="5000";
|
||||
static char *jcrit="10000";
|
||||
|
||||
int process_arguments (int, char **);
|
||||
thresholds *offset_thresholds = NULL;
|
||||
thresholds *jitter_thresholds = NULL;
|
||||
void print_help (void);
|
||||
void print_usage (void);
|
||||
|
||||
|
@ -473,7 +476,7 @@ double offset_request(const char *host, int *status){
|
|||
/* now, pick the best server from the list */
|
||||
best_index=best_offset_server(servers, num_hosts);
|
||||
if(best_index < 0){
|
||||
*status=STATE_CRITICAL;
|
||||
*status=STATE_UNKNOWN;
|
||||
} else {
|
||||
/* finally, calculate the average offset */
|
||||
for(i=0; i<servers[best_index].num_responses;i++){
|
||||
|
@ -575,7 +578,7 @@ double jitter_request(const char *host, int *status){
|
|||
if(verbose) printf("%d candiate peers available\n", num_candidates);
|
||||
if(verbose && syncsource_found) printf("synchronization source found\n");
|
||||
if(! syncsource_found){
|
||||
*status = STATE_WARNING;
|
||||
*status = STATE_UNKNOWN;
|
||||
if(verbose) printf("warning: no synchronization source found\n");
|
||||
}
|
||||
|
||||
|
@ -625,7 +628,7 @@ double jitter_request(const char *host, int *status){
|
|||
}
|
||||
if(startofvalue == NULL || startofvalue==nptr){
|
||||
printf("warning: unable to read server jitter response.\n");
|
||||
*status = STATE_WARNING;
|
||||
*status = STATE_UNKNOWN;
|
||||
} else {
|
||||
if(verbose) printf("%g\n", jitter);
|
||||
num_valid++;
|
||||
|
@ -686,18 +689,20 @@ int process_arguments(int argc, char **argv){
|
|||
verbose++;
|
||||
break;
|
||||
case 'w':
|
||||
owarn = atof(optarg);
|
||||
do_offset=1;
|
||||
owarn = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
ocrit = atof(optarg);
|
||||
do_offset=1;
|
||||
ocrit = optarg;
|
||||
break;
|
||||
case 'j':
|
||||
do_jitter=1;
|
||||
jwarn = atof(optarg);
|
||||
jwarn = optarg;
|
||||
break;
|
||||
case 'k':
|
||||
do_jitter=1;
|
||||
jcrit = atof(optarg);
|
||||
jcrit = optarg;
|
||||
break;
|
||||
case 'H':
|
||||
if(is_host(optarg) == FALSE)
|
||||
|
@ -724,14 +729,6 @@ int process_arguments(int argc, char **argv){
|
|||
}
|
||||
}
|
||||
|
||||
if (ocrit < owarn){
|
||||
usage4(_("Critical offset should be larger than warning offset"));
|
||||
}
|
||||
|
||||
if (jcrit < jwarn){
|
||||
usage4(_("Critical jitter should be larger than warning jitter"));
|
||||
}
|
||||
|
||||
if(server_address == NULL){
|
||||
usage4(_("Hostname was not supplied"));
|
||||
}
|
||||
|
@ -742,16 +739,16 @@ int process_arguments(int argc, char **argv){
|
|||
char *perfd_offset (double offset)
|
||||
{
|
||||
return fperfdata ("offset", offset, "s",
|
||||
TRUE, owarn,
|
||||
TRUE, ocrit,
|
||||
TRUE, offset_thresholds->warning->end,
|
||||
TRUE, offset_thresholds->critical->end,
|
||||
FALSE, 0, FALSE, 0);
|
||||
}
|
||||
|
||||
char *perfd_jitter (double jitter)
|
||||
{
|
||||
return fperfdata ("jitter", jitter, "s",
|
||||
do_jitter, jwarn,
|
||||
do_jitter, jcrit,
|
||||
do_jitter, jitter_thresholds->warning->end,
|
||||
do_jitter, jitter_thresholds->critical->end,
|
||||
TRUE, 0, FALSE, 0);
|
||||
}
|
||||
|
||||
|
@ -760,11 +757,18 @@ int main(int argc, char *argv[]){
|
|||
double offset=0, jitter=0;
|
||||
char *result_line, *perfdata_line;
|
||||
|
||||
result=offset_result=jitter_result=STATE_UNKNOWN;
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
result = offset_result = jitter_result = STATE_OK;
|
||||
|
||||
if (process_arguments (argc, argv) == ERROR)
|
||||
usage4 (_("Could not parse arguments"));
|
||||
|
||||
set_thresholds(&offset_thresholds, owarn, ocrit);
|
||||
set_thresholds(&jitter_thresholds, jwarn, jcrit);
|
||||
|
||||
/* initialize alarm signal handling */
|
||||
signal (SIGALRM, socket_timeout_alarm_handler);
|
||||
|
||||
|
@ -772,14 +776,13 @@ int main(int argc, char *argv[]){
|
|||
alarm (socket_timeout);
|
||||
|
||||
offset = offset_request(server_address, &offset_result);
|
||||
if(fabs(offset) > ocrit){
|
||||
/* check_ntp used to always return CRITICAL if offset_result == STATE_UNKNOWN.
|
||||
* Now we'll only do that is the offset thresholds were set */
|
||||
if (do_offset && offset_result == STATE_UNKNOWN) {
|
||||
result = STATE_CRITICAL;
|
||||
} else if(fabs(offset) > owarn) {
|
||||
result = STATE_WARNING;
|
||||
} else {
|
||||
result = STATE_OK;
|
||||
result = get_status(fabs(offset), offset_thresholds);
|
||||
}
|
||||
result=max_state(result, offset_result);
|
||||
|
||||
/* If not told to check the jitter, we don't even send packets.
|
||||
* jitter is checked using NTP control packets, which not all
|
||||
|
@ -788,40 +791,33 @@ int main(int argc, char *argv[]){
|
|||
*/
|
||||
if(do_jitter){
|
||||
jitter=jitter_request(server_address, &jitter_result);
|
||||
if(jitter > jcrit){
|
||||
result = max_state(result, STATE_CRITICAL);
|
||||
} else if(jitter > jwarn) {
|
||||
result = max_state(result, STATE_WARNING);
|
||||
} else if(jitter == -1.0 && result == STATE_OK){
|
||||
/* -1 indicates that we couldn't calculate the jitter
|
||||
* Only overrides STATE_OK from the offset */
|
||||
result = max_state_alt(result, get_status(jitter, jitter_thresholds));
|
||||
/* -1 indicates that we couldn't calculate the jitter
|
||||
* Only overrides STATE_OK from the offset */
|
||||
if(jitter == -1.0 && result == STATE_OK)
|
||||
result = STATE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
result=max_state(result, jitter_result);
|
||||
result = max_state_alt(result, jitter_result);
|
||||
|
||||
switch (result) {
|
||||
case STATE_CRITICAL :
|
||||
asprintf(&result_line, "NTP CRITICAL:");
|
||||
asprintf(&result_line, _("NTP CRITICAL:"));
|
||||
break;
|
||||
case STATE_WARNING :
|
||||
asprintf(&result_line, "NTP WARNING:");
|
||||
asprintf(&result_line, _("NTP WARNING:"));
|
||||
break;
|
||||
case STATE_OK :
|
||||
asprintf(&result_line, "NTP OK:");
|
||||
asprintf(&result_line, _("NTP OK:"));
|
||||
break;
|
||||
default :
|
||||
asprintf(&result_line, "NTP UNKNOWN:");
|
||||
asprintf(&result_line, _("NTP UNKNOWN:"));
|
||||
break;
|
||||
}
|
||||
if(offset_result==STATE_CRITICAL){
|
||||
if(offset_result == STATE_UNKNOWN){
|
||||
asprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
|
||||
asprintf(&perfdata_line, "");
|
||||
} else {
|
||||
if(offset_result==STATE_WARNING){
|
||||
asprintf(&result_line, "%s %s", result_line, _("Unable to fully sample sync server"));
|
||||
}
|
||||
asprintf(&result_line, "%s Offset %.10g secs", result_line, offset);
|
||||
asprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
|
||||
asprintf(&perfdata_line, "%s", perfd_offset(offset));
|
||||
}
|
||||
if (do_jitter) {
|
||||
|
@ -849,16 +845,31 @@ void print_help(void){
|
|||
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", "-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("\n");
|
||||
printf("%s\n", _("Examples:"));
|
||||
printf(" %s\n", _("Normal offset check:"));
|
||||
printf(" %s\n", ("./check_ntp -H ntpserv -w 0.5 -c 1"));
|
||||
printf(" %s\n", _("Check jitter too, avoiding critical notifications if jitter isn't available"));
|
||||
printf(" %s\n", _("(See Notes above for more details on thresholds formats):"));
|
||||
printf(" %s\n", ("./check_ntp -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200"));
|
||||
|
||||
printf (_(UT_SUPPORT));
|
||||
}
|
||||
|
||||
|
@ -866,5 +877,5 @@ void
|
|||
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>] [-j <warn>] [-k <crit>] [-v verbose]\n", progname);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue