From 05ef3c4bd9aabd8bf10e595b2d597958e46b897f Mon Sep 17 00:00:00 2001 From: Thomas Guyot-Sionnest Date: Tue, 10 Apr 2007 07:17:18 +0000 Subject: - Fix possibility of printing scientific numbers in perfdata - Use fperfdata function for perfdata formatting - Make the printing part a bit more flexible (similar to check_disk) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1678 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/check_ntp.c | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 18571184..a884c15e 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c @@ -731,9 +731,26 @@ int process_arguments(int argc, char **argv){ return 0; } +char *perfd_offset (double offset) +{ + return fperfdata ("offset", offset, "s", + TRUE, owarn, + TRUE, ocrit, + FALSE, 0, FALSE, 0); +} + +char *perfd_jitter (double jitter) +{ + return fperfdata ("jitter", jitter, "s", + do_jitter, jwarn, + do_jitter, jcrit, + TRUE, 0, FALSE, 0); +} + int main(int argc, char *argv[]){ int result, offset_result, jitter_result; double offset=0, jitter=0; + char *result_line, *perfdata_line; result=offset_result=jitter_result=STATE_UNKNOWN; @@ -777,28 +794,32 @@ int main(int argc, char *argv[]){ switch (result) { case STATE_CRITICAL : - printf("NTP CRITICAL: "); + asprintf(&result_line, "NTP CRITICAL:"); break; case STATE_WARNING : - printf("NTP WARNING: "); + asprintf(&result_line, "NTP WARNING:"); break; case STATE_OK : - printf("NTP OK: "); + asprintf(&result_line, "NTP OK:"); break; default : - printf("NTP UNKNOWN: "); + asprintf(&result_line, "NTP UNKNOWN:"); break; } if(offset_result==STATE_CRITICAL){ - printf("Offset unknown|offset=unknown"); + asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); } else { if(offset_result==STATE_WARNING){ - printf("Unable to fully sample sync server. "); + asprintf(&result_line, "%s %s", result_line, _("Unable to fully sample sync server")); } - printf("Offset %.10g secs|offset=%.10g", offset, offset); + asprintf(&result_line, "%s Offset %.10g secs", result_line, offset); + asprintf(&perfdata_line, "%s", perfd_offset(offset)); + } + if (do_jitter) { + asprintf(&result_line, "%s, jitter=%f", result_line, jitter); + asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); } - if (do_jitter) printf(" jitter=%f", jitter); - printf("\n"); + printf("%s|%s\n", result_line, perfdata_line); if(server_address!=NULL) free(server_address); return result; @@ -819,11 +840,14 @@ void print_help(void){ print_usage(); printf (_(UT_HELP_VRSN)); printf (_(UT_HOST_PORT), 'p', "123"); - printf (_(UT_WARN_CRIT)); + printf (" %s\n", "-w, --warning=DOUBLE"); + printf (" %s\n", _("Offset to result in warning status (seconds)")); + printf (" %s\n", "-c, --critical=DOUBLE"); + 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", _("Warning value for jitter")); printf (" %s\n", "-k, --critical=DOUBLE"); - printf (" %s\n", _("critical value for jitter")); + printf (" %s\n", _("Critical value for jitter")); printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); printf (_(UT_VERBOSE)); printf (_(UT_SUPPORT)); -- cgit v1.2.3