1
0
mirror of https://github.com/librenms/librenms-agent.git synced 2024-05-09 09:54:52 +00:00

47 lines
1.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
################################################################
# copy this script to somewhere like /opt and make chmod +x it #
# edit your snmpd.conf and include #
2016-09-12 11:45:14 +03:00
# extend ntp-server /opt/ntp-server.sh #
# restart snmpd and activate the app for desired host #
# please make sure you have the path/binaries below #
################################################################
# Binaries and paths required #
################################################################
2016-09-12 11:43:34 +03:00
BIN_NTPD='/usr/sbin/ntpd'
BIN_NTPQ='/usr/sbin/ntpq'
2016-09-12 11:43:34 +03:00
BIN_NTPDC='/usr/sbin/ntpdc'
BIN_GREP='/usr/bin/grep'
BIN_TR='/usr/bin/tr'
BIN_CUT='/usr/bin/cut'
BIN_SED='/usr/bin/sed'
################################################################
# Don't change anything unless you know what are you doing #
################################################################
2016-09-12 11:43:34 +03:00
VER=`$BIN_NTPD --version`
CMD0=`$BIN_NTPQ -c rv | $BIN_GREP -Eow "stratum=[0-9]+" | $BIN_CUT -d "=" -f 2`
echo $CMD0
CMD1=`$BIN_NTPQ -c rv | $BIN_GREP 'jitter' | $BIN_TR '\n' ' '`
IFS=', ' read -r -a array <<< "$CMD1"
for value in 2 3 4 5 6
do
echo ${array["$value"]} | $BIN_CUT -d "=" -f 2
done
2016-09-12 11:52:13 +03:00
if [[ "$VER" =~ '4.2.6p5' ]]
2016-09-12 11:43:34 +03:00
then
CMD2=`$BIN_NTPDC -c iostats | $BIN_TR -d ' ' | $BIN_TR '\n' ','`
2016-09-12 11:52:13 +03:00
else
CMD2=`$BIN_NTPQ -c iostats localhost | $BIN_TR -d ' ' | $BIN_TR '\n' ','`
2016-09-12 11:43:34 +03:00
fi
IFS=',' read -r -a array <<< "$CMD2"
for value in 0 1 2 3 5 6 7 8
do
echo ${array["$value"]} | $BIN_SED -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g'
done