Last active
May 28, 2022 17:55
-
-
Save thanosa75/cb025f5b5ed2ea5328e72db600f24251 to your computer and use it in GitHub Desktop.
Fetching ZTE SpeedPort Entry 2i (VDSL modem/router, COSMOTE Greece) modem statistics for Zabbix or other purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Available to all; taken from https://github.com/NMichas/icinga-speedport2i - slight mods | |
## to work with Zabbix 3.4 | |
## | |
## -h (hostname) Mandatory. script does not work without. | |
## if no other parameter is provided, a summary with all values is given. | |
## | |
## each of the other parameters calls it again grepping the particular value. | |
# Gather command-line parameters. | |
while [ "$#" -gt 0 ]; do | |
case "$1" in | |
-h) hostname="$2"; shift 2;; | |
-ucr) $0 -h $hostname | grep Upstream_current_rate | awk -F "=" '{print $2}' ; exit 0;; | |
-dcr) $0 -h $hostname | grep Downstream_current_rate | awk -F "=" '{print $2}' ; exit 0;; | |
-unm) $0 -h $hostname | grep Upstream_noise_margin | awk -F "=" '{print $2}' ; exit 0;; | |
-dnm) $0 -h $hostname | grep Downstream_noise_margin | awk -F "=" '{print $2}' ; exit 0;; | |
-uat) $0 -h $hostname | grep Upstream_attenuation | awk -F "=" '{print $2}' ; exit 0;; | |
-dat) $0 -h $hostname | grep Downstream_attenuation | awk -F "=" '{print $2}' ; exit 0;; | |
-dcrc) $0 -h $hostname | grep DownCrc_errors | awk -F "=" '{print $2}' ; exit 0;; | |
-ucrc) $0 -h $hostname | grep UpCrc_errors | awk -F "=" '{print $2}' ; exit 0;; | |
-dfec) $0 -h $hostname | grep Fec_errors | awk -F "=" '{print $2}' ; exit 0;; | |
-ufec) $0 -h $hostname | grep Atuc_fec_errors | awk -F "=" '{print $2}' ; exit 0;; | |
--hostname) echo "$1 requires an argument" >&2; exit 1;; | |
-*) echo "unknown option: $1" >&2; exit 1;; | |
*) echo "unrecognized argument: $1"; exit 1;; | |
esac | |
done | |
if [ -f /tmp/output.modem ]; | |
then | |
FILE_TIME=$(( `date +%s` - `stat -L --format %Y /tmp/output.modem` )) | |
if [[ "$FILE_TIME" -gt 60 ]]; | |
then | |
curl -s http://$hostname/common_page/status_info_lua.lua -o /tmp/output.modem | |
fi | |
else | |
curl -s http://$hostname/common_page/status_info_lua.lua -o /tmp/output.modem | |
fi | |
# Get HTML exctract of the status page. | |
STATUS=$(cat /tmp/output.modem) | |
# Scrape values. | |
Upstream_noise_margin=$(grep -Po "<ParaName>Upstream_noise_margin</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
Upstream_current_rate=$(grep -Po "<ParaName>Upstream_current_rate</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
Downstream_noise_margin=$(grep -Po "<ParaName>Downstream_noise_margin</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
Downstream_current_rate=$(grep -Po "<ParaName>Downstream_current_rate</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
UpCrc_errors=$(grep -Po "<ParaName>UpCrc_errors</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
Downstream_attenuation=$(grep -Po "<ParaName>Downstream_attenuation</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
Fec_errors=$(grep -Po "<ParaName>Fec_errors</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
DownCrc_errors=$(grep -Po "<ParaName>DownCrc_errors</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
Atuc_fec_errors=$(grep -Po "<ParaName>Atuc_fec_errors</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
Upstream_attenuation=$(grep -Po "<ParaName>Upstream_attenuation</ParaName>.*?<ParaValue>\K(.*?)(?=</ParaValue>)" <<< "$STATUS") | |
# Scaling. | |
Upstream_noise_margin=`bc <<<"scale=1; $Upstream_noise_margin / 10"` | |
Downstream_noise_margin=`bc <<<"scale=1; $Downstream_noise_margin / 10"` | |
Downstream_attenuation=`bc <<<"scale=1; $Downstream_attenuation / 10"` | |
Upstream_attenuation=`bc <<<"scale=1; $Upstream_attenuation / 10"` | |
# Checks. | |
critical=0 | |
if [[ -n $downRateC ]] && (( $critical==0 )) ; then | |
critical=$(echo $Downstream_current_rate '<' $downRateC | bc -l) | |
fi | |
if [[ -n $upRateC ]] && (( $critical==0 )) ; then | |
critical=$(echo $Upstream_current_rate '<' $upRateC | bc -l) | |
fi | |
if [[ -n $downAttenuationC ]] && (( $critical==0 )) ; then | |
critical=$(echo $Downstream_attenuation '<' $downAttenuationC | bc -l) | |
fi | |
if [[ -n $upAttenuationC ]] && (( $critical==0 )) ; then | |
critical=$(echo $Upstream_attenuation '<' $upAttenuationC | bc -l) | |
fi | |
warning=0 | |
if (( $critical==0 )); then | |
if [[ -n $downRateW ]] && (( $warning==0 )) ; then | |
warning=$(echo $Downstream_current_rate '<' $downRateW | bc -l) | |
fi | |
if [[ -n $upRateW ]] && (( $warning==0 )) ; then | |
warning=$(echo $Upstream_current_rate '<' $upRateW | bc -l) | |
fi | |
if [[ -n $downAttenuationW ]] && (( $warning==0 )) ; then | |
warning=$(echo $Downstream_attenuation '<' $downAttenuationW | bc -l) | |
fi | |
if [[ -n $upAttenuationW ]] && (( $warning==0 )) ; then | |
warning=$(echo $Upstream_attenuation '<' $upAttenuationW | bc -l) | |
fi | |
fi | |
# Generate output. | |
OUTPUT="OK" | |
if (( $warning==1 )); then | |
OUTPUT="WARNING" | |
fi | |
if (( $critical==1 )); then | |
OUTPUT="CRITICAL" | |
fi | |
echo "Upstream_noise_margin=$Upstream_noise_margin" | |
echo "Downstream_noise_margin=$Downstream_noise_margin" | |
echo "Upstream_current_rate=$Upstream_current_rate" | |
echo "Downstream_current_rate=$Downstream_current_rate" | |
echo "UpCrc_errors=$UpCrc_errors" | |
echo "DownCrc_errors=$DownCrc_errors" | |
echo "Upstream_attenuation=$Upstream_attenuation" | |
echo "Downstream_attenuation=$Downstream_attenuation" | |
echo "Fec_errors=$Fec_errors" | |
echo "Atuc_fec_errors=$Atuc_fec_errors" | |
# Output. | |
echo $OUTPUT | |
# Exit status | |
if (( $warning==1 )); then | |
exit 1 | |
fi | |
if (( $critical==1 )); then | |
exit 2 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment