📜 ⬆️ ⬇️

Transceiver Signal Level via SNMP in Cisco

Sometimes you need to know the signal level in the transceiver. The reasons are different: the sudden drop in the communication channel, the connection of new optical cross connects, monitoring. An engineer with the necessary level of access resolves this issue in less than one minute using the command:

#show interfaces Te1/49 transceiver !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Optical Optical Temperature Voltage Tx Power Rx Power Port (Celsius) (Volts) (dBm) (dBm) --------- ----------- ------- -------- -------- Te1/49 53.3 3.25 -4.3 -2.8 

Someone (who does not have the appropriate access) has to wait this minute for ages. For example, when the channel fell at peak hours and on the backup link there were some losses that only showed up when the link was loaded with traffic. Or when it was necessary to pass the new channel yesterday, but nothing works, because the supplier incorrectly signed the optics on the CWDM multiplexer, and it is required to find the “right wave” using the random method. And all this happens in the conditions of shortage of supreme network engineers and time.

The article discusses the option of how to check the signal, having only read-only access via SNMP. At the same time, it is necessary to wait no more than 10 minutes (the normal period for updating the corresponding variable). Allocating such access seems more secure than logical for a number of employees who, for one reason or another, do not have CCNA or CCNP (monitoring engineers, tellers, technical managers). The same information can be useful when setting up monitoring systems.
')

Given



To find



Decision


First, find the OID you need. It will consist of the ID "entSensorValue" and the "index" of the sensor itself. The latter can be found by running the following request from a host that has access via snmp to a network device with management IP 10.0.7.35:

 $ snmpwalk -v 2c -c community 10.0.7.35 1.3.6.1.2.1.47.1.1.1.1.7 | grep Te1/49 SNMPv2-SMI::mib-2.47.1.1.1.1.7.1107 = STRING: "Te1/49 Module Temperature Sensor" SNMPv2-SMI::mib-2.47.1.1.1.1.7.1157 = STRING: "Te1/49 Supply Voltage Sensor" SNMPv2-SMI::mib-2.47.1.1.1.1.7.1207 = STRING: "Te1/49 Bias Current Sensor" SNMPv2-SMI::mib-2.47.1.1.1.1.7.1257 = STRING: "Te1/49 Transmit Power Sensor" SNMPv2-SMI::mib-2.47.1.1.1.1.7.1307 = STRING: "Te1/49 Receive Power Sensor" 

We use the last number in the OID for "Te1 / 49 Transmit Power Sensor" and "Te1 / 49 Receive Power Sensor". These are respectively 1257 and 1307. Using these numbers, we can immediately obtain the level of the outgoing and incoming optical signal (value):

 $ snmpget -v 2c -c community 10.0.7.35 1.3.6.1.4.1.9.9.91.1.1.1.1.4.1257 SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1257 = INTEGER: -28 $ snmpget -v 2c -c community 10.0.7.35 1.3.6.1.4.1.9.9.91.1.1.1.1.4.1307 SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.4.1307 = INTEGER: -35 

Combining in a similar way “entSensorPrecision” and “index” of the sensor, we find the measurement accuracy (the number of decimal places):

 $ snmpget -v 2c -c community 10.0.7.35 1.3.6.1.4.1.9.9.91.1.1.1.1.3.1257 SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.3.1257 = INTEGER: 1 $ snmpget -v 2c -c community 10.0.7.35 1.3.6.1.4.1.9.9.91.1.1.1.1.3.1307 SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.3.1307 = INTEGER: 1 

The number “1” in this case means that you need to put a comma in front of one number to the right in the meaning of the corresponding sensor.
Te1 / 49 Transmit Power = -2.8
Te1 / 49 Receive Power = -3.5

To determine the units of measure, we use “entSensorType” in combination with the sensor “index”:

 $ snmpget -v 2c -c community 10.0.7.35 1.3.6.1.4.1.9.9.91.1.1.1.1.1.1257 SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.1.1257 = INTEGER: 14 $ snmpget -v 2c -c community 10.0.7.35 1.3.6.1.4.1.9.9.91.1.1.1.1.1.1307 SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.1.1307 = INTEGER: 14 

