DNS 323 - Funplug 0.7 : Supervise Fan Speed and Case & HDD temperature with SNMP

Contents[Hide]

dropcap-dns323-snmpWhen you run Net-SNMP on your DNS-323, you must have realised that standard SNMP MIBs are not providing a way to supervise your NAS temperature sensors (internal case & hard disk).

Thanks to the open nature of Net-SNMP project, it is possible to extend the Net-SNMP MIBs thru simple shell scripts.

The principle is quite simple :

  • Some new MIBs are declared to SNMP daemon with associated shell scripts
  • SNMP daemon publishes these new MIBs with the standard ones
  • When the MIB is called, SNMP daemon triggers the associated shell scripts to read the sensor values

With this approach, it becomes quite simple to publish DNS-323 fan speed and temperature sensors MIB.

This article explains how to setup your DNS-323 SNMP deamon so that it publishes some extended MIBs to read fan speed and internal case & disks temperature thru their respective sensors.

This will allow you to supervise your DNS-323 temperature levels thru SNMP with supervision softwares like Nagios, Munin, ... A Munin node example under Debian is also provided in this article.

A pre-requisite is to have have fully prepared your DNS-323 with fun_plug 0.7 and adds-on , with a complete compilation environment and Net-SNMP installation.

First step is to extend your DNS-323 possibilities to handle some new MIBs dedicated to collect :

  • fan speed
  • case temperature
  • hdd temperature

1.  Compile SmartCtl

smartctl tool will be used to read hard disk temperature.

As this tool is not available in the DNS-323 repositories, we'll first need to compile it.

# wget http://downloads.sourceforge.net/project/smartmontools/smartmontools/6.2/smartmontools-6.2.tar.gz
# tar -zxvf smartmontools-6.2.tar.gz
# cd smartmontools-6.2
# autoreconf -i
# ./configure --prefix=/ffp
# make
# make install

smartctl is now installed and operational. You can read your disk characteristics.

# smartctl --device=marvell -a /dev/sda
smartctl 6.2 2013-07-26 r3841 [armv5tejl-linux-2.6.12.6-arm1] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===

Model Family: SAMSUNG SpinPoint F2 EG
Device Model: SAMSUNG HD154UI
...
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===

SMART overall-health self-assessment test result: PASSED

General SMART Values:

Offline data collection status: (0x00) Offline data collection activity
was never started.
...

SMART Attributes Data Structure revision number: 16

Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
...
190 Airflow_Temperature_Cel 0x0022 069 063 000 Old_age Always - 31 (Min/Max 29/31)
194 Temperature_Celsius 0x0022 069 062 000 Old_age Always - 31 (Min/Max 29/33)
...

2. Acquisition of Fan Speed

2.1. Case Fan Control

The fan embedded in the DNS-323 can run at 3 different speeds :

  • stop
  • low
  • high

Fan speed can be controled in 2 ways :

  • by fan_control daemon
  • by fanspeed command

fanspeed command can be used to set fan speed or to read its state.
When reading fan state, it only indicates if it is still or if it rotates.

# fanspeed s
Stop fan
# fanspeed g
0
# fanspeed l
Set fan to low speed
# fanspeed g
1
# fanspeed h
Set fan to high speed
# fanspeed g
1

So we are able to know if case fan rotates, but we can not define it it is running low or high speed.

2.2. Script to Read Fan Speed

With the help of fanspeed utility, we can easily write a script that will be called by Net-SNMP to read actual fan speed.

This script will simply get fan speed state with fanspeed command and if fan is rotating.

/ffp/bin/snmp-fanspeed

#!/ffp/bin/sh
# ----------------------------------------------
# Retrieve dns-323 fan status
#
# Used by http://bernaerts.dyndns.org/nas/...
#
# Parameters : none
#
# Return : stop or rotate
#
# 24/07/2014, V1.0 - Creation by N. Bernaerts
# ----------------------------------------------

# retrieve fan status from fanspeed command
FAN_SPEED=`fanspeed g`

# display status
[ "$FAN_SPEED" = "0" ] && echo "stop" || echo "rotate"

# end
exit 0

To install and test it just run these commands :

# wget --no-check-certificate -O /ffp/bin/snmp-fanspeed https://raw.githubusercontent.com/NicolasBernaerts/dns323-scripts/master/snmp/snmp-fanspeed
# chmod +x /ffp/bin/snmp-fanspeed
# snmp-fanspeed
rotate

3. Acquisition of Case and Disk Temperature

This script will be called by Net-SNMP to read the DNS-323 temperature sensors.

