Add temperature and fan data to SNMP -> EdgeRouter

While playing with Librenms and EdgeRouter Infinity i found out that temperature and fan is missing from SNMP. Found that somebody did it manually but for USG PRO and i did it for Ubiquiti EdgeRouter Infinity 2.0.8 version.

We are going to use the same concept.
Step1: ssh to your EdgeRouter. You can use Filezilla or putty. Default user/pass: ubnt/ubnt.
Step2: sudo -i (to become root)
Step3: create scripts for monitoring and checking fan and temperature. We have 5 sensors for temperature and 2 for fan.

unbt@rtr:~$ show hardware temperature
Temperature:
CPU:63.00 C
Board 1:44.00 C
Board 2:49.25 C
PHY 1:74.06 C
PHY 2:76.10 C
unbt@rtr:~$ show hardware fan
FAN 1: 3708 RPM
FAN 2: 3696 RPM

Now as you are root. Just cd to /config/scripts/. Using nano create files.

So we are going to have one file for every sensor, very similar between them, we only modify how to read every sensor.
File 1 -> cpuTemp. CPU Temperature.

!/bin/sh
if [ $# != 2 ] ; then
echo "Usage: $0 [-g|-n] OID"
exit 0
fi
TEMP=sudo /usr/sbin/ubnt-hal getTemp | grep CPU | awk -F ':' '{print $2}' | sed 's/C//g'
echo $2
echo integer
echo $TEMP

File2. -> board1Temp. Board 1 Temperature.

!/bin/sh
if [ $# != 2 ] ; then
echo "Usage: $0 [-g|-n] OID"
exit 0
fi
TEMP=sudo /usr/sbin/ubnt-hal getTemp | grep "Board 1" | awk -F ':' '{print $2}' | sed 's/C//g'
echo $2
echo integer
echo $TEMP

File3. -> board2Temp. Board 2 Temperature.

 !/bin/sh
if [ $# != 2 ] ; then
echo "Usage: $0 [-g|-n] OID"
exit 0
fi
TEMP=sudo /usr/sbin/ubnt-hal getTemp | grep "Board 2" | awk -F ':' '{print $2}' | sed 's/C//g'
echo $2
echo unsigned32
echo $TEMP

File4. -> phy1Temp. PHY 1 Temperature.

!/bin/sh
if [ $# != 2 ] ; then
echo "Usage: $0 [-g|-n] OID"
exit 0
fi
TEMP=sudo /usr/sbin/ubnt-hal getTemp | grep "PHY 1" | awk -F ':' '{print $2}' | sed 's/C//g'
echo $2
echo unsigned32
echo $TEMP

File5. -> phy2Temp. PHY 2 Temperature.

!/bin/sh
if [ $# != 2 ] ; then
echo "Usage: $0 [-g|-n] OID"
exit 0
fi
TEMP=sudo /usr/sbin/ubnt-hal getTemp | grep "PHY 1" | awk -F ':' '{print $2}' | sed 's/C//g'
echo $2
echo integer
echo $TEMP

File6. -> fan1Temp. FAN 1 Temperature.

!/bin/sh
if [ $# != 2 ] ; then
echo "Usage: $0 [-g|-n] OID"
exit 0
fi
TEMP=sudo /usr/sbin/ubnt-hal getFanTach | grep "FAN 1" | awk -F ':' '{print $2}' | sed 's/RPM//g'
echo $2
echo unsigned32
echo $TEMP

File7. -> fan2Temp. FAN 2 Temperature.

  !/bin/sh
if [ $# != 2 ] ; then
echo "Usage: $0 [-g|-n] OID"
exit 0
fi
TEMP=sudo /usr/sbin/ubnt-hal getFanTach | grep "FAN 2" | awk -F ':' '{print $2}' | sed 's/RPM//g'
echo $2
echo unsigned32
echo $TEMP

Step4. Modify permisions

 chown root:root /config/scripts/cpuTemp
chown root:root /config/scripts/board1Temp
chown root:root /config/scripts/board2Temp
chown root:root /config/scripts/phy1Temp
chown root:root /config/scripts/phy2Temp
chown root:root /config/scripts/fan1Temp
chown root:root /config/scripts/fan2Temp
chmod 755 /config/scripts/cpuTemp
chmod 755 /config/scripts/board1Temp
chmod 755 /config/scripts/board2Temp
chmod 755 /config/scripts/phy1Temp
chmod 755 /config/scripts/phy2Temp
chmod 755 /config/scripts/fan1Temp
chmod 755 /config/scripts/fan2Temp

Step5. Allow user Debian-snmp to get data using ubnt-hal. Permission again.

echo "Debian-snmp     ALL = NOPASSWD: /usr/sbin/ubnt-hal" >> /etc/sudoers

Step6. Configure SNMPD to collect temperature data every time when SNMP is polled.

 echo "pass .1.3.6.1.4.1.4413.1.1.43.1.8.1.5.1.0 /config/scripts/cpuTemp" >> /etc/snmp/snmpd.conf
echo "pass .1.3.6.1.4.1.4413.1.1.43.1.15.1.1 /config/scripts/board1Temp" >> /etc/snmp/snmpd.conf
echo "pass .1.3.6.1.4.1.4413.1.1.43.1.15.1.2 /config/scripts/board2Temp" >> /etc/snmp/snmpd.conf
echo "pass .1.3.6.1.4.1.4413.1.1.43.1.15.1.3 /config/scripts/phy1Temp" >> /etc/snmp/snmpd.conf
echo "pass .1.3.6.1.4.1.41112.1.4.8.4 /config/scripts/phy2Temp" >> /etc/snmp/snmpd.conf
echo "pass .1.3.6.1.4.1.4413.1.1.43.1.6.1.4 /config/scripts/fan1Temp" >> /etc/snmp/snmpd.conf
echo "pass .1.3.6.1.4.1.4413.1.1.43.1.6.1.5 /config/scripts/fan2Temp" >> /etc/snmp/snmpd.conf

Step7. Restart SNMPD application.

/etc/init.d/snmpd restart

I used SNMP OID’s from EdgeSwitch and AirMAX from Ubiquiti. Just to be on the same side…
Currently i’m working on a fix on Librenms that will be update there. This is how it looks like now.

Bonus. Inside info from Librenms configuration. -> edgeos.yaml

mib: EdgeSwitch-BOXSERVICES-PRIVATE-MIB:UBNT-AirMAX-MIB
modules:
sensors:
state:
fanspeed:
data:
-
oid: boxServicesFansEntry
value: boxServicesFanSpeed
num_oid: '.1.3.6.1.4.1.4413.1.1.43.1.6.1.4'
index: '.1.3.6.1.4.1.4413.1.1.43.1.6.1.4'
descr: 'Fan 1'
-
oid: boxServicesFanDutyLevel
num_oid: '.1.3.6.1.4.1.4413.1.1.43.1.6.1.5'
index: '.1.3.6.1.4.1.4413.1.1.43.1.6.1.5'
descr: 'Fan 2'
temperature:
data:
-
oid: boxServicesTempSensorsEntry
value: boxServicesTempSensorTemperature
num_oid: '.1.3.6.1.4.1.4413.1.1.43.1.8.1.5.1.0'
index: 'boxServicesTempSensorTemperature.0'
descr: 'CPU Temperature'
-
oid: boxServicesTempUnitState
num_oid: '.1.3.6.1.4.1.4413.1.1.43.1.15.1.2'
index: '.1.3.6.1.4.1.4413.1.1.43.1.15.1.2'
descr: 'Board 2 Temperature'
-
oid: boxServicesTempUnitIndex
num_oid: '.1.3.6.1.4.1.4413.1.1.43.1.15.1.3'
index: '.1.3.6.1.4.1.4413.1.1.43.1.15.1.3'
descr: 'PHY 1 Temperature'
-
oid: ubntHostTemperature
num_oid: '.1.3.6.1.4.1.41112.1.4.8.4'
index: '.1.3.6.1.4.1.41112.1.4.8.4'
descr: 'PHY 2 Temperature'
-
oid: boxServicesTempUnitIndex
num_oid: '.1.3.6.1.4.1.4413.1.1.43.1.15.1.1'
index: '.1.3.6.1.4.1.4413.1.1.43.1.15.1.1'
descr: 'Board 1 Temperature'

Leave a reply:

Your email address will not be published.

Site Footer