forked from eddimas/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_ntp_by_ssh.sh
executable file
·54 lines (47 loc) · 1.32 KB
/
check_ntp_by_ssh.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
##########################################################
# Plugin to check NTP and Chrony via SSH to avoid use of agents
# Esteban Monge: estebanmonge@riseup.net
# https://github.com/EstebanMonge/nagios-plugins
############################################################
help(){
PROGNAME=$(basename $0)
cat << END
Usage :
$PROGNAME [Hostname or IP] [NTP Client]
OPTION DESCRIPTION
----------------------------------
NTP Client It can be 'chrony' or 'ntp' for Linux or 'aix' for... AIX
AIX require sudo or root permissions
----------------------------------
END
}
host=$1
ntp_client=$2
if [[ $host == "" ]]
then
help
exit 3
fi
case $ntp_client in
chrony)
output=$(ssh $host 'chronyc tracking|grep -e "Leap status"')
;;
ntp)
output=$(ssh $host 'ntpstat |grep synchronised')
;;
aix)
output=$(ssh $host 'sudo ntpq -pn | grep -F "*" | awk "{print \$1,\"offset\",\$9}"|cut -d "*" -f 2')
;;
*) help
exit 3
;;
esac
if [[ $output == *"Normal"* || $output == *"synchronised to NTP server"* || ! -z "$output" ]]
then
echo "OK - $output"
exit 0
else
echo "CRITICAL - $output"
exit 2
fi