It takes the sensor as an argument :

  • internal : internal case temperature
  • disk1 : first disk temperature
  • disk2 : second disk temperature

For case temperature sensor, it uses temperature command.

# temperature g 0
Temperature type : Fahrenheit
<temperaturertc> : get temperature = 102

For disk temperature sensors, it uses smartctl tool.

# smartctl --device=marvell -a /dev/sda
smartctl 6.2 2013-07-26 r3841 [armv5tejl-linux-2.6.12.6-arm1] (local build)
...
194 Temperature_Celsius 0x0022 069 062 000 Old_age Always - 31 (Min/Max 29/33)
...

Script should be created under /ffp/bin/snmp-temperature

/ffp/bin/snmp-temperature

#!/ffp/bin/bash
# ----------------------------------------------
# Retrieve dns-323 temperature sensor values for internal, disk1 and disk2
#
# Used by http://bernaerts.dyndns.org/nas/72-dns323-ffp07/318-dns323-ffp7-snmp-supervise-temperature-case-hdd
#
# Depends on compilation of smartmontools
#
# Parameters :
#   $1 - sensor type (internal, disk1 or disk2)
#
# 24/07/2014, V1.0 - Creation by N. Bernaerts
# 29/07/2014, V1.1 - Handle Fahrenheit & celcius case temperature
# ----------------------------------------------

# set linefeed separator
IFS='
'

# read temperature for $1
case $1 in
  # read case internal temperature
  internal)
    # read temperature
    ARR_TEMP=(`temperature g 0`)
    FAHRENHEIT=`echo ${ARR_TEMP[0]} | grep Fahrenheit`
    RESULT=`echo ${ARR_TEMP[1]} | sed 's/^.* = \([0-9]*\).*$/\1/g'`
    
    # if result is in Farenheit, convert it to celcius
    if [ "$RESULT" != "" ]; then
      RESULT=`expr $RESULT - 32`
      RESULT=`expr $RESULT \* 5 / 9`
    fi
    
    # display temperature in celcius
    echo $RESULT
    ;;

  # read disk1 (/dev/sda) temperature
  disk1)
    RESULT=`smartctl -A --device=marvell /dev/sda | grep "^194.*" | sed 's/^.*- *\([0-9]*\).*$/\1/g'`
    [ "$RESULT" = "" ] && echo "U" || echo $RESULT
    ;;

  # read disk2 (/dev/sdb) temperature
  disk2)
    RESULT=`smartctl -A --device=marvell /dev/sdb | grep "^194.*" | sed 's/^.*- *\([0-9]*\).*$/\1/g'`
    [ "$RESULT" = "" ] && echo "U" || echo $RESULT
    ;;

  # default : nothing to do
  *)
esac

# end
exit 0

To install and test it you just need to throw these commands :

# wget --no-check-certificate -O /ffp/bin/snmp-temperature https://raw.githubusercontent.com/NicolasBernaerts/dns323-scripts/master/snmp/snmp-temperature
# chmod +x /ffp/bin/snmp-temperature
# snmp-temperature disk1
30
# snmp-temperature disk2
U
# snmp-temperature internal
38

4. Acquisition of Disk Details

This script will be called by Net-SNMP to provide some details about both the disks.

These details (disk model, serial number and total capacity) will help to localize the disk in case of problem.

It takes the disk as an argument :

  • disk1 : details about first disk
  • disk2 : details about second disk

Script should be created under /ffp/bin/snmp-diskinfo

/ffp/bin/snmp-diskinfo

#!/ffp/bin/sh
# ----------------------------------------------
# Retrieve dns-325 & dns-323 disk information
#
# Used by http://bernaerts.dyndns.org/nas/71-dns325-ffp07/314-dns325-ffp7-snmp-supervise-temperature-case-hdd
#     and http://bernaerts.dyndns.org/nas/72-dns323-ffp07/318-dns323-ffp7-snmp-supervise-temperature-case-hdd
#
# Depends on packages : 
#   * smartmontools
#
# Parameters : 
#   $1 - disk reference (disk1 or disk2)
#
# 05/07/2014, V1.0 - Creation by N. Bernaerts 
# 24/07/2014, V1.1 - DNS-323 compatibility & one disk only configuration
# ----------------------------------------------

# select device according to parameter
[ "$1" = "disk1" ] && DISK="/dev/sda"
[ "$1" = "disk2" ] && DISK="/dev/sdb"

# get disk information thru smartctl
DISK_MODEL=$(smartctl -i --device=marvell $DISK | grep "^Device Model" | sed 's/^.*:[ ]*\(.*\)$/\1/')
DISK_SERIAL=$(smartctl -i --device=marvell $DISK | grep "^Serial Number" | sed 's/^.*:[ ]*\(.*\)$/\1/')
DISK_SIZE=$(smartctl -i --device=marvell $DISK | grep "^User Capacity" | sed 's/^.*:[ ]*\(.*\)$/\1/')

# generate information string
[ "$DISK_SIZE" = "" ] && DISK_INFO="No disk" || DISK_INFO="Model $DISK_MODEL, S/n $DISK_SERIAL, Capacity $DISK_SIZE"

# print result
echo "$DISK_INFO"

# end
exit 0

To install and test it you just need to throw these commands :

# wget --no-check-certificate -O /ffp/bin/snmp-diskinfo https://raw.githubusercontent.com/NicolasBernaerts/dns325-scripts/master/snmp/snmp-diskinfo
# chmod +x /ffp/bin/snmp-diskinfo
# snmp-diskinfo disk1
Model SAMSUNG HD154UI, S/n 61833B761A0D2W, Capacity 1,500,301,910,016 bytes [1.50 TB]

5. Extend Net-SNMP

Next, you need to edit /ffp/etc/snmpd.conf to declare the new sensor values and associate them with previous scripts :

  • snmp-fanspeed
  • snmp-temperature
  • snmp-diskinfo

/ffp/etc/snmpd.conf

...

extend  speed_fan              /ffp/bin/snmp-fanspeed
extend  temperature_internal   /ffp/bin/snmp-temperature  internal
extend  temperature_disk1      /ffp/bin/snmp-temperature  disk1
extend  temperature_disk2      /ffp/bin/snmp-temperature  disk2
extend  information_disk1      /ffp/bin/snmp-diskinfo     disk1
extend  information_disk2      /ffp/bin/snmp-diskinfo     disk2

Once done, last operation on the DNS-323 is to restart Net-SNMP daemon.

# /ffp/start/snmpd.sh restart

Your DNS-323 is now serving the fan speed, the 3 temperature levels and your disk details thru SNMP.

5.1. Get numerical OID of new MIBs

Before dealing with the server plugin installation, we have to get the numerical OID of our newly created MIBs.

This step is compulsory as Munin asks for SNMP capabilities using MIB numerical OID only.

To retrieve the numerical index, we will simply use snmpget tool with -One option.

# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"speed_fan\"
.1.3.6.1.4.1.8072.1.3.2.3.1.2.9.115.112.101.101.100.95.102.97.110 = STRING: 24
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"temperature_internal\"
.1.3.6.1.4.1.8072.1.3.2.3.1.2.20.116.101.109.112.101.114.97.116.117.114.101.95.105.110.116.101.114.110.97.108 = STRING: 40
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"temperature_disk1\"
.1.3.6.1.4.1.8072.1.3.2.3.1.2.17.116.101.109.112.101.114.97.116.117.114.101.95.100.105.115.107.49 = STRING: 39
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"temperature_disk2\"
.1.3.6.1.4.1.8072.1.3.2.3.1.2.17.116.101.109.112.101.114.97.116.117.114.101.95.100.105.115.107.50 = STRING: U
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"information_disk1\"
.1.3.6.1.4.1.8072.1.3.2.3.1.2.17.105.110.102.111.114.109.97.116.105.111.110.95.100.105.115.107.49 = STRING: Model SAMSUNG HD154UI, s/n 61833B761A0D2W, Capacity 1,500,301,910,016 bytes [1.50 TB]
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"information_disk2\"
.1.3.6.1.4.1.8072.1.3.2.3.1.2.17.105.110.102.111.114.109.97.116.105.111.110.95.100.105.115.107.50 = STRING: No disk

We can clearly read the numerical index for all the three temperature MIB.

These index will be used by next example of Munin plugin.

6. Munin - DNS-323 Temperature Plugin

Here is an example of a Munin plugin in charge of reading these new temperature SNMP MIBs served by your DNS-323.

Reading further suppose that you are already confortable with munin SNMP devices configuration.

All following commands have to be issued from the Munin master server.

6.1. Install DNS-323 Temperature Plugin

The new SNMP plugin in charge of reading your DNS-323 temperature sensors is strictly following the How to write SNMP Munin plugins directives.

Under Debian, it should be installed under /usr/share/munin/plugins/

/usr/share/munin/plugins/snmp__dns32x_temperature

#!/bin/sh
# -*- sh -*-
# -------------------------------------------------------
# Munin node script
#
# Monitor the internal temperature of a DNS-323 or DNS-325 NAS
# Retrieves temperature of case, hdd1 and hdd2
#
# Used in http://bernaerts.dyndns.org/nas/71-dns325-ffp07/314-dns325-ffp7-snmp-supervise-temperature-case-hdd
#     and http://bernaerts.dyndns.org/nas/72-dns323-ffp07/318-dns323-ffp7-snmp-supervise-temperature-case-hdd
#
# Parameters :
#   $1 : none, "snmpconf" or "config"
#
# 28/06/2014, V1.0 - Creation by N. Bernaerts
# 30/06/2014, V2.0 - Add fan speed status
# 05/07/2014, V2.1 - Add hard disk information
# 25/07/2014, V3.0 - Add DNS-323 compatibility
# 02/08/2014, V3.1 - Add warning and critical levels
# -------------------------------------------------------

: << =cut

=head1 NAME

snmp__dns32x_temperature - Munin plugin to monitor the internal temperature of DNS-325 & DNS-323 NAS

=head1 APPLICABLE SYSTEMS

Any DNS-323 or DNS-325 with funplug installed and Net-SNMP installed and configured

=head1 CONFIGURATION

DNS-323 or DNS-325 must have funplug installed and Net-SNMP installed and configured.
This plugin uses public community.

=head1 INTERPRETATION

The temperature in degree celsius for case, hard disk 1 and hard disk 2.
The fan rotation speed.

=head1 MIB INFORMATION

This plugin requires support for extended snmp-temperature MIBs.

=head1 MAGIC MARKERS

  #%# family=snmpauto
  #%# capabilities=snmpconf

=head1 VERSION

  $Id$

=head1 BUGS

None known.

=head1 AUTHOR

Copyright (C) 2014 Nicolas Bernaerts

=head1 LICENSE

GPLv2.

=cut

# define warning and critical temperature levels
CASE_WARNING="45"
CASE_CRITICAL="50"
DISK_WARNING="45"
DISK_CRITICAL="50"

# define display value for 3 fan states (stop, low & high)
FAN_STOP="20"
FAN_LOW="22"
FAN_HIGH="24"

# -------------------------------------------------------
# Configure all MIBs adresses
# -------------------------------------------------------

# extended MIB for temperature
MIB_FAN="1.3.6.1.4.1.8072.1.3.2.3.1.2.9.115.112.101.101.100.95.102.97.110"
MIB_TEMP_CASE="1.3.6.1.4.1.8072.1.3.2.3.1.2.20.116.101.109.112.101.114.97.116.117.114.101.95.105.110.116.101.114.110.97.108"
MIB_TEMP_DISK1="1.3.6.1.4.1.8072.1.3.2.3.1.2.17.116.101.109.112.101.114.97.116.117.114.101.95.100.105.115.107.49"
MIB_TEMP_DISK2="1.3.6.1.4.1.8072.1.3.2.3.1.2.17.116.101.109.112.101.114.97.116.117.114.101.95.100.105.115.107.50"
MIB_INFO_DISK1="1.3.6.1.4.1.8072.1.3.2.3.1.2.17.105.110.102.111.114.109.97.116.105.111.110.95.100.105.115.107.49"
MIB_INFO_DISK2="1.3.6.1.4.1.8072.1.3.2.3.1.2.17.105.110.102.111.114.109.97.116.105.111.110.95.100.105.115.107.50"

# -------------------------------------------------------
# Get NAS address
# -------------------------------------------------------

# get nas name from script name
NAS_IP=`basename $0 | cut -d'_' -f2`

# -------------------------------------------------------
# Read all MIBs data from the NAS
# -------------------------------------------------------

# if not in autoconf process, read SNMP data
if [ "$1" != "snmpconf" ]; then
  # read SNMP MIB
  MIB_RESULT=`snmpget -v1 -One -c public $NAS_IP $MIB_FAN $MIB_TEMP_CASE $MIB_TEMP_DISK1 $MIB_TEMP_DISK2 $MIB_INFO_DISK1 $MIB_INFO_DISK2`

  # get values from result
  VALUE_FAN=`echo $MIB_RESULT | sed 's/^.*'$MIB_FAN'[ =:STRING]*"\([a-z]*\)".*$/\1/g'`
  VALUE_TEMP_CASE=`echo $MIB_RESULT | sed 's/^.*'$MIB_TEMP_CASE'[ =:STRING]*"\([0-9]*\)".*$/\1/g'`
  VALUE_TEMP_DISK1=`echo $MIB_RESULT | sed 's/^.*'$MIB_TEMP_DISK1'[" =:STRING]*\([0-9]*\)".*$/\1/g'`
  VALUE_TEMP_DISK2=`echo $MIB_RESULT | sed 's/^.*'$MIB_TEMP_DISK2'[" =:STRING]*\([0-9]*\)".*$/\1/g'`
  VALUE_INFO_DISK1=`echo $MIB_RESULT | sed 's/^.*'$MIB_INFO_DISK1'[" =:STRING]*\([^"]*\).*$/\1/g'`
  VALUE_INFO_DISK2=`echo $MIB_RESULT | sed 's/^.*'$MIB_INFO_DISK2'[" =:STRING]*\([^"]*\).*$/\1/g'`
