From 9412029fa54f2a6d8522d92078ca273c723bcce9 Mon Sep 17 00:00:00 2001 From: Vebryn Date: Tue, 21 Jul 2015 14:18:23 +0200 Subject: [PATCH 1/3] add offset info Hello, A little fix with script output, everything after a pipe is considered by Nagios as perf data. I replace pipe by coma. Offset info is not displayed. It can be usefull in order to see when unsync state appear. I add offset info into perf data field. We can use pnp4nagios to graph it. Best regards --- check_ntpd.pl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/check_ntpd.pl b/check_ntpd.pl index fd26a05..b0920c6 100755 --- a/check_ntpd.pl +++ b/check_ntpd.pl @@ -7,6 +7,7 @@ chomp($ntpq_path); my @server_list = `$ntpq_path -pn`; my %server_health; +my %server_offset; my $peer_count; my $overall_health = 0; my $good_count; @@ -85,6 +86,9 @@ # Set percentage in hash $server_health{$tmp_array[0]} = $x; + + # Set offset in new hash + $server_offset{$tmp_array[0]} = $tmp_array[8]; } # Cycle through hash and tally weighted average of peer health @@ -135,15 +139,22 @@ exit 0; sub print_server_list { - print "------------------------------------------------------\n"; while(my($key, $val) = each(%server_health)) { print "Received " . $val . "% of the traffic from " . $key . "\n"; } + # display perf data + print "|"; + my $i=0; + while(my($key, $val) = each(%server_offset)) { + print "offset" . $i . "=" . "$val;;; "; + $i+=1; + } + print "\n"; } sub print_overall_health { print $_[0] . " - NTPd Health is " . $overall_health . "% with " . $peer_count . " peer(s).\n"; - print "Thresholds: Health (" . $warning_threshold . "%|" . $critical_threshold . "%); Peers (" . $peer_warning_threshold . "|" . $peer_critical_threshold . ")\n"; + print "Thresholds: Health (" . $warning_threshold . "%," . $critical_threshold . "%); Peers (" . $peer_warning_threshold . "," . $peer_critical_threshold . ")\n"; } sub display_help { From 1b15495d82d1f417707263b2c8611632cf574e28 Mon Sep 17 00:00:00 2001 From: Vebryn Date: Fri, 4 Mar 2016 17:14:06 +0100 Subject: [PATCH 2/3] Update check_ntpd.pl Add an option to check whether a backup is available or not --- check_ntpd.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/check_ntpd.pl b/check_ntpd.pl index b0920c6..1b267fb 100755 --- a/check_ntpd.pl +++ b/check_ntpd.pl @@ -20,6 +20,7 @@ "warning=i" => \(my $warning_threshold = '75'), "peer_critical=i" => \(my $peer_critical_threshold = '1'), "peer_warning=i" => \(my $peer_warning_threshold = '2'), + "no-check-backup" => \(my $no_check_backup = 0), "help" => \&display_help, ); @@ -128,7 +129,7 @@ print_server_list(); exit 2; #if there is no backup ntp server selected, warn -} elsif($selected_backup < 1) { +} elsif($no_check_backup and $selected_backup < 1) { print_overall_health("Warning"); print_server_list(); exit 1; @@ -173,6 +174,7 @@ sub display_help { print "\t--warning|-w \t-Set the warning threshold for overall health (default:75)\n"; print "\t--peer_critical \t-Set the critical threshold for number of peers (default:1)\n"; print "\t--peer_warning \t-Set the warning threshold for number of peers (default:2)\n"; + print "\t--no-check-backup\t-Don't check backup availability\n"; print "\t--help|-h\t\t-display this help\n"; exit 0; } From 868fb382361656700b6aed868126dda9d173e76f Mon Sep 17 00:00:00 2001 From: Vebryn Date: Fri, 4 Mar 2016 17:18:08 +0100 Subject: [PATCH 3/3] Update check_ntpd.pl Logic correction --- check_ntpd.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_ntpd.pl b/check_ntpd.pl index 1b267fb..049f40d 100755 --- a/check_ntpd.pl +++ b/check_ntpd.pl @@ -129,7 +129,7 @@ print_server_list(); exit 2; #if there is no backup ntp server selected, warn -} elsif($no_check_backup and $selected_backup < 1) { +} elsif(!$no_check_backup and $selected_backup < 1) { print_overall_health("Warning"); print_server_list(); exit 1;