From fb7d068c4998312fc90f5d99c92b33937cd44726 Mon Sep 17 00:00:00 2001 From: Finn Andersen Date: Wed, 29 Oct 2014 22:23:03 +0100 Subject: [PATCH 1/5] Made Munin plugin to graph signal levels from a Cisco EPC3010 cable modem --- plugins/modem/cisco-epc3010_ | 187 +++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100755 plugins/modem/cisco-epc3010_ diff --git a/plugins/modem/cisco-epc3010_ b/plugins/modem/cisco-epc3010_ new file mode 100755 index 00000000..6d12694c --- /dev/null +++ b/plugins/modem/cisco-epc3010_ @@ -0,0 +1,187 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=head1 NAME + +epc3010_ - munin-plugin to monitor Upstream/Downstream Power Levels and Signal to Noise Ratio on Cisco EPC3010 EuroDocsis 3.0 Data Modem + +=head1 CONFIGURATION + +This plugin does not require configuration. +Create two links called epc3010_downstream and epc3010_upstream in order to use this script. + +=head1 AUTHOR + +Finn Andersen - xiphias256@gmail.com + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=contrib + #%# capabilities=autoconf + +=cut + +# +############################################### +# +# HISTORY +# v1.0 : Initial release +# +############################################### +# + +# Decide if you want upstream og downstream info +DIRECTION=${0##*epc3010_} + +# Check if argument is autoconfig or config +case "$1" in + +autoconfig) + # Does your network have a Cisco EPC3010? + curl -s http://192.168.100.1/Docsis_system.asp | grep -q "Cisco EPC3010" + if [ $? -eq 0 ]; then + echo "yes" + exit 0 + else + echo "Can't find Cisco EPC3010 modem in your network" + exit 1 + fi + ;; +config) + if [ $DIRECTION == "downstream" ]; then + echo "graph_title Cisco EPC3010 Downstream measurements"; + echo "graph_args -l 0 --base 1000" + echo "graph_category network" + echo "graph_vlabel (-) is Power Level (+) is SNR" + echo "graph_info Downstream Signal to Noise Ratio (dB) and Power Level (dBmV) from Cisco EPC3010 modem. Info is scraped from statuspage on the modem (http://192.168.100.1)" + echo "channel_1_pwr.label Channel 1 (dBmV)" + echo "channel_1_pwr.type GAUGE" + echo "channel_1_pwr.max 50" + echo "channel_2_pwr.label Channel 2 (dBmV)" + echo "channel_2_pwr.type GAUGE" + echo "channel_2_pwr.max 50" + echo "channel_3_pwr.label Channel 3 (dBmV)" + echo "channel_3_pwr.type GAUGE" + echo "channel_3_pwr.max 50" + echo "channel_4_pwr.label Channel 4 (dBmV)" + echo "channel_4_pwr.type GAUGE" + echo "channel_4_pwr.max 50" + echo "channel_5_pwr.label Channel 5 (dBmV)" + echo "channel_5_pwr.type GAUGE" + echo "channel_5_pwr.max 50" + echo "channel_6_pwr.label Channel 6 (dBmV)" + echo "channel_6_pwr.type GAUGE" + echo "channel_6_pwr.max 50" + echo "channel_7_pwr.label Channel 7 (dBmV)" + echo "channel_7_pwr.type GAUGE" + echo "channel_7_pwr.max 50" + echo "channel_8_pwr.label Channel 8 (dBmV)" + echo "channel_8_pwr.type GAUGE" + echo "channel_8_pwr.max 50" + echo "channel_1_snr.label Channel 1 (dB)" + echo "channel_1_snr.type GAUGE" + echo "channel_1_snr.max 50" + echo "channel_2_snr.label Channel 2 (dB)" + echo "channel_2_snr.type GAUGE" + echo "channel_2_snr.max 50" + echo "channel_3_snr.label Channel 3 (dB)" + echo "channel_3_snr.type GAUGE" + echo "channel_3_snr.max 50" + echo "channel_4_snr.label Channel 4 (dB)" + echo "channel_4_snr.type GAUGE" + echo "channel_4_snr.max 50" + echo "channel_5_snr.label Channel 5 (dB)" + echo "channel_5_snr.type GAUGE" + echo "channel_5_snr.max 50" + echo "channel_6_snr.label Channel 6 (dB)" + echo "channel_6_snr.type GAUGE" + echo "channel_6_snr.max 50" + echo "channel_7_snr.label Channel 7 (dB)" + echo "channel_7_snr.type GAUGE" + echo "channel_7_snr.max 50" + echo "channel_8_snr.label Channel 8 (dB)" + echo "channel_8_snr.type GAUGE" + echo "channel_8_snr.max 50" + exit 0 + fi + if [ "$DIRECTION" == "upstream" ]; then + echo "graph_title Cisco EPC3010 Upstream measurements"; + echo "graph_args -l 30 --base 1000" + echo "graph_category network" + echo "graph_vlabel Powerlevvel in dBmV" + echo "graph_info Upstream Power Levels from Cisco EPC3010 modem,scraped from it's statuspage (http://192.168.100.1)" + echo "channel_1_pwr.label Channel 1 (dBmV)" + echo "channel_1_pwr.type GAUGE" + echo "channel_1_pwr.max 60" + echo "channel_2_pwr.label Channel 2 (dBmV)" + echo "channel_2_pwr.type GAUGE" + echo "channel_2_pwr.max 60" + echo "channel_3_pwr.label Channel 3 (dBmV)" + echo "channel_3_pwr.type GAUGE" + echo "channel_3_pwr.max 60" + echo "channel_4_pwr.label Channel 4 (dBmV)" + echo "channel_4_pwr.type GAUGE" + echo "channel_4_pwr.max 60" + exit 0 + fi + ;; +esac + + +# Location and name of tempfile to parse +FILENAME=/tmp/cisco_epc3010.dump + + +# Get statuspage from the modem +curl -s -o $FILENAME http://192.168.100.1/Docsis_system.asp + + +# Bash arrays starts on index 0, we 0-pad the first index. It makes it easier later on.. +SNR_ARRAY=( 0 $(cat $FILENAME | grep " ch_snr" | awk -F "nowrap>| | | Date: Thu, 30 Oct 2014 09:42:28 +0100 Subject: [PATCH 2/5] Fixed some typo in text --- plugins/modem/cisco-epc3010_ | 128 +++++++++++++++-------------------- 1 file changed, 56 insertions(+), 72 deletions(-) diff --git a/plugins/modem/cisco-epc3010_ b/plugins/modem/cisco-epc3010_ index 6d12694c..c0e00d32 100755 --- a/plugins/modem/cisco-epc3010_ +++ b/plugins/modem/cisco-epc3010_ @@ -31,7 +31,7 @@ GPLv2 ############################################### # # HISTORY -# v1.0 : Initial release +# v1.0 : Initial release # ############################################### # @@ -55,79 +55,59 @@ autoconfig) ;; config) if [ $DIRECTION == "downstream" ]; then - echo "graph_title Cisco EPC3010 Downstream measurements"; - echo "graph_args -l 0 --base 1000" - echo "graph_category network" - echo "graph_vlabel (-) is Power Level (+) is SNR" - echo "graph_info Downstream Signal to Noise Ratio (dB) and Power Level (dBmV) from Cisco EPC3010 modem. Info is scraped from statuspage on the modem (http://192.168.100.1)" - echo "channel_1_pwr.label Channel 1 (dBmV)" - echo "channel_1_pwr.type GAUGE" - echo "channel_1_pwr.max 50" - echo "channel_2_pwr.label Channel 2 (dBmV)" - echo "channel_2_pwr.type GAUGE" - echo "channel_2_pwr.max 50" - echo "channel_3_pwr.label Channel 3 (dBmV)" - echo "channel_3_pwr.type GAUGE" - echo "channel_3_pwr.max 50" - echo "channel_4_pwr.label Channel 4 (dBmV)" - echo "channel_4_pwr.type GAUGE" - echo "channel_4_pwr.max 50" - echo "channel_5_pwr.label Channel 5 (dBmV)" - echo "channel_5_pwr.type GAUGE" - echo "channel_5_pwr.max 50" - echo "channel_6_pwr.label Channel 6 (dBmV)" - echo "channel_6_pwr.type GAUGE" - echo "channel_6_pwr.max 50" - echo "channel_7_pwr.label Channel 7 (dBmV)" - echo "channel_7_pwr.type GAUGE" - echo "channel_7_pwr.max 50" - echo "channel_8_pwr.label Channel 8 (dBmV)" - echo "channel_8_pwr.type GAUGE" - echo "channel_8_pwr.max 50" - echo "channel_1_snr.label Channel 1 (dB)" - echo "channel_1_snr.type GAUGE" - echo "channel_1_snr.max 50" - echo "channel_2_snr.label Channel 2 (dB)" - echo "channel_2_snr.type GAUGE" - echo "channel_2_snr.max 50" - echo "channel_3_snr.label Channel 3 (dB)" - echo "channel_3_snr.type GAUGE" - echo "channel_3_snr.max 50" - echo "channel_4_snr.label Channel 4 (dB)" - echo "channel_4_snr.type GAUGE" - echo "channel_4_snr.max 50" - echo "channel_5_snr.label Channel 5 (dB)" - echo "channel_5_snr.type GAUGE" - echo "channel_5_snr.max 50" - echo "channel_6_snr.label Channel 6 (dB)" - echo "channel_6_snr.type GAUGE" - echo "channel_6_snr.max 50" - echo "channel_7_snr.label Channel 7 (dB)" - echo "channel_7_snr.type GAUGE" - echo "channel_7_snr.max 50" - echo "channel_8_snr.label Channel 8 (dB)" - echo "channel_8_snr.type GAUGE" - echo "channel_8_snr.max 50" + printf "graph_title Cisco EPC3010 Downstream measurements\n"; + printf "graph_args -l 0 --base 1000\n" + printf "graph_category other\n" + printf "graph_vlabel Small number is Power Level, large number is SNR\n" + printf "graph_info Downstream Signal to Noise Ratio (dB) and Power Level (dBmV) from Cisco EPC3010 modem. Info is scraped from statuspage on the modem (http://192.168.100.1)\n" + printf "channel_1_pwr.label Channel 1 (dBmV)\n" + printf "channel_1_pwr.type GAUGE\n" + printf "channel_2_pwr.label Channel 2 (dBmV)\n" + printf "channel_2_pwr.type GAUGE\n" + printf "channel_3_pwr.label Channel 3 (dBmV)\n" + printf "channel_3_pwr.type GAUGE\n" + printf "channel_4_pwr.label Channel 4 (dBmV)\n" + printf "channel_4_pwr.type GAUGE\n" + printf "channel_5_pwr.label Channel 5 (dBmV)\n" + printf "channel_5_pwr.type GAUGE\n" + printf "channel_6_pwr.label Channel 6 (dBmV)\n" + printf "channel_6_pwr.type GAUGE\n" + printf "channel_7_pwr.label Channel 7 (dBmV)\n" + printf "channel_7_pwr.type GAUGE\n" + printf "channel_8_pwr.label Channel 8 (dBmV)\n" + printf "channel_8_pwr.type GAUGE\n" + printf "channel_1_snr.label Channel 1 (dB)\n" + printf "channel_1_snr.type GAUGE\n" + printf "channel_2_snr.label Channel 2 (dB)\n" + printf "channel_2_snr.type GAUGE\n" + printf "channel_3_snr.label Channel 3 (dB)\n" + printf "channel_3_snr.type GAUGE\n" + printf "channel_4_snr.label Channel 4 (dB)\n" + printf "channel_4_snr.type GAUGE\n" + printf "channel_5_snr.label Channel 5 (dB)\n" + printf "channel_5_snr.type GAUGE\n" + printf "channel_6_snr.label Channel 6 (dB)\n" + printf "channel_6_snr.type GAUGE\n" + printf "channel_7_snr.label Channel 7 (dB)\n" + printf "channel_7_snr.type GAUGE\n" + printf "channel_8_snr.label Channel 8 (dB)\n" + printf "channel_8_snr.type GAUGE\n" exit 0 fi if [ "$DIRECTION" == "upstream" ]; then - echo "graph_title Cisco EPC3010 Upstream measurements"; - echo "graph_args -l 30 --base 1000" - echo "graph_category network" - echo "graph_vlabel Powerlevvel in dBmV" - echo "graph_info Upstream Power Levels from Cisco EPC3010 modem,scraped from it's statuspage (http://192.168.100.1)" - echo "channel_1_pwr.label Channel 1 (dBmV)" - echo "channel_1_pwr.type GAUGE" - echo "channel_1_pwr.max 60" - echo "channel_2_pwr.label Channel 2 (dBmV)" - echo "channel_2_pwr.type GAUGE" - echo "channel_2_pwr.max 60" - echo "channel_3_pwr.label Channel 3 (dBmV)" - echo "channel_3_pwr.type GAUGE" - echo "channel_3_pwr.max 60" - echo "channel_4_pwr.label Channel 4 (dBmV)" - echo "channel_4_pwr.type GAUGE" - echo "channel_4_pwr.max 60" + printf "graph_title Cisco EPC3010 Upstream measurements\n" + printf "graph_args -l 30 --base 1000\n" + printf "graph_category other\n" + printf "graph_vlabel Power level in dBmV\n" + printf "graph_info Upstream Power Levels from Cisco EPC3010 modem,scraped from its statuspage (http://192.168.100.1)\n" + printf "channel_1_pwr.label Channel 1 (dBmV)\n" + printf "channel_1_pwr.type GAUGE\n" + printf "channel_2_pwr.label Channel 2 (dBmV)\n" + printf "channel_2_pwr.type GAUGE\n" + printf "channel_3_pwr.label Channel 3 (dBmV)\n" + printf "channel_3_pwr.type GAUGE\n" + printf "channel_4_pwr.label Channel 4 (dBmV)\n" + printf "channel_4_pwr.type GAUGE\n" exit 0 fi ;; @@ -184,4 +164,8 @@ if [ "$DIRECTION" == "upstream" ]; then exit 0 fi -# rm -f $FILENAME + +# +# Remove tempory file, used for parsing data +# +rm -f $FILENAME From 771fb2dd72472581e5101343e5e649e79487325f Mon Sep 17 00:00:00 2001 From: Finn Andersen Date: Thu, 30 Oct 2014 09:56:25 +0100 Subject: [PATCH 3/5] Changed to a more secure way of handling tempfiles --- plugins/modem/cisco-epc3010_ | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/modem/cisco-epc3010_ b/plugins/modem/cisco-epc3010_ index c0e00d32..7cdf846b 100755 --- a/plugins/modem/cisco-epc3010_ +++ b/plugins/modem/cisco-epc3010_ @@ -32,6 +32,7 @@ GPLv2 # # HISTORY # v1.0 : Initial release +# 1.0.1 : More secure handling of tempfiles # ############################################### # @@ -115,7 +116,7 @@ esac # Location and name of tempfile to parse -FILENAME=/tmp/cisco_epc3010.dump +FILENAME=$(mktemp /tmp/cisco_epc3010-XXXX.dump) || exit 1 # Get statuspage from the modem @@ -130,7 +131,7 @@ UP_PWR_ARRAY=( 0 $(cat $FILENAME | grep " up_pwr" | awk -F "nowrap>| Date: Thu, 30 Oct 2014 13:33:49 +0100 Subject: [PATCH 4/5] Simplified parsing of the html table. Everything is done with awk. Got rid of cat and grep --- plugins/modem/cisco-epc3010_ | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modem/cisco-epc3010_ b/plugins/modem/cisco-epc3010_ index 7cdf846b..58e7565f 100755 --- a/plugins/modem/cisco-epc3010_ +++ b/plugins/modem/cisco-epc3010_ @@ -124,9 +124,9 @@ curl -s -o $FILENAME http://192.168.100.1/Docsis_system.asp # Bash arrays starts on index 0, we 0-pad the first index. It makes it easier later on.. -SNR_ARRAY=( 0 $(cat $FILENAME | grep " ch_snr" | awk -F "nowrap>| | | ]' '/ ch_snr/{print $3}' $FILENAME) ) +PWR_ARRAY=( 0 $(awk -F'[<>]' '/ ch_pwr/{print $3}' $FILENAME) ) +UP_PWR_ARRAY=( 0 $(awk -F'[<>]' '/ up_pwr/{print $3}' $FILENAME) ) From 678fb563f1a18446c51755f64690be5c8bab24ea Mon Sep 17 00:00:00 2001 From: Finn Andersen Date: Sat, 1 Nov 2014 22:06:51 +0100 Subject: [PATCH 5/5] Changed how tempory filename is created and handled. Now follows example in mktemp documentation. --- plugins/modem/cisco-epc3010_ | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/plugins/modem/cisco-epc3010_ b/plugins/modem/cisco-epc3010_ index 58e7565f..d5f18c03 100755 --- a/plugins/modem/cisco-epc3010_ +++ b/plugins/modem/cisco-epc3010_ @@ -115,19 +115,21 @@ config) esac -# Location and name of tempfile to parse -FILENAME=$(mktemp /tmp/cisco_epc3010-XXXX.dump) || exit 1 +FILENAME=$(mktemp -q) && { + # Safe to use $FILENAME only within this block. Use quotes, + # since $TMPDIR, and thus $FILENAME, may contain whitespace. + + # Get statuspage from the modem + curl -s -o $FILENAME http://192.168.100.1/Docsis_system.asp -# Get statuspage from the modem -curl -s -o $FILENAME http://192.168.100.1/Docsis_system.asp - - -# Bash arrays starts on index 0, we 0-pad the first index. It makes it easier later on.. -SNR_ARRAY=( 0 $(awk -F'[<>]' '/ ch_snr/{print $3}' $FILENAME) ) -PWR_ARRAY=( 0 $(awk -F'[<>]' '/ ch_pwr/{print $3}' $FILENAME) ) -UP_PWR_ARRAY=( 0 $(awk -F'[<>]' '/ up_pwr/{print $3}' $FILENAME) ) + # Bash arrays starts on index 0, we 0-pad the first index. It makes it easier later on.. + SNR_ARRAY=( 0 $(awk -F'[<>]' '/ ch_snr/{print $3}' $FILENAME) ) + PWR_ARRAY=( 0 $(awk -F'[<>]' '/ ch_pwr/{print $3}' $FILENAME) ) + UP_PWR_ARRAY=( 0 $(awk -F'[<>]' '/ up_pwr/{print $3}' $FILENAME) ) + rm -f "$FILENAME" +} # @@ -138,7 +140,7 @@ if [ "$DIRECTION" == "downstream" ]; then total=${#PWR_ARRAY[*]} for (( index=1; index<$(( $total )); index++ )) do - printf "channel_%d_pwr.value %s\n" $index ${PWR_ARRAY[$index]} + printf "channel_%d_pwr.value %s\n" $index ${PWR_ARRAY[$index]} done total=${#SNR_ARRAY[*]} @@ -146,12 +148,10 @@ if [ "$DIRECTION" == "downstream" ]; then do printf "channel_%d_snr.value %s\n" $index ${SNR_ARRAY[$index]} done - exit 0 fi - # # Upstream info - Modem outputs Power Levels # @@ -160,15 +160,7 @@ if [ "$DIRECTION" == "upstream" ]; then total=${#UP_PWR_ARRAY[*]} for (( index=1; index<$(( $total )); index++ )) do - printf "channel_%d_pwr.value %s\n" $index ${UP_PWR_ARRAY[$index]} + printf "channel_%d_pwr.value %s\n" $index ${UP_PWR_ARRAY[$index]} done exit 0 fi - - -# -# Remove tempory file, used for parsing data -# -trap "rm -rf $FILENAME" EXIT - -