-
Notifications
You must be signed in to change notification settings - Fork 0
/
qnap-volume.sh
executable file
·60 lines (49 loc) · 2.77 KB
/
qnap-volume.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#########################################################################
# QNAP disk info (total/used/free) to InfluxDB
#
# majority of script taken from:
# cacti script for QNAP NAS
# Code restructured and updated by Bruce Cheng <email at brucecheng.com>, January 2013
# Partly based on work from: http://pnpk.net
#
# REQUIREMENT: You must install "bc"
# PURPOSE: Obtain disk volume information
# Usage: qnap-volume.sh <hostname> <snmp_community>
#
#########################################################################
if [[ $# -ne 2 ]]; then
echo "Usage: qnap-volume.sh <hostname> <snmp_community>"
exit 1
fi
#Set your InfluxDB parameters
influxhost="localhost:8086"
influxdb="telegraf"
qnaphostname="zoidberg"
hdtotalsize=`snmpget -v1 -t 5 -c $2 $1 .1.3.6.1.4.1.24681.1.2.17.1.4.1 |cut -d\" -f2 | cut -d' ' -f1 |awk '{ printf($1) }'`
hdfreesize_snmp=`snmpget -v1 -t 5 -c $2 $1 .1.3.6.1.4.1.24681.1.2.17.1.5.1`
hdtempcelsius=`snmpget -v1 -Oqv -t 5 -c $2 $1 1.3.6.1.4.1.24681.1.2.11.1.3.1 | cut -d" " -f1 | cut -d"\"" -f2`
# First assign free size based on the assumption TB
hdfreesize=`echo $hdfreesize_snmp |cut -d\" -f2 | cut -d' ' -f1 |awk '{ printf($1) }'`
# If the string "GB" is found, divide the variable by 1024 to convert GB to TB size
if [[ "$hdfreesize_snmp" == *" GB"* ]]; then
hdfreesize=`echo "scale=2; $hdfreesize / 1024" | bc`
fi
# If the string "MB" is found, divide the variable by 1048576 to convert MB to TB size
if [[ "$hdfreesize_snmp" == *" MB"* ]]; then
hdfreesize=`echo "scale=2; $hdfreesize / 1048576" | bc`
fi
hdusedsize=`echo "scale=2; $hdtotalsize - $hdfreesize" | bc |awk '{ printf($1) }'`
hdusedpercent=`echo "scale=2; $hdusedsize/$hdtotalsize*100" | bc`
#printf ' hdtotalsize:'$hdtotalsize
#printf ' hdfreesize:'$hdfreesize
#printf ' hdusedsize:'$hdusedsize
#printf ' hdusedpercent: '$hdusedpercent
#printf ' hdtempcelsius: '$hdtempcelsius
#Post values of disk total, used and free to InfluxDB
curl -i -XPOST "http://$influxhost/write?db=$influxdb" --data-binary "qnap-disk,host=$qnaphostname,metric=hdtotal value=$hdtotalsize `date +%s`000000000" >/dev/null 2>&1
curl -i -XPOST "http://$influxhost/write?db=$influxdb" --data-binary "qnap-disk,host=$qnaphostname,metric=hdfree value=$hdfreesize `date +%s`000000000" >/dev/null 2>&1
curl -i -XPOST "http://$influxhost/write?db=$influxdb" --data-binary "qnap-disk,host=$qnaphostname,metric=hdused value=$hdusedsize `date +%s`000000000" >/dev/null 2>&1
curl -i -XPOST "http://$influxhost/write?db=$influxdb" --data-binary "qnap-disk,host=$qnaphostname,metric=hdusedpercent value=$hdusedpercent `date +%s`000000000" >/dev/null 2>&1
curl -i -XPOST "http://$influxhost/write?db=$influxdb" --data-binary "qnap-disk,host=$qnaphostname,metric=hdtempcelsius value=$hdtempcelsius `date +%s`000000000" >/dev/null 2>&1
exit 0