A value of 14 corresponds to the units of "dBm". The list of values ​​is given in the description of "entSensorType".
Decimal prefix can be added to units of measurement. Which one will show “entSensorScale” :

 $ snmpget -v 2c -c community 10.0.7.35 1.3.6.1.4.1.9.9.91.1.1.1.1.2.1257 SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.2.1257 = INTEGER: 9 $ snmpget -v 2c -c community 10.0.7.35 1.3.6.1.4.1.9.9.91.1.1.1.1.2.1307 SNMPv2-SMI::enterprises.9.9.91.1.1.1.1.2.1307 = INTEGER: 9 

In this case, the prefix "Units" (which corresponds to the number 9) actually means the absence of the prefix.
Thus, we received the signal level of the transceiver installed in the port Te1 / 49, on the switch with IP 10.0.7.35

Te1 / 49 Transmit Power = -2.8 dBm
Te1 / 49 Receive Power = -3.5 dBm

Let's make the answer according to the textbook :

light.bash
 #!/bin/bash E_OPTERROR=65 verbose=0 get_type () { if [ -z "$1" ] # Length of argument is 0? then exit $E_OPTERROR elif [ "$1" -eq "1" ] then truetype=other elif [ "$1" -eq "2" ] then truetype=unknown elif [ "$1" -eq "3" ] then truetype=voltsAC elif [ "$1" -eq "4" ] then truetype=voltsDC elif [ "$1" -eq "5" ] then truetype=amperes elif [ "$1" -eq "6" ] then truetype=watts elif [ "$1" -eq "7" ] then truetype=hertz elif [ "$1" -eq "8" ] then truetype=celsius elif [ "$1" -eq "9" ] then truetype=percentRH elif [ "$1" -eq "10" ] then truetype="rpm" elif [ "$1" -eq "11" ] then truetype=cmm elif [ "$1" -eq "12" ] then truetype=truthvalue elif [ "$1" -eq "13" ] then truetype=specialEnum elif [ "$1" -eq "14" ] then truetype=dBm else echo type=$1,error; exit $E_OPTERROR fi return 0 } get_scale () { if [ -z "$1" ] # Length of argument is 0? then exit $E_OPTERROR elif [ "$1" -eq "1" ] then truescale=yocto elif [ "$1" -eq "2" ] then truescale=zepto elif [ "$1" -eq "3" ] then truescale=atto elif [ "$1" -eq "4" ] then truescale=femto elif [ "$1" -eq "5" ] then truescale=pico elif [ "$1" -eq "6" ] then truescale=nano elif [ "$1" -eq "7" ] then truescale=micro elif [ "$1" -eq "8" ] then truescale=milli elif [ "$1" -eq "9" ] then truescale="" elif [ "$1" -eq "10" ] then truescale=kilo elif [ "$1" -eq "11" ] then truescale=mega elif [ "$1" -eq "12" ] then truescale=giga elif [ "$1" -eq "13" ] then truescale=tera elif [ "$1" -eq "14" ] then truescale=exa elif [ "$1" -eq "15" ] then truescale=peta elif [ "$1" -eq "16" ] then truescale=zetta elif [ "$1" -eq "17" ] then truescale=yotta else echo scale=$1,error; exit $E_OPTERROR fi return 0 } #reading the options while getopts ":c:h:i:v" Option do #echo $OPTIND case $Option in c ) community=$OPTARG;; h ) host=$OPTARG;; i ) interface=$OPTARG;; v ) echo "Verbose mode is set";verbose=1;; * ) echo "Usage: `basename $0` -c community -h host -i interface"; exit $E_OPTERROR;; # default options esac done shift $(($OPTIND - 1)) #moving on to the next provided option if [ -z "$community" ] || [ -z $host ] || [ -z $interface ] # if some of options is not submitted then echo "Usage: `basename $0` -c community -h host -i interface" exit $E_OPTERROR fi if [ $verbose -eq 1 ] then echo "community is \"$community\"" echo "host is \"$host\"" echo "interface is \"$interface\"" fi #looking for the index of sensor if [ $verbose -eq 1 ] then echo "executing \"snmpwalk -v 2c -OX -c $community $host 1.3.6.1.2.1.47.1.1.1.1.7 | grep $interface\"" fi # step1: getiing information about device #snmpwalk -v 2c -OX -c $community $host 1.3.6.1.2.1.47.1.1.1.1.7 | grep $interface > index=0 while read line; do string[$index]="$line" index=$(($index+1)) # done < <(cat tempcache) done < <(snmpwalk -v 2c -OX -c $community $host 1.3.6.1.2.1.47.1.1.1.1.7 | grep $interface) if [ $verbose -eq 1 ] then for ((a=0; a < ${#string[*]}; a++)) do echo "have a string#$a as ${string[$a]}" done fi # step2: parse/cut received strings if [ $verbose -eq 1 ] then echo "parsing/cuting snmpwalk result" fi for ((a=0; a < ${#string[*]}; a++)) do rx_string=`echo ${string[$a]} | grep Receive`; tx_string=`echo ${string[$a]} | grep Transmit`; if [ -n "$rx_string" ] then rx_sensor=`echo ${string[$a]}| cut -d "[" -f2 | cut -d "]" -f1` elif [ -n "$tx_string" ] then tx_sensor=`echo ${string[$a]}| cut -d "[" -f2 | cut -d "]" -f1` fi done if [ $verbose -eq 1 ] then echo "index of rx_sensor parsed to $rx_sensor" echo "index of tx_sensor parsed to $tx_sensor" fi #getting the sensor value if [ $verbose -eq 1 ] then echo "getting the sensor value" fi rx_value=`snmpget -v 2c -c $community $host 1.3.6.1.4.1.9.9.91.1.1.1.1.4.$rx_sensor | grep -o -e "INTEGER: [-+0-9]*" | cut -f2 -d" "` rx_precision=`snmpget -v 2c -c $community $host 1.3.6.1.4.1.9.9.91.1.1.1.1.3.$rx_sensor | grep -o -e "INTEGER: [-+0-9]*" | cut -f2 -d" "` rx_type=`snmpget -v 2c -c $community $host 1.3.6.1.4.1.9.9.91.1.1.1.1.1.$rx_sensor | grep -o -e "INTEGER: [-+0-9]*" | cut -f2 -d" "` get_type $rx_type rx_type=$truetype rx_scale=`snmpget -v 2c -c $community $host 1.3.6.1.4.1.9.9.91.1.1.1.1.2.$rx_sensor | grep -o -e "INTEGER: [-+0-9]*" | cut -f2 -d" "` get_scale $rx_scale rx_scale=$truescale tx_value=`snmpget -v 2c -c $community $host 1.3.6.1.4.1.9.9.91.1.1.1.1.4.$tx_sensor | grep -o -e "INTEGER: [-+0-9]*" | cut -f2 -d" "` tx_precision=`snmpget -v 2c -c $community $host 1.3.6.1.4.1.9.9.91.1.1.1.1.3.$tx_sensor | grep -o -e "INTEGER: [-+0-9]*" | cut -f2 -d" "` tx_type=`snmpget -v 2c -c $community $host 1.3.6.1.4.1.9.9.91.1.1.1.1.1.$tx_sensor | grep -o -e "INTEGER: [-+0-9]*" | cut -f2 -d" "` get_type $tx_type tx_type=$truetype tx_scale=`snmpget -v 2c -c $community $host 1.3.6.1.4.1.9.9.91.1.1.1.1.2.$rx_sensor | grep -o -e "INTEGER: [-+0-9]*" | cut -f2 -d" "` get_scale $tx_scale tx_scale=$truescale let lengthrx=${#rx_value}-$rx_precision let lengthtx=${#tx_value}-$tx_precision echo RX=${rx_value:0:$lengthrx}.${rx_value:$lengthrx} $rx_scale$rx_type echo TX=${tx_value:0:$lengthtx}.${tx_value:$lengthtx} $tx_scale$tx_type exit 0 

Source: https://habr.com/ru/post/260721/


All Articles