From 25fb357809a38138677972783b3956f2f9c4cdb0 Mon Sep 17 00:00:00 2001 From: Jellyfrog Date: Thu, 18 Mar 2021 20:07:25 +0100 Subject: [PATCH] Lint more files (#356) --- agent-local/bind | 6 +-- agent-local/check_mrpe | 7 ++- agent-local/dmi | 2 +- agent-local/nfsstats | 2 +- agent-local/rocks.sh | 1 + snmp/Openwrt/wlClients.sh | 9 ++-- snmp/Openwrt/wlFrequency.sh | 5 +-- snmp/Openwrt/wlNoiseFloor.sh | 5 +-- snmp/Openwrt/wlRate.sh | 13 +++--- snmp/Openwrt/wlSNR.sh | 13 +++--- snmp/apache-stats.sh | 3 +- snmp/backupninja.py | 26 +++++------ snmp/chip.sh | 6 +-- snmp/distro | 68 ++++++++++++++--------------- snmp/freeradius.sh | 83 ++++++++++++++++++------------------ snmp/gpsd | 3 +- snmp/icecast-stats.sh | 2 +- snmp/mdadm | 5 ++- snmp/ntp-client | 3 +- snmp/ntp-server.sh | 10 +++-- snmp/phpfpmsp | 12 +++--- snmp/pi-hole | 4 +- snmp/powermon-snmp.py | 4 +- snmp/shoutcast.php | 1 + snmp/voipmon-stats.sh | 2 +- 25 files changed, 148 insertions(+), 147 deletions(-) diff --git a/agent-local/bind b/agent-local/bind index ed294e3..f30597c 100755 --- a/agent-local/bind +++ b/agent-local/bind @@ -4,18 +4,18 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . stats="/etc/bind/named.stats" echo "<<>>" -> $stats +true > $stats rndc stats && cat $stats diff --git a/agent-local/check_mrpe b/agent-local/check_mrpe index d21b6d9..ab6e809 100644 --- a/agent-local/check_mrpe +++ b/agent-local/check_mrpe @@ -14,7 +14,7 @@ EXITCODE=3 while getopts "Vha:H:p:" opt; do case $opt in - V) printf "check_mrpe v$VERSION\n" + V) printf 'check_mrpe v%s\n' "$VERSION" exit 0 ;; h) hflag=1 @@ -25,8 +25,7 @@ while getopts "Vha:H:p:" opt; do H) Hflag=1 Hval="$OPTARG" ;; - p) pflag=1 - pval="$OPTARG" + p) pval="$OPTARG" ;; \?) hflag=1 EXITCODE=0 @@ -80,4 +79,4 @@ for i in $($BIN_NC -w 1 "$Hval" "$pval" 2>&1 | $BIN_SED '/^<<>>/,/^<<>>' # requires dmidecode for FIELD in bios-vendor bios-version bios-release-date system-manufacturer system-product-name system-version system-serial-number system-uuid baseboard-manufacturer baseboard-product-name baseboard-version baseboard-serial-number baseboard-asset-tag chassis-manufacturer chassis-type chassis-version chassis-serial-number chassis-asset-tag processor-family processor-manufacturer processor-version processor-frequency do - echo $FIELD=$(dmidecode -s $FIELD | grep -v '^#') + echo $FIELD="$(dmidecode -s $FIELD | grep -v '^#')" done diff --git a/agent-local/nfsstats b/agent-local/nfsstats index 404e2fd..a43afe7 100755 --- a/agent-local/nfsstats +++ b/agent-local/nfsstats @@ -21,7 +21,7 @@ LOG_NEW='/var/cache/librenms/nfsstats_new' $BIN_NFSSTAT -$CFG_NFSVER -n -l | $BIN_TR -s " " | $BIN_CUT -d ' ' -f 5 | $BIN_GREP -v '^$' > $LOG_NEW 2>&1 $BIN_PASTE $LOG_NEW $LOG_OLD | while read a b ; do - echo $(($a - $b)) + echo $(($a - $b)) done $BIN_RM $LOG_OLD 2>&1 diff --git a/agent-local/rocks.sh b/agent-local/rocks.sh index 9ff1ec3..7636a02 100755 --- a/agent-local/rocks.sh +++ b/agent-local/rocks.sh @@ -7,6 +7,7 @@ # @author SvennD # required +# shellcheck disable=SC1091 source /etc/profile.d/sge-binaries.sh; QSTAT="/opt/gridengine/bin/linux-x64/qstat" diff --git a/snmp/Openwrt/wlClients.sh b/snmp/Openwrt/wlClients.sh index 5becad1..f454e59 100755 --- a/snmp/Openwrt/wlClients.sh +++ b/snmp/Openwrt/wlClients.sh @@ -1,5 +1,5 @@ #!/bin/sh - + # wlClients.sh # Counts connected (associated) Wi-Fi devices # Arguments: targed interface. Assumes all interfaces if no argument @@ -12,16 +12,13 @@ if [ $# -gt 1 ]; then fi # Get path to this script -scriptdir=$(dirname $(readlink -f -- "$0")) +scriptdir=$(dirname "$(readlink -f -- "$0")") -# Get hostname, interface list. Set target, which is name returned for interface -hostname=$(/bin/uname -n) +# Get interface list. Set target, which is name returned for interface if [ "$1" ]; then interfaces=$1 - target=$1 else interfaces=$(cat "$scriptdir"/wlInterfaces.txt | cut -f 1 -d",") - target=wlan fi # Count associated devices diff --git a/snmp/Openwrt/wlFrequency.sh b/snmp/Openwrt/wlFrequency.sh index 83e68b1..658459a 100755 --- a/snmp/Openwrt/wlFrequency.sh +++ b/snmp/Openwrt/wlFrequency.sh @@ -1,5 +1,5 @@ #!/bin/sh - + # wlFrequency.sh # Returns wlFrequency, in MHz (not channel number) # Arguments: targed interface @@ -11,8 +11,7 @@ if [ $# -ne 1 ]; then exit 1 fi -# Get hostname, extract frequency -hostname=$(/bin/uname -n) +# Extract frequency frequency=$(/usr/sbin/iw dev "$1" info | /bin/grep channel | /usr/bin/cut -f 2- -s -d" " | /usr/bin/cut -f 2- -s -d"(" | /usr/bin/cut -f 1 -s -d" ") # Return snmp result diff --git a/snmp/Openwrt/wlNoiseFloor.sh b/snmp/Openwrt/wlNoiseFloor.sh index 47d4b4e..a3880cf 100755 --- a/snmp/Openwrt/wlNoiseFloor.sh +++ b/snmp/Openwrt/wlNoiseFloor.sh @@ -1,5 +1,5 @@ #!/bin/sh - + # wlNoiseFloor.sh # Returns wlNoiseFloor, in dBm # Arguments: targed interface @@ -11,9 +11,8 @@ if [ $# -ne 1 ]; then exit 1 fi -# Get hostname, extract noise floor. Note, all associated stations have the same value, so just grab the first one +# Extract noise floor. Note, all associated stations have the same value, so just grab the first one # Use tail, not head (i.e. last line, not first), as head exits immediately, breaks the pipe to cut! -hostname=$(/bin/uname -n) noise=$(/usr/bin/iwinfo "$1" assoclist | /usr/bin/cut -s -d "/" -f 2 | /usr/bin/cut -s -d "(" -f 1 | /usr/bin/cut -s -d " " -f 2 | /usr/bin/tail -1) # Return snmp result diff --git a/snmp/Openwrt/wlRate.sh b/snmp/Openwrt/wlRate.sh index 08b68b1..6b90724 100755 --- a/snmp/Openwrt/wlRate.sh +++ b/snmp/Openwrt/wlRate.sh @@ -1,5 +1,5 @@ #!/bin/sh - + # wlRate.sh # Returns wlRate, bit rate in Mbit/s # Arguments: @@ -14,17 +14,16 @@ if [ $# -ne 3 ]; then exit 1 fi -# Get hostname, calculate result. Sum just for debug, and have to return integer +# Calculate result. Sum just for debug, and have to return integer # => If not integer (e.g. 2.67e+07), LibreNMS will drop the exponent (result, 2.67 bits/sec!) -hostname=$(/bin/uname -n) ratelist=$(/usr/sbin/iw dev "$1" station dump | /bin/grep "$2 bitrate" | /usr/bin/cut -f 2 -s -d" ") -if [ "$3" == "sum" ]; then +if [ "$3" = "sum" ]; then result=$(/bin/echo "$ratelist" | /usr/bin/awk -F ':' '{sum += $2} END {printf "%d\n", 1000000*sum}') -elif [ "$3" == "avg" ]; then +elif [ "$3" = "avg" ]; then result=$(/bin/echo "$ratelist" | /usr/bin/awk -F ':' '{sum += $2} END {printf "%d\n", 1000000*sum/NR}') -elif [ "$3" == "min" ]; then +elif [ "$3" = "min" ]; then result=$(/bin/echo "$ratelist" | /usr/bin/awk -F ':' 'NR == 1 || $2 < min {min = $2} END {printf "%d\n", 1000000*min}') -elif [ "$3" == "max" ]; then +elif [ "$3" = "max" ]; then result=$(/bin/echo "$ratelist" | /usr/bin/awk -F ':' 'NR == 1 || $2 > max {max = $2} END {printf "%d\n", 1000000*max}') fi diff --git a/snmp/Openwrt/wlSNR.sh b/snmp/Openwrt/wlSNR.sh index d19283d..2378c1a 100755 --- a/snmp/Openwrt/wlSNR.sh +++ b/snmp/Openwrt/wlSNR.sh @@ -1,5 +1,5 @@ #!/bin/sh - + # wlSNR.sh # Returns wlSNR, Signal-to-Noise ratio in dB # Arguments: @@ -13,16 +13,15 @@ if [ $# -ne 2 ]; then exit 1 fi -# Get hostname, calculate result. Sum just for debug, and return integer (safest / easiest) -hostname=$(/bin/uname -n) +# Calculate result. Sum just for debug, and return integer (safest / easiest) snrlist=$(/usr/bin/iwinfo "$1" assoclist | /usr/bin/cut -s -d "/" -f 2 | /usr/bin/cut -s -d "(" -f 2 | /usr/bin/cut -s -d " " -f 2 | /usr/bin/cut -s -d ")" -f 1) -if [ "$2" == "sum" ]; then +if [ "$2" = "sum" ]; then result=$(/bin/echo "$snrlist" | /usr/bin/awk -F ':' '{sum += $1} END {printf "%d\n", sum}') -elif [ "$2" == "avg" ]; then +elif [ "$2" = "avg" ]; then result=$(/bin/echo "$snrlist" | /usr/bin/awk -F ':' '{sum += $1} END {printf "%d\n", sum/NR}') -elif [ "$2" == "min" ]; then +elif [ "$2" = "min" ]; then result=$(/bin/echo "$snrlist" | /usr/bin/awk -F ':' 'NR == 1 || $1 < min {min = $1} END {printf "%d\n", min}') -elif [ "$2" == "max" ]; then +elif [ "$2" = "max" ]; then result=$(/bin/echo "$snrlist" | /usr/bin/awk -F ':' 'NR == 1 || $1 > max {max = $1} END {printf "%d\n", max}') fi diff --git a/snmp/apache-stats.sh b/snmp/apache-stats.sh index 9b677fd..be14a69 100755 --- a/snmp/apache-stats.sh +++ b/snmp/apache-stats.sh @@ -12,7 +12,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin function debugecho() { if [ ${#Debug} -gt 0 ]; then - echo debug: $@ + echo debug: "$@" fi } @@ -23,6 +23,7 @@ function debugecho() { Tmp_File=/tmp/apache_status # Debug=on; use environment, i.e. Debug=on apache-stats.sh +# shellcheck disable=SC2153 if [ "${DEBUG}" != "" ]; then Debug=${DEBUG} else diff --git a/snmp/backupninja.py b/snmp/backupninja.py index 80cf55f..7ae1b46 100644 --- a/snmp/backupninja.py +++ b/snmp/backupninja.py @@ -20,20 +20,20 @@ backupninja_datas = { if not os.path.isfile(logfile): error_string = "file unavailable" error = 1 - break +else: + with io.open(logfile, "r") as f: + for line in reversed(list(f)): + match = re.search( + "^(.*) [a-zA-Z]*: FINISHED: ([0-9]+) actions run. ([0-9]+) fatal. ([0-9]+) error. ([0-9]+) warning.$", + line, + ) + if match: + backupninja_datas["last_actions"] = int(match.group(2)) + backupninja_datas["last_fatal"] = int(match.group(3)) + backupninja_datas["last_error"] = int(match.group(4)) + backupninja_datas["last_warning"] = int(match.group(5)) + break -with io.open(logfile, "r") as f: - for line in reversed(list(f)): - match = re.search( - "^(.*) [a-zA-Z]*: FINISHED: ([0-9]+) actions run. ([0-9]+) fatal. ([0-9]+) error. ([0-9]+) warning.$", - line, - ) - if match: - backupninja_datas["last_actions"] = int(match.group(2)) - backupninja_datas["last_fatal"] = int(match.group(3)) - backupninja_datas["last_error"] = int(match.group(4)) - backupninja_datas["last_warning"] = int(match.group(5)) - break output = { "version": version, diff --git a/snmp/chip.sh b/snmp/chip.sh index 4dc2fac..ff2cebb 100644 --- a/snmp/chip.sh +++ b/snmp/chip.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Based on https://github.com/Photonicsguy/CHIP +# Based on https://github.com/Photonicsguy/CHIP # Enable ADC registers i2cset -y -f 0 0x34 0x82 0xff @@ -67,7 +67,7 @@ if [ $STATUS_BATCON == 1 ]; then BAT_PERCENT=$(printf "%d" "$REG") else VBAT=0 - BATT_CUR=0 + #BATT_CUR=0 BAT_PERCENT=0 fi @@ -82,6 +82,6 @@ echo $ACIN_C echo $VBUS echo $VBUS_C echo $VBAT -echo $(echo "$BAT_C-$BAT_D"|bc) +echo "$(echo "$BAT_C-$BAT_D"|bc)" echo $BAT_PERCENT echo $STATUS_CHARGING diff --git a/snmp/distro b/snmp/distro index 69cd452..f481bbe 100755 --- a/snmp/distro +++ b/snmp/distro @@ -1,24 +1,24 @@ #!/usr/bin/env sh # Detects which OS and if it is Linux then it will detect which Linux Distribution. -OS=`uname -s` -REV=`uname -r` -MACH=`uname -m` +OS=$(uname -s) +REV=$(uname -r) +#MACH=$(uname -m) if [ "${OS}" = "SunOS" ] ; then OS=Solaris - ARCH=`uname -p` - OSSTR="${OS} ${REV}(${ARCH} `uname -v`)" + ARCH=$(uname -p) + OSSTR="${OS} ${REV}(${ARCH} $(uname -v))" elif [ "${OS}" = "AIX" ] ; then - OSSTR="${OS} `oslevel` (`oslevel -r`)" + OSSTR="${OS} $(oslevel) ($(oslevel -r))" elif [ "${OS}" = "Linux" ] ; then - KERNEL=`uname -r` + #KERNEL=$(uname -r) if [ -f /etc/fedora-release ]; then DIST=$(cat /etc/fedora-release | awk '{print $1}') - REV=`cat /etc/fedora-release | sed s/.*release\ // | sed s/\ .*//` + REV=$(cat /etc/fedora-release | sed s/.*release\ // | sed s/\ .*//) elif [ -f /etc/redhat-release ] ; then DIST=$(cat /etc/redhat-release | awk '{print $1}') @@ -29,8 +29,8 @@ elif [ "${OS}" = "Linux" ] ; then DIST="CloudLinux" elif [ "${DIST}" = "Mandriva" ]; then DIST="Mandriva" - PSEUDONAME=`cat /etc/mandriva-release | sed s/.*\(// | sed s/\)//` - REV=`cat /etc/mandriva-release | sed s/.*release\ // | sed s/\ .*//` + #PSEUDONAME=$(cat /etc/mandriva-release | sed s/.*\(// | sed s/\)//) + REV=$(cat /etc/mandriva-release | sed s/.*release\ // | sed s/\ .*//) elif [ -f /etc/oracle-release ]; then DIST="Oracle" elif [ -f /etc/rockstor-release ]; then @@ -39,39 +39,39 @@ elif [ "${OS}" = "Linux" ] ; then DIST="RedHat" fi - PSEUDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//` - REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//` + #PSEUDONAME=$(cat /etc/redhat-release | sed s/.*\(// | sed s/\)//) + REV=$(cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//) elif [ -f /etc/mandrake-release ] ; then DIST='Mandrake' - PSEUDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//` - REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//` + #PSEUDONAME=$(cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//) + REV=$(cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//) elif [ -f /etc/devuan_version ] ; then - DIST="Devuan `cat /etc/devuan_version`" + DIST="Devuan $(cat /etc/devuan_version)" REV="" elif [ -f /etc/debian_version ] ; then - DIST="Debian `cat /etc/debian_version`" + DIST="Debian $(cat /etc/debian_version)" REV="" IGNORE_OS_RELEASE=1 if [ -f /usr/bin/lsb_release ] ; then - ID=`lsb_release -i | awk -F ':' '{print $2}' | sed 's/ //g'` + ID=$(lsb_release -i | awk -F ':' '{print $2}' | sed 's/ //g') fi if [ "${ID}" = "Raspbian" ] ; then - DIST="Raspbian `cat /etc/debian_version`" + DIST="Raspbian $(cat /etc/debian_version)" fi if [ -f /usr/bin/pveversion ]; then - DIST="${DIST}/PVE `/usr/bin/pveversion | cut -d '/' -f 2`" + DIST="${DIST}/PVE $(/usr/bin/pveversion | cut -d '/' -f 2)" fi if [ -f /usr/bin/pmgversion ]; then # pmgversion requires root permissions to run, please add NOPASSWD setting to visudo. - DIST="${DIST}/PMG `sudo /usr/bin/pmgversion | cut -d '/' -f 2`" + DIST="${DIST}/PMG $(sudo /usr/bin/pmgversion | cut -d '/' -f 2)" fi if [ -f /etc/dogtag ]; then - DIST=`cat /etc/dogtag` + DIST=$(cat /etc/dogtag) fi - + elif [ -f /etc/gentoo-release ] ; then DIST="Gentoo" REV=$(tr -d '[[:alpha:]]' /dev/null 2>&1 + REV=$(nvram show | grep buildno= | egrep -o '[0-9].[0-9].[0-9]') > /dev/null 2>&1 fi fi # try standardized os version methods - if [ -f /etc/os-release -a "${IGNORE_OS_RELEASE}" != 1 ] ; then + if [ -f /etc/os-release ] && [ "${IGNORE_OS_RELEASE}" != 1 ] ; then . /etc/os-release STD_DIST="$NAME" STD_REV="$VERSION_ID" - elif [ -f /etc/lsb-release -a "${IGNORE_LSB}" != 1 ] ; then + elif [ -f /etc/lsb-release ] && [ "${IGNORE_LSB}" != 1 ] ; then STD_DIST=$(lsb_release -si) STD_REV=$(lsb_release -sr) fi @@ -133,18 +133,18 @@ elif [ "${OS}" = "Linux" ] ; then elif [ "${OS}" = "Darwin" ] ; then if [ -f /usr/bin/sw_vers ] ; then - OSSTR=`/usr/bin/sw_vers|grep -v Build|sed 's/^.*:.//'| tr "\n" ' '` + OSSTR=$(/usr/bin/sw_vers|grep -v Build|sed 's/^.*:.//'| tr "\n" ' ') fi elif [ "${OS}" = "FreeBSD" ] ; then if [ -f /etc/version ] ; then DIST=$(cat /etc/version | cut -d'-' -f 1) if [ "${DIST}" = "FreeNAS" ]; then - OSSTR=`cat /etc/version | cut -d' ' -f 1` + OSSTR=$(cat /etc/version | cut -d' ' -f 1) fi else - OSSTR=`/usr/bin/uname -mior` + OSSTR=$(/usr/bin/uname -mior) fi fi -echo ${OSSTR} +echo "${OSSTR}" diff --git a/snmp/freeradius.sh b/snmp/freeradius.sh index 8a9423b..6a0a29f 100644 --- a/snmp/freeradius.sh +++ b/snmp/freeradius.sh @@ -11,6 +11,7 @@ RADIUS_PORT='18121' RADIUS_KEY='adminsecret' if [ -f $CONFIGFILE ]; then + # shellcheck disable=SC1090 . $CONFIGFILE fi @@ -27,44 +28,44 @@ fi RESULT=$(echo "$RADIUS_STATUS_CMD" | $BIN_RADCLIENT -x $RADIUS_SERVER:$RADIUS_PORT status $RADIUS_KEY) -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Access-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Access-Accepts = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Access-Rejects = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Access-Challenges = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Auth-Responses = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Auth-Duplicate-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Auth-Malformed-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Auth-Invalid-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Auth-Dropped-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Auth-Unknown-Types = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Accounting-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Accounting-Responses = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Acct-Duplicate-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Acct-Malformed-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Acct-Invalid-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Acct-Dropped-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Acct-Unknown-Types = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Access-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Access-Accepts = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Access-Rejects = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Access-Challenges = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Auth-Responses = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Auth-Duplicate-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Auth-Malformed-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Auth-Invalid-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Auth-Dropped-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Auth-Unknown-Types = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Accounting-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Accounting-Responses = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Acct-Duplicate-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Acct-Malformed-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Acct-Invalid-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Acct-Dropped-Requests = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Total-Proxy-Acct-Unknown-Types = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Queue-Len-Internal = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Queue-Len-Proxy = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Queue-Len-Auth = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Queue-Len-Acct = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Queue-Len-Detail = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Queue-PPS-In = [[:digit:]]*' -echo "$RESULT" | grep -o 'FreeRADIUS-Queue-PPS-Out = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Access-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Access-Accepts = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Access-Rejects = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Access-Challenges = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Auth-Responses = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Auth-Duplicate-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Auth-Malformed-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Auth-Invalid-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Auth-Dropped-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Auth-Unknown-Types = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Accounting-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Accounting-Responses = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Acct-Duplicate-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Acct-Malformed-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Acct-Invalid-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Acct-Dropped-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Acct-Unknown-Types = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Access-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Access-Accepts = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Access-Rejects = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Access-Challenges = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Auth-Responses = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Auth-Duplicate-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Auth-Malformed-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Auth-Invalid-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Auth-Dropped-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Auth-Unknown-Types = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Accounting-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Accounting-Responses = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Acct-Duplicate-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Acct-Malformed-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Acct-Invalid-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Acct-Dropped-Requests = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Total-Proxy-Acct-Unknown-Types = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Queue-Len-Internal = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Queue-Len-Proxy = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Queue-Len-Auth = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Queue-Len-Acct = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Queue-Len-Detail = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Queue-PPS-In = [[:digit:]]*' +echo "$RESULT" | $BIN_GREP -o 'FreeRADIUS-Queue-PPS-Out = [[:digit:]]*' diff --git a/snmp/gpsd b/snmp/gpsd index eed38c4..913f43d 100755 --- a/snmp/gpsd +++ b/snmp/gpsd @@ -18,12 +18,13 @@ BIN_PYTHON='/usr/bin/env python' # Check for config file CONFIG=$0".conf" if [ -f "$CONFIG" ]; then + # shellcheck disable=SC1090 . "$CONFIG" fi # Create Temp File TMPFILE=$(mktemp) -trap "rm -f $TMPFILE" 0 2 3 15 +trap 'rm -f $TMPFILE' 0 2 3 15 # Write GPSPIPE Data to Temp File $BIN_GPIPE -w -n 20 > "$TMPFILE" diff --git a/snmp/icecast-stats.sh b/snmp/icecast-stats.sh index 541c174..e373f6f 100644 --- a/snmp/icecast-stats.sh +++ b/snmp/icecast-stats.sh @@ -5,7 +5,7 @@ used_memory=$(ps -U icecast -o rsz | awk 'FNR==2{print}') cpu_load=$(ps -U icecast -o %cpu | awk 'FNR==2{print}') pid=$(pidof icecast) -total_files=$(ls -l /proc/"${pid}"/fd | wc -l) +total_files=$(find /proc/"${pid}"/fd | wc -l) echo "Used Memory=""$used_memory" echo "CPU Load=""$cpu_load" diff --git a/snmp/mdadm b/snmp/mdadm index 8565f8d..5e820c8 100755 --- a/snmp/mdadm +++ b/snmp/mdadm @@ -7,7 +7,8 @@ REALPATH=/usr/bin/realpath CONFIGFILE=/etc/snmp/mdadm.conf if [ -f $CONFIGFILE ] ; then - . $CONFIGFILE + # shellcheck disable=SC1090 + . $CONFIGFILE fi VERSION=1 @@ -19,7 +20,7 @@ OUTPUT_DATA='[' # use 'ls' command to check if md blocks exist if $LS /dev/md?* 1> /dev/null 2>&1 ; then for ARRAY_BLOCKDEVICE in $($LS -1 /dev/md?*) ; do - RAID="/sys/block/"$($BASENAME $($REALPATH "$ARRAY_BLOCKDEVICE")) + RAID="/sys/block/"$($BASENAME "$($REALPATH "$ARRAY_BLOCKDEVICE")") # ignore arrays with no slaves if [ -z "$($LS -1 "$RAID"/slaves 2> /dev/null)" ] ; then diff --git a/snmp/ntp-client b/snmp/ntp-client index 0df9ee0..eccb5e5 100755 --- a/snmp/ntp-client +++ b/snmp/ntp-client @@ -13,13 +13,12 @@ # Don't change anything unless you know what are you doing # ################################################################ BIN_NTPQ='/usr/bin/env ntpq' -BIN_NTPD='/usr/bin/env ntpd' BIN_GREP='/usr/bin/env grep' BIN_AWK='/usr/bin/env awk' -BIN_HEAD='/usr/bin/env head' CONFIG=$0".conf" if [ -f "$CONFIG" ]; then + # shellcheck disable=SC1090 . "$CONFIG" fi diff --git a/snmp/ntp-server.sh b/snmp/ntp-server.sh index 6fa2f69..ba1af15 100755 --- a/snmp/ntp-server.sh +++ b/snmp/ntp-server.sh @@ -3,7 +3,7 @@ # Alternatively you can put them in $0.conf, meaning if you've named # this script ntp-client.sh then it must go in ntp-client.sh.conf . # -# NTPQV output version of "ntpq -c rv" +# NTPQV output version of "ntpq -c rv" # p1 DD-WRT and some other outdated linux distros # p11 FreeBSD 11 and any linux distro that is up to date # @@ -16,7 +16,8 @@ CONFIGFILE=/etc/snmp/ntp-server.conf BIN_ENV='/usr/bin/env' if [ -f $CONFIGFILE ] ; then - . $CONFIGFILE + # shellcheck disable=SC1090 + . $CONFIGFILE fi BIN_NTPD="$BIN_ENV ntpd" @@ -34,7 +35,8 @@ NTPQV="p11" ################################################################ CONFIG=$0".conf" if [ -f "$CONFIG" ]; then - . "$CONFIG" + # shellcheck disable=SC1090 + . "$CONFIG" fi VERSION=1 @@ -75,7 +77,7 @@ IGNOREDPACKETS=$(echo "$CMD2" | $BIN_AWK -F ' ' '{print $7}') RECEIVEDPACKETS=$(echo "$CMD2" | $BIN_AWK -F ' ' '{print $8}') PACKETSSENT=$(echo "$CMD2" | $BIN_AWK -F ' ' '{print $9}') PACKETSENDFAILURES=$(echo "$CMD2" | $BIN_AWK -F ' ' '{print $10}') -INPUTWAKEUPS=$(echo "$CMD2" | $BIN_AWK -F ' ' '{print $11}') +#INPUTWAKEUPS=$(echo "$CMD2" | $BIN_AWK -F ' ' '{print $11}') USEFULINPUTWAKEUPS=$(echo "$CMD2" | $BIN_AWK -F ' ' '{print $12}') echo '{"data":{"offset":"'"$OFFSET"\ diff --git a/snmp/phpfpmsp b/snmp/phpfpmsp index a4d7a43..6fbf22c 100644 --- a/snmp/phpfpmsp +++ b/snmp/phpfpmsp @@ -52,13 +52,13 @@ opts="" # Contributed by @safeie with PR #276 # Modified to work as a SNMP extend by Zane C. Bowers-Hadley -declare -A phpfpm_urls=() -declare -A phpfpm_curl_opts=() +#declare -A phpfpm_urls=() +#declare -A phpfpm_curl_opts=() # _update_every is a special variable - it holds the number of seconds # between the calls of the _update() function -phpfpm_update_every= -phpfpm_priority=60000 +#phpfpm_update_every= +#phpfpm_priority=60000 declare -a phpfpm_response=() phpfpm_pool="" @@ -78,8 +78,8 @@ phpfpm_slow_requests=0 # local opts="${1}" url="${2}" - phpfpm_response=($(curl -Ss "${opts}" "${url}")) - [ $? -ne 0 -o "${#phpfpm_response[@]}" -eq 0 ] && exit 1 + phpfpm_response=("$(curl -Ss "${opts}" "${url}")") + [ $? -ne 0 ] || [ "${#phpfpm_response[@]}" -eq 0 ] && exit 1 if [[ "${phpfpm_response[0]}" != "pool:" \ || "${phpfpm_response[2]}" != "process" \ diff --git a/snmp/pi-hole b/snmp/pi-hole index 342ef10..2a7682f 100644 --- a/snmp/pi-hole +++ b/snmp/pi-hole @@ -12,11 +12,13 @@ PICONFIGFILE='/etc/pihole/setupVars.conf' DHCPLEASEFILE='/etc/pihole/dhcp.leases' if [ -f $CONFIGFILE ]; then + # shellcheck disable=SC1090 . $CONFIGFILE fi # read in pi-hole variables for DHCP range if [ -f $PICONFIGFILE ]; then + # shellcheck disable=SC1090 . $PICONFIGFILE fi @@ -74,7 +76,7 @@ debug() { fi if [ -f $PICONFIGFILE ]; then echo '[ok] Pi-Hole config file exists, DHCP stats will be captured if scope active' - else + else echo '[error] Pi-Hole config file does not exist, DHCP stats will not be captured if used' fi if [ -f $DHCPLEASEFILE ]; then diff --git a/snmp/powermon-snmp.py b/snmp/powermon-snmp.py index e280fe7..d9f179c 100755 --- a/snmp/powermon-snmp.py +++ b/snmp/powermon-snmp.py @@ -98,7 +98,7 @@ usage = ( + " [-v|--verbose] [-w|--warnings] | -l|--list-methods | -h|--help" ) methods = ["sensors", "hpasmcli"] -# costPerkWh = 0.15 # <<<< UNCOMMENT +# costPerkWh = 0.15 # <<<< CHANGE ### General functions @@ -352,7 +352,7 @@ except NameError: # Get data data = getData(method) data["supply"] = {} -data["supply"]["rate"] = costPerkWh +data["supply"]["rate"] = costPerkWh # pylint: disable=E0602 # Top-level reading # CUSTOMISE THIS FOR YOUR HOST diff --git a/snmp/shoutcast.php b/snmp/shoutcast.php index 637d3ab..05ee52d 100755 --- a/snmp/shoutcast.php +++ b/snmp/shoutcast.php @@ -39,6 +39,7 @@ function get_data($host, $port) { + $rawdata = null; $fp = @fsockopen($host, $port, $errno, $errstr, 5); if (!$fp) { $connect = 0; diff --git a/snmp/voipmon-stats.sh b/snmp/voipmon-stats.sh index 1dcab4d..66f9439 100644 --- a/snmp/voipmon-stats.sh +++ b/snmp/voipmon-stats.sh @@ -5,7 +5,7 @@ used_memory=$(ps -C voipmonitor -o rsz | awk 'FNR==2 {print}') cpu_load=$(ps -C voipmonitor -o %cpu | awk 'FNR==2 {print}') pid=$(pidof voipmonitor) -total_files=$(ls -l /proc/"${pid}"/fd | wc -l) +total_files=$(find /proc/"${pid}"/fd | wc -l) echo "Used Memory=""$used_memory" echo "CPU Load=""$cpu_load"