fi

# -------------------------------------------------------
# Handle SNMP autoconf call
# -------------------------------------------------------

# snmpconf : announce required MIBs
if [ "$1" = "snmpconf" ]; then
  echo "require $MIB_FAN"
  echo "require $MIB_TEMP_CASE"
  echo "require $MIB_TEMP_DISK1"
  echo "require $MIB_TEMP_DISK2"

# -------------------------------------------------------
# Handle configuration call
# -------------------------------------------------------

# config : read node configuration
elif [ "$1" = "config" ]; then
  # NAS general infos
  echo "host_name $NAS_IP"
  echo "graph_title Temperature & Fan speed ($NAS_IP)"
  echo "graph_vlabel Degree Celsius"
  echo "graph_category temperature"
  echo "graph_info Temperature Levels & Fan speed"
  echo "graph_args --lower-limit $FAN_STOP --rigid"

  # fan speed
  echo "fan.info Fan speed (off:$FAN_STOP, low:$FAN_LOW, high:$FAN_HIGH)"
  echo "fan.label Fan"
  echo "fan.colour c0c0c0"
  echo "fan.draw AREA"

  # internal temperature
  echo "case.label Internal case"
  echo "case.colour 00ff00"
  echo "case.info Case internal sensor"
  echo "case.warning :$CASE_WARNING"
  echo "case.critical :$CASE_CRITICAL"


  # disk1 temperature
  echo "disk1.label Disk 1"
  echo "disk1.colour 0000ff"
  echo "disk1.info HDD sensor, $VALUE_INFO_DISK1"
  echo "disk1.warning :$DISK_WARNING"
  echo "disk1.critical :$DISK_CRITICAL"


  # disk2 temperature
  echo "disk2.label Disk 2"
  echo "disk2.colour ff00ff"
  echo "disk2.info HDD sensor, $VALUE_INFO_DISK2"
  echo "disk2.warning :$DISK_WARNING"
  echo "disk2.critical :$DISK_CRITICAL"

# -------------------------------------------------------
# Handle data read call
# -------------------------------------------------------

# normal case : read temperatures
else
  # publish fan speed
  case $VALUE_FAN in
    stop)   echo "fan.value $FAN_STOP" ;;
    rotate) echo "fan.value $FAN_LOW" ;;
    low)    echo "fan.value $FAN_LOW" ;;
    high)   echo "fan.value $FAN_HIGH" ;;
    *)      echo "fan.value U" ;;
  esac

  # publish temperature levels
  echo "case.value $VALUE_TEMP_CASE"
  echo "disk1.value $VALUE_TEMP_DISK1"
  echo "disk2.value $VALUE_TEMP_DISK2"
fi

exit 0

After the plugin installation, you'll need to restart munin-node daemon.

# wget -O /usr/share/munin/plugins/snmp__dns32x_temperature https://raw.githubusercontent.com/NicolasBernaerts/munin-plugin/master/snmp__dns32x_temperature
# chmod +x /usr/share/munin/plugins/snmp__dns32x_temperature
# service munin-node restart

6.2. Configure Munin

You can now start munin SNMP auto-configuration for your DNS-323 :

# munin-node-configure --shell --snmp yourdns323networkname
...
ln -s '/usr/share/munin/plugins/snmp__dns32x_temperature' '/etc/munin/plugins/snmp_yourdns323networkname_dns32x_temperature'
...
# ln -s '/usr/share/munin/plugins/snmp__dns32x_temperature' '/etc/munin/plugins/snmp_yourdns323networkname_dns32x_temperature'

You should very soon be able to check your DNS-323 temperature sensors on your munin console.

Fan speed is also displayed on the lower part of the graph.

dns325-snmp temperature-day

Your NAS health is now under control   :-)

 

Hope it helps.

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus