1 |
dpavlin |
1 |
#!/bin/bash |
2 |
|
|
|
3 |
|
|
config_file="$1" |
4 |
|
|
|
5 |
|
|
if test -z "$config_file" |
6 |
|
|
then |
7 |
|
|
echo "Syntax: snmp.sh <config>" |
8 |
|
|
exit |
9 |
|
|
fi |
10 |
|
|
|
11 |
|
|
if ! test -e "$config_file" |
12 |
|
|
then |
13 |
|
|
echo "Warning: configuration file '$config_file' does not exist!" |
14 |
|
|
exit |
15 |
|
|
fi |
16 |
|
|
|
17 |
|
|
if ! test -s "$config_file" |
18 |
|
|
then |
19 |
|
|
echo "Warning: configuration file '$config_file' is empty!" |
20 |
|
|
exit |
21 |
|
|
fi |
22 |
|
|
|
23 |
|
|
egrep -v '^\s*[#;]' "$config_file" | while read host community version port |
24 |
|
|
do |
25 |
|
|
if test -z "$community" |
26 |
|
|
then |
27 |
|
|
community="public" |
28 |
|
|
fi |
29 |
|
|
|
30 |
|
|
if test -z "$version" |
31 |
|
|
then |
32 |
|
|
version="2c" |
33 |
|
|
fi |
34 |
|
|
|
35 |
|
|
if test -z "$port" |
36 |
|
|
then |
37 |
|
|
port="161" |
38 |
|
|
fi |
39 |
|
|
|
40 |
|
|
if test -n "$host" |
41 |
|
|
then |
42 |
|
|
temp="/tmp/snmp-$host-$port-$$" |
43 |
|
|
echo "Probing '$host' [community=$community, version=$version, port=$port] ..." |
44 |
|
|
rrd-client.pl -q -s "$host" -c "$community" -V "$version" -P "$port" > "$temp" |
45 |
|
|
cat "$temp" | rrd-server.pl -u "$host" |
46 |
|
|
rm -f "$temp" |
47 |
|
|
fi |
48 |
|
|
done |
49 |
|
|
|