├── LICENSE ├── README.md └── check_snmp_synology.sh /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 exensio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # synology-nagios-plugin 2 | A simple Nagios Plugin which checks the health of a Synology NAS 3 | It checks the following items: 4 | * System status (Power, Fans) 5 | * Disks status 6 | * RAID (Volumes) status 7 | * DSM update status 8 | * Temperatures 9 | * Storage usage 10 | * UPS informations 11 | 12 | ## [exensio GmbH Blog](https://www.exensio.de/news-medien) 13 | 14 | This repositroy is created for the blogpost: [Synology DiskStation per SNMP überwachen](https://www.exensio.de/news-medien/newsreader-blog/synology-diskstation-per-snmp-ueberwachen) 15 | 16 | ## Requirements 17 | The SNMP agent on the NAS has to be activated. 18 | 19 | ## Command Line Usage 20 | ``` 21 | ./check_snmp_synology [OPTION] -u [user] -p [pass] -h [hostname] 22 | options: 23 | -u [snmp username] Username for SNMPv3 24 | -p [snmp password] Password for SNMPv3 25 | 26 | -2 [community name] Use SNMPv2 (no need user/password) & define community name (default public) 27 | 28 | -W [warning temp] Warning temperature (for disks & synology) (default 50) 29 | -C [critical temp] Critical temperature (for disks & synology) (default 60) 30 | 31 | -w [warning %] Warning storage usage percentage (default 80) 32 | -c [critical %] Critical storage usage percentage (default 95) 33 | 34 | -U Show informations about the connected UPS (default no) 35 | -f PerfData - print performance data for temperature and storage usage percentage (default no) 36 | -v Verbose - print all informations about your Synology (default no) 37 | -d Check DSM Version - check if an update for DiskStation Manager is available (default no) 38 | 39 | ``` 40 | 41 | ## Nagios Plugin Configuration 42 | My *commands.cfg* looks like this: 43 | ``` 44 | define command { 45 | command_name check_snmp_synology 46 | command_line $USER2$/check_snmp_synology -2 $ARG1$ -v -h $HOSTADDRESS$ -f -W $ARG2$ -C $ARG3$ -w $ARG4$ -c $ARG5$ 47 | } 48 | ``` 49 | 50 | And my *services.cfg* looks like this: 51 | ``` 52 | define service { 53 | service_description check_snmp_synology_demo 54 | host_name demo_host 55 | use check_mk_active 56 | check_command check_snmp_synology!public!45!48!85!90 57 | } 58 | ``` 59 | 60 | ## Based on 61 | This plugin has been originally published by [Nicolas Ordonez] (mailto:nicolas.ord@gmail.com) on [https://exchange.nagios.org] (https://exchange.nagios.org/directory/Plugins/Network-and-Systems-Management/Others/Synology-status/details) 62 | -------------------------------------------------------------------------------- /check_snmp_synology.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # 4 | # check_website_by_selenium.sh 5 | # Description : Checks a website using the Selenium Grid 6 | # 7 | # The MIT License (MIT) 8 | # 9 | # Copyright (c) 2016, Roland Rickborn (roland.rickborn@exensio.de) 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy 12 | # of this software and associated documentation files (the "Software"), to deal 13 | # in the Software without restriction, including without limitation the rights 14 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | # copies of the Software, and to permit persons to whom the Software is 16 | # furnished to do so, subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included in 19 | # all copies or substantial portions of the Software. 20 | # 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | # THE SOFTWARE. 28 | # 29 | # check_snmp_synology for nagios version 2.4 30 | # See https://exchange.nagios.org/directory/Plugins/Network-and-Systems-Management/Others/Synology-status/details 31 | # 32 | # 16.04.2015 Nicolas Ordonez, Switzerland 33 | # 05.10.2015 Roland Rickborn , Germany 34 | # 29.02.2016 j-ed, https://github.com/j-ed 35 | # 10.05.2016 Luiz Henrique De Andrade, luizhandrade 36 | #--------------------------------------------------- 37 | # this plugin checks the health of your Synology NAS 38 | # - System status (Power, Fans) 39 | # - Disks status 40 | # - RAID status 41 | # - DSM update status 42 | # - Temperature Warning and Critical 43 | # - UPS information 44 | # - Storage percentage of use 45 | # 46 | # Tested with DSM 5.0, 5.1 & 5.2 47 | #--------------------------------------------------- 48 | # Based on http://ukdl.synology.com/download/Document/MIBGuide/Synology_DiskStation_MIB_Guide.pdf 49 | #--------------------------------------------------- 50 | # actual number disk limit = 52 disks per Synology 51 | #--------------------------------------------------- 52 | 53 | SNMPWALK=$(which snmpwalk) 54 | SNMPGET=$(which snmpget) 55 | 56 | SNMPVersion="3" 57 | SNMPV2Community="public" 58 | SNMPTimeout="10" 59 | warningTemperature="50" 60 | criticalTemperature="60" 61 | warningStorage="80" 62 | criticalStorage="95" 63 | hostname="" 64 | healthWarningStatus=0 65 | healthCriticalStatus=0 66 | healthString="" 67 | verbose="no" 68 | ups="no" 69 | perfDataTempString="" 70 | perfDataStorageString="" 71 | perfData="no" 72 | dsmcheck="no" 73 | 74 | #OID declarations 75 | OID_syno="1.3.6.1.4.1.6574" 76 | OID_model="1.3.6.1.4.1.6574.1.5.1.0" 77 | OID_serialNumber="1.3.6.1.4.1.6574.1.5.2.0" 78 | OID_DSMVersion="1.3.6.1.4.1.6574.1.5.3.0" 79 | OID_DSMUpgradeAvailable="1.3.6.1.4.1.6574.1.5.4.0" 80 | OID_systemStatus="1.3.6.1.4.1.6574.1.1.0" 81 | OID_temperature="1.3.6.1.4.1.6574.1.2.0" 82 | OID_powerStatus="1.3.6.1.4.1.6574.1.3.0" 83 | OID_systemFanStatus="1.3.6.1.4.1.6574.1.4.1.0" 84 | OID_CPUFanStatus="1.3.6.1.4.1.6574.1.4.2.0" 85 | 86 | OID_disk="" 87 | OID_disk2="" 88 | OID_diskID="1.3.6.1.4.1.6574.2.1.1.2" 89 | OID_diskModel="1.3.6.1.4.1.6574.2.1.1.3" 90 | OID_diskStatus="1.3.6.1.4.1.6574.2.1.1.5" 91 | OID_diskTemp="1.3.6.1.4.1.6574.2.1.1.6" 92 | 93 | OID_RAID="" 94 | OID_RAIDName="1.3.6.1.4.1.6574.3.1.1.2" 95 | OID_RAIDStatus="1.3.6.1.4.1.6574.3.1.1.3" 96 | 97 | OID_Storage="1.3.6.1.2.1.25.2.3.1" 98 | OID_StorageDesc="1.3.6.1.2.1.25.2.3.1.3" 99 | OID_StorageAllocationUnits="1.3.6.1.2.1.25.2.3.1.4" 100 | OID_StorageSize="1.3.6.1.2.1.25.2.3.1.5" 101 | OID_StorageSizeUsed="1.3.6.1.2.1.25.2.3.1.6" 102 | 103 | OID_UpsModel="1.3.6.1.4.1.6574.4.1.1.0" 104 | OID_UpsSN="1.3.6.1.4.1.6574.4.1.3.0" 105 | OID_UpsStatus="1.3.6.1.4.1.6574.4.2.1.0" 106 | OID_UpsLoad="1.3.6.1.4.1.6574.4.2.12.1.0" 107 | OID_UpsBatteryCharge="1.3.6.1.4.1.6574.4.3.1.1.0" 108 | OID_UpsBatteryChargeWarning="1.3.6.1.4.1.6574.4.3.1.4.0" 109 | 110 | usage() 111 | { 112 | echo "usage: ./check_snmp_synology [OPTION] -u [user] -p [pass] -h [hostname]" 113 | echo "options:" 114 | echo " -u [snmp username] Username for SNMPv3" 115 | echo " -p [snmp password] Password for SNMPv3" 116 | echo "" 117 | echo " -2 [community name] Use SNMPv2 (no need user/password) & define community name (default $SNMPV2Community)" 118 | echo "" 119 | echo " -W [warning temp] Warning temperature (for disks & synology) (default $warningTemperature)" 120 | echo " -C [critical temp] Critical temperature (for disks & synology) (default $criticalTemperature)" 121 | echo "" 122 | echo " -w [warning %] Warning storage usage percentage (default $warningStorage)" 123 | echo " -c [critical %] Critical storage usage percentage (default $criticalStorage)" 124 | echo "" 125 | echo " -U Show informations about the connected UPS (default no)" 126 | echo " -v Verbose - print all informations about your Synology (default $verbose)" 127 | echo " -f PerfData - print performance data for temperature and storage usage percentage (default $perfData)" 128 | echo " -d Check DSM Version - check if an update for DiskStation Manager is available (default $dsmcheck)" 129 | echo "" 130 | echo "" 131 | echo "examples: ./check_snmp_synology -u admin -p 1234 -h nas.intranet" 132 | echo " ./check_snmp_synology -u admin -p 1234 -h nas.intranet -v" 133 | echo " ./check_snmp_synology -2 public -h nas.intranet" 134 | exit 3 135 | } 136 | 137 | if [ "$1" == "--help" ]; then 138 | usage 139 | exit 0 140 | fi 141 | 142 | while getopts 2:W:C:w:c:u:p:h:Uvfd OPTNAME; 143 | do 144 | case "$OPTNAME" in 145 | u) SNMPUser="$OPTARG";; 146 | p) SNMPPassword="$OPTARG";; 147 | h) hostname="$OPTARG";; 148 | v) verbose="yes";; 149 | 2) SNMPVersion="2" 150 | SNMPV2Community="$OPTARG";; 151 | w) warningStorage="$OPTARG";; 152 | c) criticalStorage="$OPTARG";; 153 | W) warningTemperature="$OPTARG";; 154 | C) criticalTemperature="$OPTARG";; 155 | U) ups="yes";; 156 | f) perfData="yes";; 157 | d) dsmcheck="yes";; 158 | *) usage;; 159 | esac 160 | done 161 | 162 | if [ "$warningTemperature" -gt "$criticalTemperature" ] ; then 163 | echo "Critical temperature must be higher than warning temperature" 164 | echo "Warning temperature: $warningTemperature" 165 | echo "Critical temperature: $criticalTemperature" 166 | echo "" 167 | echo "For more information: ./${0##*/} --help" 168 | exit 1 169 | fi 170 | 171 | if [ "$warningStorage" -gt "$criticalStorage" ] ; then 172 | echo "The Critical storage usage percentage must be higher than the warning storage usage percentage" 173 | echo "Warning: $warningStorage" 174 | echo "Critical: $criticalStorage" 175 | echo "" 176 | echo "For more information: ./${0##*/} --help" 177 | exit 1 178 | fi 179 | 180 | if [ "$hostname" = "" ] || ([ "$SNMPVersion" = "3" ] && [ "$SNMPUser" = "" ]) || ([ "$SNMPVersion" = "3" ] && [ "$SNMPPassword" = "" ]) ; then 181 | usage 182 | else 183 | if [ "$SNMPVersion" = "2" ] ; then 184 | SNMPArgs=" -OQne -v 2c -c $SNMPV2Community -t $SNMPTimeout" 185 | else 186 | SNMPArgs=" -OQne -v 3 -u $SNMPUser -A $SNMPPassword -l authNoPriv -a MD5 -t $SNMPTimeout" 187 | if [ ${#SNMPPassword} -lt "8" ] ; then 188 | echo "snmpwalk: (The supplied password length is too short.)" 189 | exit 1 190 | fi 191 | fi 192 | tmpRequest=`$SNMPWALK $SNMPArgs $hostname $OID_model 2> /dev/null` 193 | if [ "$?" != "0" ] ; then 194 | echo "CRITICAL - Problem with SNMP request, check user/password/host" 195 | exit 2 196 | fi 197 | nbDisk=`$SNMPWALK $SNMPArgs $hostname $OID_diskID | wc -l` 198 | nbRAID=`$SNMPWALK $SNMPArgs $hostname $OID_RAIDName | wc -l` 199 | 200 | for i in `seq 1 $nbDisk`; 201 | do 202 | if [ $i -lt 25 ] ; then 203 | OID_disk="$OID_disk $OID_diskID.$(($i-1)) $OID_diskModel.$(($i-1)) $OID_diskStatus.$(($i-1)) $OID_diskTemp.$(($i-1)) " 204 | else 205 | OID_disk2="$OID_disk2 $OID_diskID.$(($i-1)) $OID_diskModel.$(($i-1)) $OID_diskStatus.$(($i-1)) $OID_diskTemp.$(($i-1)) " 206 | fi 207 | done 208 | 209 | for i in `seq 1 $nbRAID`; 210 | do 211 | OID_RAID="$OID_RAID $OID_RAIDName.$(($i-1)) $OID_RAIDStatus.$(($i-1))" 212 | done 213 | 214 | if [ "$ups" = "yes" ] && [ "$dsmcheck" = "yes" ]; then 215 | syno=`$SNMPGET $SNMPArgs $hostname $OID_model $OID_serialNumber $OID_DSMVersion $OID_systemStatus $OID_temperature $OID_powerStatus $OID_systemFanStatus $OID_CPUFanStatus $OID_disk $OID_RAID $OID_DSMUpgradeAvailable $OID_UpsModel $OID_UpsSN $OID_UpsStatus $OID_UpsLoad $OID_UpsBatteryCharge $OID_UpsBatteryChargeWarning 2> /dev/null` 216 | elif [ "$ups" = "no" ] && [ "$dsmcheck" = "yes" ] ; then 217 | syno=`$SNMPGET $SNMPArgs $hostname $OID_model $OID_serialNumber $OID_DSMVersion $OID_systemStatus $OID_temperature $OID_powerStatus $OID_systemFanStatus $OID_CPUFanStatus $OID_disk $OID_RAID $OID_DSMUpgradeAvailable 2> /dev/null` 218 | elif [ "$ups" = "yes" ] && [ "$dsmcheck" = "no" ] ; then 219 | syno=`$SNMPGET $SNMPArgs $hostname $OID_model $OID_serialNumber $OID_DSMVersion $OID_systemStatus $OID_temperature $OID_powerStatus $OID_systemFanStatus $OID_CPUFanStatus $OID_disk $OID_RAID $OID_UpsModel $OID_UpsSN $OID_UpsStatus $OID_UpsLoad $OID_UpsBatteryCharge $OID_UpsBatteryChargeWarning 2> /dev/null` 220 | elif [ "$ups" = "no" ] && [ "$dsmcheck" = "no" ] ; then 221 | syno=`$SNMPGET $SNMPArgs $hostname $OID_model $OID_serialNumber $OID_DSMVersion $OID_systemStatus $OID_temperature $OID_powerStatus $OID_systemFanStatus $OID_CPUFanStatus $OID_disk $OID_RAID 2> /dev/null` 222 | fi 223 | 224 | if [ "$OID_disk2" != "" ]; then 225 | syno2=`$SNMPGET $SNMPArgs $hostname $OID_disk2 2> /dev/null` 226 | syno=$(echo "$syno";echo "$syno2";) 227 | fi 228 | 229 | model=$(echo "$syno" | grep $OID_model | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 230 | serialNumber=$(echo "$syno" | grep $OID_serialNumber | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 231 | DSMVersion=$(echo "$syno" | grep $OID_DSMVersion | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 232 | 233 | healthString="Synology $model (s/n:$serialNumber, $DSMVersion)" 234 | 235 | DSMUpgradeAvailable=$(echo "$syno" | grep $OID_DSMUpgradeAvailable | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 236 | case $DSMUpgradeAvailable in 237 | "1") DSMUpgradeAvailable="Available"; healthWarningStatus=1; healthString="$healthString, DSM update available";; 238 | "2") DSMUpgradeAvailable="Unavailable";; 239 | "3") DSMUpgradeAvailable="Connecting";; 240 | "4") DSMUpgradeAvailable="Disconnected"; healthWarningStatus=1; healthString="$healthString, DSM Update Disconnected";; 241 | "5") DSMUpgradeAvailable="Others"; healthWarningStatus=1; healthString="$healthString, Check DSM Update";; 242 | esac 243 | 244 | RAIDName=$(echo "$syno" | grep $OID_RAIDName | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 245 | RAIDStatus=$(echo "$syno" | grep $OID_RAIDStatus | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 246 | systemStatus=$(echo "$syno" | grep $OID_systemStatus | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 247 | temperature=$(echo "$syno" | grep $OID_temperature | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 248 | powerStatus=$(echo "$syno" | grep $OID_powerStatus | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 249 | systemFanStatus=$(echo "$syno" | grep $OID_systemFanStatus | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 250 | CPUFanStatus=$(echo "$syno" | grep $OID_CPUFanStatus | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 251 | 252 | 253 | #Check system status 254 | if [ "$systemStatus" = "1" ] ; then 255 | systemStatus="Normal" 256 | else 257 | systemStatus="Failed" 258 | healthCriticalStatus=1 259 | healthString="$healthString, System status: $systemStatus " 260 | fi 261 | 262 | #Check system temperature 263 | if [ "$temperature" -gt "$warningTemperature" ] ; then 264 | if [ "$temperature" -gt "$criticalTemperature" ] ; then 265 | temperature="$temperature (CRITICAL)" 266 | healthCriticalStatus=1 267 | healthString="$healthString, temperature: $temperature " 268 | else 269 | temperature="$temperature (WARNING)" 270 | healthWarningStatus=1 271 | healthString="$healthString, temperature: $temperature " 272 | fi 273 | else 274 | temperature="$temperature (Normal)" 275 | fi 276 | 277 | #Check power status 278 | if [ "$powerStatus" = "1" ] ; then 279 | powerStatus="Normal" 280 | else 281 | powerStatus="Failed"; 282 | healthCriticalStatus=1 283 | healthString="$healthString, Power status: $powerStatus " 284 | fi 285 | 286 | 287 | #Check system fan status 288 | if [ "$systemFanStatus" = "1" ] ; then 289 | systemFanStatus="Normal" 290 | else 291 | systemFanStatus="Failed"; 292 | healthCriticalStatus=1 293 | healthString="$healthString, System fan status: $systemFanStatus " 294 | fi 295 | 296 | #Check CPU fan status 297 | if [ "$CPUFanStatus" = "1" ] ; then 298 | CPUFanStatus="Normal" 299 | else 300 | CPUFanStatus="Failed"; 301 | healthCriticalStatus=1 302 | healthString="$healthString, CPU fan status: $CPUFanStatus " 303 | fi 304 | 305 | #Check all disk status 306 | for i in `seq 1 $nbDisk`; 307 | do 308 | diskID[$i]=$(echo "$syno" | grep "$OID_diskID.$(($i-1)) " | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 309 | diskModel[$i]=$(echo "$syno" | grep "$OID_diskModel.$(($i-1)) " | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 310 | diskStatus[$i]=$(echo "$syno" | grep "$OID_diskStatus.$(($i-1)) " | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 311 | diskTemp[$i]=$(echo "$syno" | grep "$OID_diskTemp.$(($i-1)) " | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 312 | 313 | #Store perfData 314 | perfDataTempString="$perfDataTempString 'Temp Disk $i'=${diskTemp[$i]};$warningTemperature;$criticalTemperature;0" ; 315 | 316 | case ${diskStatus[$i]} in 317 | "1") diskStatus[$i]="Normal"; ;; 318 | "2") diskStatus[$i]="Initialized"; ;; 319 | "3") diskStatus[$i]="NotInitialized"; ;; 320 | "4") diskStatus[$i]="SystemPartitionFailed"; healthCriticalStatus=1; healthString="$healthString, problem with ${diskID[$i]} (model:${diskModel[$i]}) status:${diskStatus[$i]} temperature:${diskTemp[$i]}";; 321 | "5") diskStatus[$i]="Crashed"; healthCriticalStatus=1; healthString="$healthString, problem with ${diskID[$i]} (model:${diskModel[$i]}) status:${diskStatus[$i]} temperature:${diskTemp[$i]}";; 322 | esac 323 | 324 | if [ "${diskTemp[$i]}" -gt "$warningTemperature" ] ; then 325 | if [ "${diskTemp[$i]}" -gt "$criticalTemperature" ] ; then 326 | diskTemp[$i]="${diskTemp[$i]} (CRITICAL)" 327 | healthCriticalStatus=1; 328 | healthString="$healthString, ${diskID[$i]} temperature: ${diskTemp[$i]}" 329 | else 330 | diskTemp[$i]="${diskTemp[$i]} (WARNING)" 331 | healthWarningStatus=1; 332 | healthString="$healthString, ${diskID[$i]} temperature: ${diskTemp[$i]}" 333 | fi 334 | fi 335 | 336 | done 337 | 338 | #Check all RAID volume status 339 | for i in `seq 1 $nbRAID`; 340 | do 341 | RAIDName[$i]=$(echo "$syno" | grep $OID_RAIDName.$(($i-1)) | cut -d "=" -f2) 342 | RAIDStatus[$i]=$(echo "$syno" | grep $OID_RAIDStatus.$(($i-1)) | cut -d "=" -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') 343 | 344 | storageName[$i]=$(echo "${RAIDName[$i]}" | sed -e 's/[[:blank:]]//g' | sed -e 's/\"//g' | sed 's/.*/\L&/') 345 | 346 | syno_diskDescr=`$SNMPWALK $SNMPArgs $hostname $OID_Storage.3 2> /dev/null` 347 | 348 | storageID[$i]=$(echo "$syno_diskDescr" | grep -Eo ".[0-9]* = \"\/${storageName[$i]}\" *" | cut -d "." -f2 | cut -d " " -f1) 349 | 350 | if [ "${storageID[$i]}" != "" ] ; then 351 | storageSize[$i]=`$SNMPGET $SNMPArgs $hostname $OID_StorageSize.${storageID[$i]} | cut -d "=" -f2` 352 | 353 | storageSizeUsed[$i]=`$SNMPGET $SNMPArgs $hostname $OID_StorageSizeUsed.${storageID[$i]} | cut -d "=" -f2` 354 | 355 | storageAllocationUnits[$i]=`$SNMPGET $SNMPArgs $hostname $OID_StorageAllocationUnits.${storageID[$i]} | cut -d "=" -f2` 356 | 357 | storagePercentUsed[$i]=$((${storageSizeUsed[$i]} * 100 / ${storageSize[$i]})) 358 | storagePercentUsedString[$i]="${storagePercentUsed[$i]}% used" 359 | 360 | #Store perfData 361 | perfDataStorageString="$perfDataStorageString 'Raid $i Usage'=${storagePercentUsed[$i]};$warningStorage;$criticalStorage;0" ; 362 | 363 | if [ "${storagePercentUsed[$i]}" -gt "$warningStorage" ] ; then 364 | if [ "${storagePercentUsed[$i]}" -gt "$criticalStorage" ] ; then 365 | healthCriticalStatus=1; 366 | storagePercentUsedString[$i]="${storagePercentUsedString[$i]} CRITICAL" 367 | healthString="$healthString,${RAIDName[$i]}: ${storagePercentUsedString[$i]}" 368 | else 369 | healthWarningStatus=1; 370 | storagePercentUsedString[$i]="${storagePercentUsedString[$i]} WARNING" 371 | healthString="$healthString,${RAIDName[$i]}: ${storagePercentUsedString[$i]}" 372 | fi 373 | fi 374 | fi 375 | 376 | case ${RAIDStatus[$i]} in 377 | "1") RAIDStatus[$i]="Normal"; ;; 378 | "2") RAIDStatus[$i]="Repairing"; healthWarningStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 379 | "3") RAIDStatus[$i]="Migrating"; healthWarningStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 380 | "4") RAIDStatus[$i]="Expanding"; healthWarningStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 381 | "5") RAIDStatus[$i]="Deleting"; healthWarningStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 382 | "6") RAIDStatus[$i]="Creating"; healthWarningStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 383 | "7") RAIDStatus[$i]="RaidSyncing"; healthWarningStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 384 | "8") RAIDStatus[$i]="RaidParityChecking"; healthWarningStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 385 | "9") RAIDStatus[$i]="RaidAssembling"; healthWarningStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 386 | "10") RAIDStatus[$i]="Canceling"; healthWarningStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 387 | "11") RAIDStatus[$i]="Degrade"; healthCriticalStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 388 | "12") RAIDStatus[$i]="Crashed"; healthCriticalStatus=1; healthString="$healthString, RAID status (${RAIDName[$i]}): ${RAIDStatus[$i]} ";; 389 | esac 390 | done 391 | 392 | if [ "$verbose" = "yes" ] ; then 393 | echo "Synology model: $model" ; 394 | echo "Synology s/n: $serialNumber" ; 395 | echo "DSM Version: $DSMVersion" ; 396 | echo "DSM update: $DSMUpgradeAvailable" ; 397 | echo "System Status: $systemStatus" ; 398 | echo "Temperature: $temperature" ; 399 | echo "Power Status: $powerStatus" ; 400 | echo "System Fan Status: $systemFanStatus" ; 401 | echo "CPU Fan Status: $CPUFanStatus" ; 402 | echo "Number of disks: $nbDisk" ; 403 | for i in `seq 1 $nbDisk`; 404 | do 405 | echo " ${diskID[$i]} (model:${diskModel[$i]}) status:${diskStatus[$i]} temperature:${diskTemp[$i]}" ; 406 | done 407 | echo "Number of RAID volume: $nbRAID" ; 408 | for i in `seq 1 $nbRAID`; 409 | do 410 | echo " ${RAIDName[$i]} status:${RAIDStatus[$i]} ${storagePercentUsedString[$i]}" ; 411 | done 412 | 413 | # Display UPS information 414 | if [ "$ups" = "yes" ] ; then 415 | upsModel=$(echo "$syno" | grep $OID_UpsModel | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 416 | upsSN=$(echo "$syno" | grep $OID_UpsSN | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 417 | upsStatus=$(echo "$syno" | grep $OID_UpsStatus | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 418 | upsLoad=$(echo "$syno" | grep $OID_UpsLoad | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 419 | upsBatteryCharge=$(echo "$syno" | grep $OID_UpsBatteryCharge | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 420 | upsBatteryChargeWarning=$(echo "$syno" | grep $OID_UpsBatteryChargeWarning | cut -d "=" -f2 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 421 | 422 | echo "UPS:" 423 | echo " Model: $upsModel" 424 | echo " s/n: $upsSN" 425 | echo " Status: $upsStatus" 426 | echo " Load: $upsLoad" 427 | echo " Battery charge: $upsBatteryCharge" 428 | echo " Battery charge warning:$upsBatteryChargeWarning" 429 | fi 430 | 431 | echo ""; 432 | fi 433 | 434 | if [ "$healthCriticalStatus" = "1" ] && [ "$perfData" == "no" ] ; then 435 | echo "CRITICAL - $healthString" 436 | exit 2 437 | fi 438 | if [ "$healthWarningStatus" = "1" ] && [ "$perfData" == "no" ] ; then 439 | echo "WARNING - $healthString" 440 | exit 1 441 | fi 442 | if [ "$healthCriticalStatus" = "0" ] && [ "$healthWarningStatus" = "0" ] && [ "$perfData" == "no" ] ; then 443 | echo "OK - $healthString is in good health" 444 | exit 0 445 | fi 446 | if [ "$healthCriticalStatus" = "1" ] && [ "$perfData" == "yes" ] ; then 447 | echo "CRITICAL - $healthString | $perfDataTempString $perfDataStorageString" 448 | exit 2 449 | fi 450 | if [ "$healthWarningStatus" = "1" ] && [ "$perfData" == "yes" ] ; then 451 | echo "WARNING - $healthString | $perfDataTempString $perfDataStorageString" 452 | exit 1 453 | fi 454 | if [ "$healthCriticalStatus" = "0" ] && [ "$healthWarningStatus" = "0" ] && [ "$perfData" == "yes" ] ; then 455 | echo "OK - $healthString is in good health | $perfDataTempString $perfDataStorageString" 456 | exit 0 457 | fi 458 | fi 459 | 460 | exit 3 461 | --------------------------------------------------------------------------------