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

Subscribers

People subscribed via source and target branches

to all changes: