First commit

This commit is contained in:
2018-03-13 08:04:28 +01:00
commit 196a7d2af6
32 changed files with 33836 additions and 0 deletions

204
syno/disk_mac.sh Executable file
View File

@@ -0,0 +1,204 @@
#!/bin/bash
#cf test sur les strings
SNMPCOMMUNITY="public"
SNMPVERSION="2c"
SNMPWALK=$(which snmpwalk)
SNMPGET=$(which snmpget)
CMD_BC=$(which bc)
CMD_EXPR=$(which expr)
#HOSTNAME="localhost"
HOSTNAME="192.168.0.8"
WARNING=80
CRITICAL=90
STATE=$STATE_UNKNOWN
STATE_OK="OK"
STATE_WARNING="Warning"
STATE_CRITICAL="Critical"
STATE_UNKNOWN="Inconnu"
##############
# Disk MIB (no)
##############
OID_storage=""
OID_hrStorageIndex=".1.3.6.1.2.1.25.2.3.1.1"
#A description of the type and instance of the storage described by this entry
OID_hrStorageDescr=".1.3.6.1.2.1.25.2.3.1.3"
#The size, in bytes, of the data objects allocated from this pool
OID_hrStorageAllocationUnits=".1.3.6.1.2.1.25.2.3.1.4"
#The size of the storage represented by this entry, in units of hrStorageAllocationUnits
OID_hrStorageSize=".1.3.6.1.2.1.25.2.3.1.5"
#The amount of the storage represented by this entry
OID_hrStorageUsed=".1.3.6.1.2.1.25.2.3.1.6"
OID_diskIODevice=".1.3.6.1.4.1.2021.13.15.1.1.2"
OID_diskIONReadX=".1.3.6.1.4.1.2021.13.15.1.1.12"
OID_diskIONWrittenX=".1.3.6.1.4.1.2021.13.15.1.1.13"
OID_synoDisk=".1.3.6.1.4.1.6574.2"
nbStorage=`$SNMPWALK -OQne -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME $OID_hrStorageDescr 2> /dev/null | wc -l`
declare RESULT=()
while read -r LINE; do
RESULT[${#RESULT[@]}]=$LINE
index=`$SNMPGET -OQne -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME $OID_hrStorageIndex.$(($i)) 2> /dev/null`
OID_storage="$OID_storage $OID_hrStorageDescr.$(($LINE)) $OID_hrStorageAllocationUnits.$(($LINE)) $OID_hrStorageSize.$(($LINE)) $OID_hrStorageUsed.$(($LINE)) "
done < <($SNMPWALK -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME $OID_hrStorageIndex | awk '{print $4}')
diskMIB=`$SNMPGET -OQne -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME $OID_storage 2> /dev/null`
#OID_hrStorageIndex=".1.3.6.1.2.1.25.2.3.1.1"
#OID_hrStorageType=".1.3.6.1.2.1.25.2.3.1.2"
#OID_hrStorageDescr=".1.3.6.1.2.1.25.2.3.1.3"
#OID_hrStorageAllocationUnits=".1.3.6.1.2.1.25.2.3.1.4"
#OID_hrStorageSize=".1.3.6.1.2.1.25.2.3.1.5"
#OID_hrStorageUsed=".1.3.6.1.2.1.25.2.3.1.6"
#OID_diskIODevice=".1.3.6.1.4.1.2021.13.15.1.1.2"
#OID_diskIONReadX=".1.3.6.1.4.1.2021.13.15.1.1.12"
#OID_diskIONWrittenX=".1.3.6.1.4.1.2021.13.15.1.1.13"
#OID_synoDisk=".1.3.6.1.4.1.6574.2"
if [ "$?" != "0" ] ; then
echo "CRITICAL - Problem with SNMP request diksMIB"
#exit 2
fi
#echo $diskMIB
size_convert() {
if [ $VALUE -ge 1099511627776 ]; then
VALUE=`echo "scale=2 ; ( ( ( $VALUE / 1024 ) / 1024 ) / 1024 ) / 1024" | $CMD_BC`
VALUE="$VALUE To"
elif [ $VALUE -ge 1073741824 ]; then
VALUE=`echo "scale=2 ; ( ( $VALUE / 1024 ) / 1024 ) / 1024" | $CMD_BC`
VALUE="$VALUE Go"
elif [ $VALUE -ge 1048576 ]; then
VALUE=`echo "scale=2 ; ( $VALUE / 1024 ) / 1024" | $CMD_BC`
VALUE="$VALUE Mo"
else
VALUE=`echo "scale=2 ; $VALUE / 1024" | $CMD_BC`
VALUE="$VALUE Octets"
fi
}
size_fix() {
if [ ${VALUE: 0:1} = "-" ]; then
VALUE=`$CMD_EXPR 4294967294 - \( 0 - $VALUE \)`
fi
}
hrStorageDescr=""
hrStorageAllocationUnits=""
hrStorageSize=""
hrStorageUsed=""
i=0
j=0
declare RESULT=()
while read -r LINE; do
RESULT[${#RESULT[@]}]=$LINE
_hrStorageDescr=$(echo $LINE | grep $OID_hrStorageDescr | cut -d "=" -f2)
_hrStorageAllocationUnits=$(echo $LINE | grep $OID_hrStorageAllocationUnits | cut -d "=" -f2)
_hrStorageSize=$(echo $LINE | grep $OID_hrStorageSize | cut -d "=" -f2)
_hrStorageUsed=$(echo $LINE | grep $OID_hrStorageUsed | cut -d "=" -f2)
if [ -n "$_hrStorageDescr" ] ; then hrStorageDescr[$j]=$_hrStorageDescr ; fi
if [ -n "$_hrStorageAllocationUnits" ] ; then hrStorageAllocationUnits[$j]=$_hrStorageAllocationUnits ; fi
if [ -n "$_hrStorageSize" ] ; then hrStorageSize[$j]=$_hrStorageSize ; fi
if [ -n "$_hrStorageUsed" ] ; then
#hrStorageUsed[$j]=$_hrStorageUsed
VALUE=$_hrStorageUsed
#size_fix
#size_convert
hrStorageUsed[$j]=$VALUE
fi
((i=i+1))
if [ $i -eq "4" ]
then
i=0
((j=j+1))
fi
done < <($SNMPGET -OQne -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME $OID_storage)
for((i=0;i<$nbStorage;i++));
do
# // remove all spaces
#DISK_LABEL=${hrStorageDescr[i]// }
# remove leading and trailing spaces
DISK_LABEL=`echo ${hrStorageDescr[i]} | sed 's/^ *//g' | sed 's/ *$//g'`
DISK_UNIT=`echo ${hrStorageAllocationUnits[i]} | awk '{print $1}'`
DISK_TOTAL=${hrStorageSize[i]// }
DISK_USED=${hrStorageUsed[i]// }
# longeur de la chaine
#echo ${#DISK_USED}
# 1er caractère de la variable est -
#if [ ${VALUE: 0:1} = "-" ]; then
#echo "$DISK_LABEL"
# Swap space
#if [ "${DISK_LABEL}" == "Shared memory" ]; then
#echo "$DISK_TOTAL"
#echo "$DISK_USED"
#fi
if [ "${DISK_LABEL}" != "/dev" ] && [ "${DISK_LABEL}" != "/net" ] && [ "${DISK_LABEL}" != "/home" ] && [ "${DISK_LABEL}" != "Shared memory" ]; then
DISK_TOTAL=`$CMD_EXPR $DISK_TOTAL \* \( $DISK_UNIT \)`
DISK_USED=`$CMD_EXPR $DISK_USED \* \( $DISK_UNIT \)`
#echo "$DISK_TOTAL"
#echo "$DISK_USED"
PERFDATA_WARNING=0
PERFDATA_CRITICAL=0
if [ $WARNING != 0 ] || [ $CRITICAL != 0 ]; then
DISK_USED_POURCENT=`$CMD_EXPR \( $DISK_USED \* 100 \) / $DISK_TOTAL`
PERFDATA_WARNING=`$CMD_EXPR \( $DISK_TOTAL \* $WARNING \) / 100`
PERFDATA_CRITICAL=`$CMD_EXPR \( $DISK_TOTAL \* $CRITICAL \) / 100`
#echo "$PERFDATA_WARNING"
#echo "$PERFDATA_CRITICAL"
if [ $DISK_USED_POURCENT -gt $CRITICAL ] && [ $CRITICAL != 0 ]; then
STATE=$STATE_CRITICAL
elif [ $DISK_USED_POURCENT -gt $WARNING ] && [ $WARNING != 0 ]; then
STATE=$STATE_WARNING
else
STATE=$STATE_OK
fi
else
STATE=$STATE_OK
fi
VALUE=$DISK_TOTAL
size_convert
DISK_TOTAL_FORMAT=$VALUE
VALUE=$DISK_USED
size_convert
DISK_USED_FORMAT=$VALUE
printf "%s %s %s\n" "$DISK_LABEL $DISK_USED_FORMAT utilise sur $DISK_TOTAL_FORMAT (${DISK_USED_POURCENT}%) $STATE"
fi
done
#exit $STATE