#!/ffp/bin/bash # ---------------------------------------------- # Muninlite plugin for DNS-320 # # Used to supervise : # * fan speed # * case temperature # * hdd temperature # # This script needs the following utilities to run : # * fan_control # * smartctl # * lsblk # # To install muninlite on DNS-320, please check : # http://bernaerts.dyndns.org/nas/71-dns325-ffp07/319-dns325-dns323-ffp7-munin-node-muninlite # # 28/04/2015, V1.0 - Creation by N. Bernaerts # 02/05/2015, V1.1 - Handle fan speed from user.log # 03/05/2015, V1.2 - Handle error where temperature case is read as 0 # 03/05/2015, V1.3 - Do not check idle drive (thanks to John Kari) # ---------------------------------------------- # ------------------------------------------------------- # Initialisation # ------------------------------------------------------- # log file LOG_FILE="/var/log/user.log" # 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="24" FAN_HIGH="28" # get nas name NAS_IP=$(hostname) # ------------------------------------------------------- # Disk array initialisation # ------------------------------------------------------- # load array all disks available on the system ARR_DISK=($(lsblk --nodeps --noheadings | cut -d' ' -f1 | grep "sd.")) # ------------------------------------------------------- # Configuration call # ------------------------------------------------------- if [ "$1" = "config" ]; then # ------------------------------- # NAS general infos # ------------------------------- echo "host_name $NAS_IP" echo "graph_title Temperature & Fan speed" echo "graph_vlabel Degree Celsius" echo "graph_category temperature" echo "graph_info Temperature Levels & Fan speed" echo "graph_scale no" echo "graph_args --lower-limit $FAN_STOP --upper-limit ${DISK_CRITICAL} --rigid" # ------------------------------- # Fan speed # ------------------------------- echo "fan.label Fan" echo "fan.info Fan speed (off:$FAN_STOP, low:$FAN_LOW, high:$FAN_HIGH)" echo "fan.colour c0c0c0" echo "fan.draw AREA" # ------------------------------- # Case internal temperature # ------------------------------- echo "case.label Internal case" echo "case.info Internal Case Sensor" echo "case.colour 00ff00" echo "case.warning :${CASE_WARNING}" echo "case.critical :${CASE_CRITICAL}" # ------------------------------- # Hard drives temperature # ------------------------------- for DISK in "${ARR_DISK[@]}" do # init text DISK_INFO="Idle" # check disk state DISK_STATE=$(hdparm -C /dev/${DISK} | grep "state.*" | sed 's/.*[=: ]//') # if disk is not idle if [ "${DISK_STATE}" = "active/idle" ] then # get disk capacity DISK_SIZE=$(smartctl -i --device=marvell /dev/${DISK} | grep "^User Capacity" | sed 's/^.*:\([0-9 ,]*\)bytes.*$/\1/' | tr -d " ," | sed 's/\(.*\).\{9\}/\1/') # if disk is present, get its full characteristics if [ "${DISK_SIZE}" != "" ] then DISK_MODEL=$(smartctl -i --device=marvell /dev/${DISK} | grep "^Device Model" | sed 's/^.*:[ ]*\(.*\)$/\1/') DISK_SERIAL=$(smartctl -i --device=marvell /dev/${DISK} | grep "^Serial Number" | sed 's/^.*:[ ]*\(.*\)$/\1/') DISK_INFO="${DISK_SIZE} Gb, model ${DISK_MODEL}, s/n ${DISK_SERIAL}" fi fi # display disk1 configuration echo "${DISK}.label /dev/${DISK}" echo "${DISK}.info ${DISK_INFO}" echo "${DISK}.warning :${DISK_WARNING}" echo "${DISK}.critical :${DISK_CRITICAL}" done # ------------------------------------------------------- # Normal call : Read Data # ------------------------------------------------------- else # read internal case temperature (handle read errors reporting 0) TEMP_CASE=$(fan_control -g 0 | grep " is " | sed 's/^.*is \([0-9]*\)$/\1/') [ "${TEMP_CASE}" = "0" ] && TEMP_CASE="U" # publish case temperature echo "case.value ${TEMP_CASE}" # read fan state FAN_STATE=$(fan_control -g 3 | sed 's/^.*is \([0-9]*\).*$/\1/') # if fan rotates, get speed from last user.log record if [ "${FAN_STATE}" == "1" ] then FAN_SPEED=$(cat ${LOG_FILE} | grep "Fan Speed" | tail -n 1 - | sed 's/^.*\"\(.*\)\".*$/\1/') [ "${FAN_SPEED}" == "High" ] && FAN_STATE=2 fi # publish fan speed case ${FAN_STATE} in 0) echo "fan.value ${FAN_STOP}" ;; 1) echo "fan.value ${FAN_LOW}" ;; 2) echo "fan.value ${FAN_HIGH}" ;; *) echo "fan.value U" ;; esac for DISK in "${ARR_DISK[@]}" do # check disk state DISK_STATE=$(hdparm -C /dev/${DISK} | grep "state.*" | sed 's/.*[=: ]//') # if disk is not idle if [ "${DISK_STATE}" = "active/idle" ] then # read hard disk 1 temperature TEMP_DISK=$(smartctl -A --device=marvell /dev/${DISK} | grep "^194.*" | sed 's/^.*- *\([0-9]*\).*$/\1/g') # publish disk temperature echo "${DISK}.value ${TEMP_DISK}" fi done fi