diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2007-04-10 07:17:18 (GMT) |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2007-04-10 07:17:18 (GMT) |
commit | 05ef3c4bd9aabd8bf10e595b2d597958e46b897f (patch) | |
tree | 6254c722462e94e0cd2c86ee20242596dfe9a6ac /plugins | |
parent | 8b5a26467fdbb37081ad87503559a8140711cac4 (diff) | |
download | monitoring-plugins-05ef3c4bd9aabd8bf10e595b2d597958e46b897f.tar.gz |
- 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
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_ntp.c | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 1857118..a884c15 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
@@ -731,9 +731,26 @@ int process_arguments(int argc, char **argv){ | |||
731 | return 0; | 731 | return 0; |
732 | } | 732 | } |
733 | 733 | ||
734 | char *perfd_offset (double offset) | ||
735 | { | ||
736 | return fperfdata ("offset", offset, "s", | ||
737 | TRUE, owarn, | ||
738 | TRUE, ocrit, | ||
739 | FALSE, 0, FALSE, 0); | ||
740 | } | ||
741 | |||
742 | char *perfd_jitter (double jitter) | ||
743 | { | ||
744 | return fperfdata ("jitter", jitter, "s", | ||
745 | do_jitter, jwarn, | ||
746 | do_jitter, jcrit, | ||
747 | TRUE, 0, FALSE, 0); | ||
748 | } | ||
749 | |||
734 | int main(int argc, char *argv[]){ | 750 | int main(int argc, char *argv[]){ |
735 | int result, offset_result, jitter_result; | 751 | int result, offset_result, jitter_result; |
736 | double offset=0, jitter=0; | 752 | double offset=0, jitter=0; |
753 | char *result_line, *perfdata_line; | ||
737 | 754 | ||
738 | result=offset_result=jitter_result=STATE_UNKNOWN; | 755 | result=offset_result=jitter_result=STATE_UNKNOWN; |
739 | 756 | ||
@@ -777,28 +794,32 @@ int main(int argc, char *argv[]){ | |||
777 | 794 | ||
778 | switch (result) { | 795 | switch (result) { |
779 | case STATE_CRITICAL : | 796 | case STATE_CRITICAL : |
780 | printf("NTP CRITICAL: "); | 797 | asprintf(&result_line, "NTP CRITICAL:"); |
781 | break; | 798 | break; |
782 | case STATE_WARNING : | 799 | case STATE_WARNING : |
783 | printf("NTP WARNING: "); | 800 | asprintf(&result_line, "NTP WARNING:"); |
784 | break; | 801 | break; |
785 | case STATE_OK : | 802 | case STATE_OK : |
786 | printf("NTP OK: "); | 803 | asprintf(&result_line, "NTP OK:"); |
787 | break; | 804 | break; |
788 | default : | 805 | default : |
789 | printf("NTP UNKNOWN: "); | 806 | asprintf(&result_line, "NTP UNKNOWN:"); |
790 | break; | 807 | break; |
791 | } | 808 | } |
792 | if(offset_result==STATE_CRITICAL){ | 809 | if(offset_result==STATE_CRITICAL){ |
793 | printf("Offset unknown|offset=unknown"); | 810 | asprintf(&result_line, "%s %s", result_line, _("Offset unknown")); |
794 | } else { | 811 | } else { |
795 | if(offset_result==STATE_WARNING){ | 812 | if(offset_result==STATE_WARNING){ |
796 | printf("Unable to fully sample sync server. "); | 813 | asprintf(&result_line, "%s %s", result_line, _("Unable to fully sample sync server")); |
797 | } | 814 | } |
798 | printf("Offset %.10g secs|offset=%.10g", offset, offset); | 815 | asprintf(&result_line, "%s Offset %.10g secs", result_line, offset); |
816 | asprintf(&perfdata_line, "%s", perfd_offset(offset)); | ||
817 | } | ||
818 | if (do_jitter) { | ||
819 | asprintf(&result_line, "%s, jitter=%f", result_line, jitter); | ||
820 | asprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); | ||
799 | } | 821 | } |
800 | if (do_jitter) printf(" jitter=%f", jitter); | 822 | printf("%s|%s\n", result_line, perfdata_line); |
801 | printf("\n"); | ||
802 | 823 | ||
803 | if(server_address!=NULL) free(server_address); | 824 | if(server_address!=NULL) free(server_address); |
804 | return result; | 825 | return result; |
@@ -819,11 +840,14 @@ void print_help(void){ | |||
819 | print_usage(); | 840 | print_usage(); |
820 | printf (_(UT_HELP_VRSN)); | 841 | printf (_(UT_HELP_VRSN)); |
821 | printf (_(UT_HOST_PORT), 'p', "123"); | 842 | printf (_(UT_HOST_PORT), 'p', "123"); |
822 | printf (_(UT_WARN_CRIT)); | 843 | printf (" %s\n", "-w, --warning=DOUBLE"); |
844 | printf (" %s\n", _("Offset to result in warning status (seconds)")); | ||
845 | printf (" %s\n", "-c, --critical=DOUBLE"); | ||
846 | printf (" %s\n", _("Offset to result in critical status (seconds)")); | ||
823 | printf (" %s\n", "-j, --warning=DOUBLE"); | 847 | printf (" %s\n", "-j, --warning=DOUBLE"); |
824 | printf (" %s\n", _("warning value for jitter")); | 848 | printf (" %s\n", _("Warning value for jitter")); |
825 | printf (" %s\n", "-k, --critical=DOUBLE"); | 849 | printf (" %s\n", "-k, --critical=DOUBLE"); |
826 | printf (" %s\n", _("critical value for jitter")); | 850 | printf (" %s\n", _("Critical value for jitter")); |
827 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | 851 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); |
828 | printf (_(UT_VERBOSE)); | 852 | printf (_(UT_VERBOSE)); |
829 | printf (_(UT_SUPPORT)); | 853 | printf (_(UT_SUPPORT)); |