-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsnmp.sh
More file actions
executable file
·108 lines (84 loc) · 3.07 KB
/
Copy pathsnmp.sh
File metadata and controls
executable file
·108 lines (84 loc) · 3.07 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
set -eu
GUDES="1 2 3"
PORTS="1 2 3 4 5 6 7 8"
HOSTS="1 2 3 4 5 6 7 8 10 11 14 15 19 25 26 27 29 31 32 41 42 52"
INTERFACES="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19"
export snmparg="-O qv -v 2c -c public"
echo "/* THIS FILE IS AUTO GENERATED BY snmp.sh */"
tempcur=$(snmp get -O qv -v 2c -c public gude7 enterprises.28507.56.1.6.1.1.2.1)
tempmin=$(cat /var/www/obsdlab/state-temp-min.txt)
tempmax=$(cat /var/www/obsdlab/state-temp-max.txt)
echo $tempcur $(date +"%F %T") >> /var/www/obsdlab/state-temp.log
if [ $tempcur -lt $tempmin ]; then
echo $tempcur > /var/www/obsdlab/state-temp-min.txt
tempmin=$tempcur
fi
if [ $tempcur -gt $tempmax ]; then
echo $tempcur > /var/www/obsdlab/state-temp-max.txt
tempmax=$tempcur
fi
tempmintime=$(stat -t '%F %T' -f '%Sm' /var/www/obsdlab/state-temp-min.txt)
tempmaxtime=$(stat -t '%F %T' -f '%Sm' /var/www/obsdlab/state-temp-max.txt)
tempcur=$(echo $tempcur | sed -Ee 's/(.*)(.)$/\1.\2/')
tempmin=$(echo $tempmin | sed -Ee 's/(.*)(.)$/\1.\2/')
tempmax=$(echo $tempmax | sed -Ee 's/(.*)(.)$/\1.\2/')
echo "#tempcur::before { content: \"$tempcur °C\" }"
echo "#tempmin::before { content: \"$tempmin °C\" }"
echo "#tempmax::before { content: \"$tempmax °C\" }"
echo "#tempmintime::before { content: \"$tempmintime\" }"
echo "#tempmaxtime::before { content: \"$tempmaxtime\" }"
#
# collect power socket states
#
for g in $GUDES; do
for p in $PORTS; do
stat=$(snmp get $snmparg gude$g .iso.org.dod.internet.private.enterprises.28507.1.1.2.2.1.3.$p) || break
name=$(snmp get $snmparg gude$g .iso.org.dod.internet.private.enterprises.28507.1.1.2.2.1.2.$p) || break
echo "#g${g}p${p}::before { content: \"$name\"; }"
if [ $stat -eq 1 ]; then
echo "#g${g}p${p} { background-color: #73d216; }"
else
echo "#g${g}p${p} { background-color: #cc0000; }"
fi
done
echo
done
# gude 7
for p in $(jot 12); do
stat=$(snmp get $snmparg gude7 1.3.6.1.4.1.28507.56.1.3.1.2.1.3.$p) || break
name=$(snmp get $snmparg gude7 1.3.6.1.4.1.28507.56.1.3.1.2.1.2.$p) || break
echo "#g7p${p}::before { content: \"$name\"; }"
if [ $stat -eq 1 ]; then
echo "#g7p${p} { background-color: #73d216; }"
else
echo "#g7p${p} { background-color: #cc0000; }"
fi
done
echo
#
# collect interface information
#
for ot in $HOSTS; do
for i in $INTERFACES; do
name=$(snmp get $snmparg -r 0 ot$ot .iso.org.dod.internet.mgmt.mib_2.ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.$i) || break
speed=$(snmp get $snmparg -r 0 ot$ot .iso.org.dod.internet.mgmt.mib_2.ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifHighSpeed.$i) || break
if [ "$name" = "No Such Object available on this agent at this OID" ]; then
continue
fi
if [ "$name" = "No Such Instance currently exists at this OID" ]; then
continue
fi
if [ "$name" = "enc0" -o "$name" = "lo0" -o "$name" = "pflog0" ]; then
echo "#ot${ot}i${i} { display: none; }"
continue
fi
echo "#ot${ot}i${i}::before { content: \"$name\"; }"
if [ $speed -eq 0 ]; then
echo "#ot${ot}i${i} { background-color: #d3d7cf; }"
else
echo "#ot${ot}i${i} { background-color: #73d216; }"
fi
done
echo
done