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


dropcap-dns325-snmpWhen you run Net-SNMP on your DNS-325, 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-325 fan speed and temperature sensors MIB.

This article explains how to setup your DNS-325 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-325 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-325 with fun_plug 0.7 and adds-on and to have Net-SNMP installed.

Even if not tested, this procedure should also be compatible with DNS-320 devices.

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

  • fan speed
  • case temperature
  • hdd temperature

These extensions will be done with the help of some data acquisition scripts.

1. Acquisition of Fan Speed

1.1. Script to log Fan Speed

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

  • stop
  • low
  • high

Fan speed can be controled in 2 ways :

  • by fan_control daemon
  • by fanspeed command

Every time fan_control daemon changes fan speed, it logs it in /var/log/user.log


Jul 01 14:35:40 nas-fto fan_control: Set Fan Speed To "HIGH".
Jul 2 02:30:06 nas-fto rtc: Set System Time.
Jul 2 07:00:08 nas-fto fan_control: Set Fan-Control Mode To "Auto(Off/Low/High)"
Jul 02 17:31:44 nas-fto fan_control: Set Fan Speed To "LOW".

Command fanspeed can be used to read the fan state, but it only indicates if fan is still or if it rotates. It can also be used to force fan speed.

# fanspeed g
# fanspeed l
fanspeed: set fan speed to Low
# fanspeed h
fanspeed: set fan speed to high
# fanspeed g

If you force fan speed with fanspeed command, it does not log the speed change in /var/log/user.log.

So, to be able at anytime to know what the actual fan speed is, whatever command has been used to set it, simplest thing to do is to log the speed change even when fanspeed is used. That way, /var/log/user.log will allow you to get last speed forced whatever command has been used.

As /ffp/sbin is the first in the path, an easy solution is to overload fanspeed command with a new /ffp/sbin/fanspeed command that will be in charge of logging the speed change and calling original tool.

# ----------------------------------------------
# Overload original fanspeed command
# to log speed change in /var/log/user.log
# in the same way as fan_control command
# Used to supervise fan speed in
# http://bernaerts.dyndns.org/nas/314-dns325-ffp7-snmp-supervise-temperature-case-hdd
# Parameters :
#   $1 - fanspeed original parameter (h, high, l, low, s, stop or g)
# 30/06/2014, V1.0 - Creation by N. Bernaerts
# 28/07/2014, V1.1 - Add high, low & stop input
# ----------------------------------------------

# generate speed to log
case $1 in 
  h | high) LOG_SPEED="HIGH";;
  l | low)  LOG_SPEED="LOW";; 
  s | stop) LOG_SPEED="STOP";; 
  *) LOG_SPEED="";; 

# if a speed change has to be logged
if [ "$LOG_SPEED" != "" ]; then
  # generate log data
  LOG_TIME=$(date +"%b %d %H:%M:%S")

  # log action
  echo "$LOG_TIME $LOG_HOST fanspeed: Set Fan Speed To \"$LOG_SPEED\"." >> /var/log/user.log

# call original fanspeed command
/usr/sbin/fanspeed $1

To install the new fanspeed command, run these commands :

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

You'll need to reboot your NAS for this new fanspeed script to be used so that all fan speed changes will be logged in /var/log/user.log

1.2. Script to Read Fan Speed

Now that /var/log/user.log holds latest speed change, 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, it will get the rotation speed from latest speed change in /var/log/user.log.

# ----------------------------------------------
# Retrieve dns-325 fan status
# Used by http://bernaerts.dyndns.org/nas/314-dns325-ffp7-snmp-supervise-temperature-case-hdd
# Parameters : none
# 30/06/2014, V1.0 - Creation by N. Bernaerts
# 02/07/2014, V1.1 - Deal with switch to auto mode
# 14/07/2014, V1.2 - Change fan speed to 0..2
# 18/07/2014, V1.3 - Change fan speed to stop, low & high
# ----------------------------------------------

# retrieve fan status from fanspeed command
FAN_SPEED=$(fanspeed g)

# if fan is not rotating
if [ "$FAN_SPEED" = "stop" ]
  # display stop level
  echo $FAN_SPEED

