Merge lp:~brad-marshall/charms/trusty/ntp/remove-ntp-status-check into lp:charms/trusty/ntp

Proposed by Brad Marshall
Status: Merged
Merged at revision: 22
Proposed branch: lp:~brad-marshall/charms/trusty/ntp/remove-ntp-status-check
Merge into: lp:charms/trusty/ntp
Diff against target: 184 lines (+0/-162)
2 files modified
files/nagios/check_ntpd.pl (+0/-154)
hooks/ntp_hooks.py (+0/-8)
To merge this branch: bzr merge lp:~brad-marshall/charms/trusty/ntp/remove-ntp-status-check
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Paul Gear (community) Approve
Review via email: mp+261927@code.launchpad.net

Description of the change

The check ntp status check is now superseded by ntpmon, no longer needed.

To post a comment you must log in.
Revision history for this message
Paul Gear (paulgear) wrote :

Looks good to me; check_ntpmon.py is designed to handle all of the checks that check_ntpd.pl provides, plus others.

review: Approve
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed file 'files/nagios/check_ntpd.pl'
--- files/nagios/check_ntpd.pl 2015-03-17 06:25:03 +0000
+++ files/nagios/check_ntpd.pl 1970-01-01 00:00:00 +0000
@@ -1,154 +0,0 @@
1#!/usr/bin/perl -w
2# Script from http://exchange.nagios.org/directory/Plugins/Network-Protocols/NTP-and-Time/check_ntpd/details
3
4use Getopt::Long;
5use strict;
6
7GetOptions(
8 "critical=i" => \(my $critical_threshold = '50'),
9 "warning=i" => \(my $warning_threshold = '75'),
10 "peer_critical=i" => \(my $peer_critical_threshold = '1'),
11 "peer_warning=i" => \(my $peer_warning_threshold = '2'),
12 "help" => \&display_help,
13);
14
15my $ntpq_path = `/usr/bin/which ntpq`;
16$ntpq_path =~ s/\n//g;
17my @server_list = `$ntpq_path -pn`;
18my %server_health;
19my $peer_count;
20my $overall_health = 0;
21my $good_count;
22my $selected_primary;
23my $selected_backup = 0;
24
25# Cleanup server list
26for(my $i = 0; $i < @server_list; $i++) {
27 if($server_list[$i] =~ /LOCAL/) {
28 splice(@server_list, $i, 1);
29 $i--;
30 } elsif($server_list[$i] =~ /^===/) {
31 splice(@server_list, $i, 1);
32 $i--;
33 } elsif($server_list[$i] =~ /jitter$/) {
34 splice(@server_list, $i, 1);
35 $i--;
36 } elsif($server_list[$i] =~ /^No association/) {
37 splice(@server_list, $i, 1);
38 $i--;
39 }
40}
41
42# Get number of peers
43$peer_count = @server_list;
44
45# Cycle through peers
46for(my $i = 0; $i < @server_list; $i++) {
47 #split each element of the peer line
48 my @tmp_array = split(" ", $server_list[$i]);
49
50 # Check for first character of peer
51 # space = Discarded due to high stratum and/or failed sanity checks.
52 # x = Designated falseticker by the intersection algorithm.
53 # . = Culled from the end of the candidate list.
54 # - = Discarded by the clustering algorithm.
55 # + = Included in the final selection set.
56 # # = Selected for synchronization but distance exceeds maximum.
57 # * = Selected for synchronization.
58 # o = Selected for synchronization, pps signal in use.
59 if(substr($tmp_array[0], 0, 1) eq '*') {
60 $selected_primary = "true";
61 } elsif(substr($tmp_array[0], 0, 1) eq '+') {
62 $selected_backup++;
63 }
64
65 $good_count = 0;
66 # Read in the octal number in column 6
67 my $rearch = oct($tmp_array[6]);
68
69 # while $rearch is not 0
70 while($rearch) {
71 # 1s place 0 or 1?
72 $good_count += $rearch % 2;
73 # Bit shift to the right
74 $rearch = $rearch >> 1;
75 }
76
77 # Calculate good packets received
78 $rearch = int(($good_count / 8) * 100);
79
80 # Set percentage in hash
81 $server_health{$tmp_array[0]} = $rearch;
82}
83
84# Cycle through hash and tally weighted average of peer health
85while(my($key, $val) = each(%server_health)) {
86 $overall_health += $val * (1 / $peer_count);
87}
88
89########################### Nagios Status checks ###########################
90#if overall health is below critical threshold, crit
91if($overall_health <= $critical_threshold) {
92 print_overall_health("Critical");
93 print_server_list();
94 exit 2;
95}
96
97#if overall health is below warning and above critical threshold, warn
98if(($overall_health <= $warning_threshold) && ($overall_health > $critical_threshold)) {
99 print_overall_health("Warning");
100 print_server_list();
101 exit 1;
102}
103
104#if the number of peers is below the critical threshold, crit
105if($peer_count <= $peer_critical_threshold) {
106 print_overall_health("Critical");
107 print_server_list();
108 exit 2;
109#if the number of peers is below the warning threshold, warn
110} elsif($peer_count <= $peer_warning_threshold) {
111 print_overall_health("Warning");
112 print_server_list();
113 exit 1;
114}
115
116#check to make sure we have one backup and one selected ntp server
117#if there is no primary ntp server selected, crit
118if($selected_primary ne "true") {
119 print_overall_health("Critical");
120 print_server_list();
121 exit 2;
122#if there is no backup ntp server selected, warn
123} elsif($selected_backup < 1) {
124 print_overall_health("Warning");
125 print_server_list();
126 exit 1;
127}
128
129print_overall_health("OK");
130print_server_list();
131exit 0;
132
133sub print_server_list {
134 print "---------------------------\n";
135 while(my($key, $val) = each(%server_health)) {
136 print "Received " . $val . "% of the traffic from " . $key . "\n";
137 }
138}
139
140sub print_overall_health {
141 print $_[0] . " - NTPd Health is " . $overall_health . "% with " . $peer_count . " peers.\n";
142}
143
144sub display_help {
145 print "This nagios check is to determine the health of the NTPd client on the local system. It uses the reach attribute from 'ntpq -pn' to determine the health of each listed peer, and determines the average health based on the number of peers. For example, if there are 3 peers, and one peer has dropped 2 of the last 8 packets, it's health will be 75%. This will result in an overall health of about 92% ((100+100+75) / 3).\n";
146 print "\n";
147 print "Available Options:\n";
148 print "\t--critical|-c <num>\t-Set the critical threshold for overall health (default:50)\n";
149 print "\t--warning|-w <num>\t-Set the warning threshold for overall health (default:75)\n";
150 print "\t--peer_critical <num>\t-Set the critical threshold for number of peers (default:1)\n";
151 print "\t--peer_warning <num>\t-Set the warning threshold for number of peers (default:2)\n";
152 print "\t--help|-h\t\t-display this help\n";
153 exit 0;
154}
1550
=== modified file 'hooks/ntp_hooks.py'
--- hooks/ntp_hooks.py 2015-04-27 13:24:33 +0000
+++ hooks/ntp_hooks.py 2015-06-15 06:31:50 +0000
@@ -92,9 +92,6 @@
92 fetch.apt_install(['python-dbus', 'python-psutil'])92 fetch.apt_install(['python-dbus', 'python-psutil'])
93 nagios_ntpmon_checks = hookenv.config('nagios_ntpmon_checks')93 nagios_ntpmon_checks = hookenv.config('nagios_ntpmon_checks')
94 if os.path.isdir(NAGIOS_PLUGINS):94 if os.path.isdir(NAGIOS_PLUGINS):
95 host.rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nagios',
96 'check_ntpd.pl'),
97 os.path.join(NAGIOS_PLUGINS, 'check_ntpd.pl'))
98 if nagios_ntpmon_checks:95 if nagios_ntpmon_checks:
99 host.rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nagios',96 host.rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nagios',
100 'check_ntpmon.py'),97 'check_ntpmon.py'),
@@ -104,11 +101,6 @@
104 current_unit = nrpe.get_nagios_unit_name()101 current_unit = nrpe.get_nagios_unit_name()
105 nrpe_setup = nrpe.NRPE(hostname=hostname)102 nrpe_setup = nrpe.NRPE(hostname=hostname)
106 nrpe.add_init_service_checks(nrpe_setup, ['ntp'], current_unit)103 nrpe.add_init_service_checks(nrpe_setup, ['ntp'], current_unit)
107 nrpe_setup.add_check(
108 shortname="ntp_status",
109 description='Check NTP status {%s}' % current_unit,
110 check_cmd='check_ntpd.pl'
111 )
112 for nc in nagios_ntpmon_checks.split(" "):104 for nc in nagios_ntpmon_checks.split(" "):
113 nrpe_setup.add_check(105 nrpe_setup.add_check(
114 shortname="ntpmon_%s" % nc,106 shortname="ntpmon_%s" % nc,

Subscribers

People subscribed via source and target branches

to all changes: