From ba8efdfa0b098a6e7f4791b7c0f6f28e26c89ed6 Mon Sep 17 00:00:00 2001 From: ReachableCEO Date: Wed, 2 Jul 2025 21:08:39 -0500 Subject: [PATCH] more ntp fixes --- ProjectCode/Agents/librenms/ntp-client | 34 +++++++++++++++++++++++ ProjectCode/Agents/librenms/ntp-client.sh | 25 ----------------- ProjectCode/Modules/OAM/oam-librenms.sh | 2 +- 3 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 ProjectCode/Agents/librenms/ntp-client delete mode 100644 ProjectCode/Agents/librenms/ntp-client.sh diff --git a/ProjectCode/Agents/librenms/ntp-client b/ProjectCode/Agents/librenms/ntp-client new file mode 100644 index 0000000..eccb5e5 --- /dev/null +++ b/ProjectCode/Agents/librenms/ntp-client @@ -0,0 +1,34 @@ +#!/bin/sh +# Please make sure the paths below are correct. +# Alternatively you can put them in $0.conf, meaning if you've named +# this script ntp-client then it must go in ntp-client.conf . +# +# NTPQV output version of "ntpq -c rv" +# Version 4 is the most common and up to date version. +# +# If you are unsure, which to set, run this script and make sure that +# the JSON output variables match that in "ntpq -c rv". +# +################################################################ +# Don't change anything unless you know what are you doing # +################################################################ +BIN_NTPQ='/usr/bin/env ntpq' +BIN_GREP='/usr/bin/env grep' +BIN_AWK='/usr/bin/env awk' + +CONFIG=$0".conf" +if [ -f "$CONFIG" ]; then + # shellcheck disable=SC1090 + . "$CONFIG" +fi + +NTP_OFFSET=$($BIN_NTPQ -c rv | $BIN_GREP "offset" | $BIN_AWK -Foffset= '{print $2}' | $BIN_AWK -F, '{print $1}') +NTP_FREQUENCY=$($BIN_NTPQ -c rv | $BIN_GREP "frequency" | $BIN_AWK -Ffrequency= '{print $2}' | $BIN_AWK -F, '{print $1}') +NTP_SYS_JITTER=$($BIN_NTPQ -c rv | $BIN_GREP "sys_jitter" | $BIN_AWK -Fsys_jitter= '{print $2}' | $BIN_AWK -F, '{print $1}') +NTP_CLK_JITTER=$($BIN_NTPQ -c rv | $BIN_GREP "clk_jitter" | $BIN_AWK -Fclk_jitter= '{print $2}' | $BIN_AWK -F, '{print $1}') +NTP_WANDER=$($BIN_NTPQ -c rv | $BIN_GREP "clk_wander" | $BIN_AWK -Fclk_wander= '{print $2}' | $BIN_AWK -F, '{print $1}') +NTP_VERSION=$($BIN_NTPQ -c rv | $BIN_GREP "version" | $BIN_AWK -F'ntpd ' '{print $2}' | $BIN_AWK -F. '{print $1}') + +echo '{"data":{"offset":"'"$NTP_OFFSET"'","frequency":"'"$NTP_FREQUENCY"'","sys_jitter":"'"$NTP_SYS_JITTER"'","clk_jitter":"'"$NTP_CLK_JITTER"'","clk_wander":"'"$NTP_WANDER"'"},"version":"'"$NTP_VERSION"'","error":"0","errorString":""}' + +exit 0 diff --git a/ProjectCode/Agents/librenms/ntp-client.sh b/ProjectCode/Agents/librenms/ntp-client.sh deleted file mode 100644 index aa56f81..0000000 --- a/ProjectCode/Agents/librenms/ntp-client.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -################################################################ -# copy this script to somewhere like /opt and make chmod +x it # -# edit your snmpd.conf and include # -# extend ntp-client /opt/ntp-client.sh # -# restart snmpd and activate the app for desired host # -# please make sure you have the path/binaries below # -################################################################ -# Binaries and paths required # -################################################################ -BIN_NTPQ="$(command -v ntpq)" -BIN_GREP="$(command -v grep)" -BIN_TR="$(command -v tr)" -BIN_CUT="$(command -v cut)" -################################################################ -# Don't change anything unless you know what are you doing # -################################################################ -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 - diff --git a/ProjectCode/Modules/OAM/oam-librenms.sh b/ProjectCode/Modules/OAM/oam-librenms.sh index b3c8a5c..48e193b 100644 --- a/ProjectCode/Modules/OAM/oam-librenms.sh +++ b/ProjectCode/Modules/OAM/oam-librenms.sh @@ -46,7 +46,7 @@ systemctl start check_mk.socket cat ../../Agents/librenms/dmi.sh > /usr/lib/check_mk_agent/local/dmi.sh cat ../../Agents/librenms/dpkg.sh > /usr/lib/check_mk_agent/local/dpkg.sh #cat ../../Agents/librenms/mysql.sh > /usr/lib/check_mk_agent/local/mysql.sh -cat ../../Agents/librenms/ntp-client.sh > /usr/lib/check_mk_agent/local/ntp-client.sh +cat ../../Agents/librenms/ntp-client > /usr/lib/check_mk_agent/local/ntp-client #cat ../../Agents/librenms/ntp-server.sh > /usr/lib/check_mk_agent/local/ntp-server.sh cat ../../Agents/librenms/os-updates.sh > /usr/lib/check_mk_agent/local/os-updates.sh cat ../../Agents/librenms/postfixdetailed > /usr/lib/check_mk_agent/local/postfixdetailed