# fan is supposed to rotate, get value from user.log
  # retrieve last fan speed change in /var/log/user.log
  LOG_SPEED=$(cat /var/log/user.log | grep "Set Fan Speed" | tail -n 1 | sed 's/^.*"\([^"]*\)".*$/\1/g' | tr '[:upper:]' '[:lower:]')

  # return the value
  echo $LOG_SPEED

# 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/dns325-scripts/master/snmp/snmp-fanspeed
# chmod +x /ffp/bin/snmp-fanspeed
# snmp-fanspeed

2. Acquisition of Temperature Sensors

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

It takes the sensor as an argument :

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

For case sensor, it uses temperature command.

# temperature g 0
temperature: system temperature = 33

For disk sensors, it uses smartctl tool.

# smartctl -A --device=marvell /dev/sda
smartctl version 5.38 [arm-none-linux-gnueabi] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/


SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
  1 Raw_Read_Error_Rate     0x002f   200   200   051    Pre-fail  Always       -       0
194 Temperature_Celsius     0x0022   118   108   000    Old_age   Always       -       32
200 Multi_Zone_Error_Rate   0x0008   100   253   000    Old_age   Offline      -       0

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

# ----------------------------------------------
# Retrieve dns-325 temperature sensor values for internal, disk1 and disk2
# Used by http://bernaerts.dyndns.org/nas/314-dns325-ffp7-snmp-supervise-temperature-case-hdd
# Depends on packages : 
#   * smartmontools
# Parameters :
#   $1 - sensor type (internal, disk1 or disk2)
# 28/06/2014, V1.0 - Creation by N. Bernaerts 
# ----------------------------------------------

# read temperature for $1
case $1 in
  # read case internal temperature
    echo $(temperature g 0 | sed 's/^.* = \([0-9]*\).*$/\1/g')

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

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

  # default : nothing to do

# 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/dns325-scripts/master/snmp/snmp-temperature
# chmod +x /ffp/bin/snmp-temperature
# snmp-temperature disk1
# snmp-temperature internal

3. 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

# ----------------------------------------------
# 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 WDC WD30EFRX-68EUZN0, S/n WD-WMC4N2588825, Capacity 3,000,592,982,016 bytes

4. Extend Net-SNMP

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

  • /ffp/bin/snmp-fanspeed
  • /ffp/bin/snmp-temperature
  • /ffp/bin/snmp-diskinfo


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-325 is to restart Net-SNMP daemon.

# /ffp/start/snmpd.sh restart

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

4.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\"
. = STRING: 24
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"temperature_internal\"
. = STRING: 40
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"temperature_disk1\"
. = STRING: 39
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"temperature_disk2\"
. = STRING: 35
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"information_disk1\"
. = STRING: Model WDC WD30EFRX-68EUZN0, s/n WD-WMC4N2588825, Capacity 3,000,592,982,016 bytes
# snmpget -v1 -One -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"information_disk2\"
. = STRING: Model WDC WD30EFRX-68EUZN0, s/n WD-WMC4N2588521, Capacity 3,000,592,982,016 bytes

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

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

5. Munin - DNS-325 Temperature Plugin

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

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.

5.1. Install DNS-325 Temperature Plugin

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

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

# -*- 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


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


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


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


This plugin requires support for extended snmp-temperature MIBs.


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

=head1 VERSION


=head1 BUGS

None known.

=head1 AUTHOR

Copyright (C) 2014 Nicolas Bernaerts

=head1 LICENSE



# define warning and critical temperature levels

# define display value for 3 fan states (stop, low & high)

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

# extended MIB for temperature

# -------------------------------------------------------
# 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

  # 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'`

# -------------------------------------------------------
# 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
  # 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" ;;

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

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

5.2. Configure Munin

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

# munin-node-configure --shell --snmp yourdns325networkname
ln -s '/usr/share/munin/plugins/snmp__dns325_temperature' '/etc/munin/plugins/snmp_yourdns325networkname_dns32x_temperature'
# ln -s '/usr/share/munin/plugins/snmp__dns32x_temperature' '/etc/munin/plugins/snmp_yourdns325networkname_dns32x_temperature'

You should very soon be able to check your DNS-325 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