2011-06-15 22:18:50 +02:00
|
|
|
#!/bin/bash
|
2010-11-07 18:59:13 +01:00
|
|
|
|
|
|
|
|
2011-06-15 22:18:50 +02:00
|
|
|
IPS=`fping -a -g $1 2>/dev/null`
|
2010-11-07 18:59:13 +01:00
|
|
|
if [ $? -gt 2 ]; then
|
|
|
|
echo failed to run fping
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#addgroup --group misc --alias "Misc hosts"
|
|
|
|
|
2011-06-15 22:18:50 +02:00
|
|
|
check_port() {
|
|
|
|
hostname=$1
|
|
|
|
port=$2
|
|
|
|
check_tcp -H $hostname -p $port > /dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
is_windows() {
|
|
|
|
hostname=$1
|
|
|
|
check_port $hostname 3389 > /dev/null 2>&1
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
is_linux() {
|
|
|
|
hostname=$1
|
|
|
|
check_port $hostname 22
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-07 18:59:13 +01:00
|
|
|
for ip in $IPS; do
|
2011-06-15 22:18:50 +02:00
|
|
|
|
|
|
|
# Check if ip is just fping garbage output
|
|
|
|
echo $ip | grep -Eq '\[|\]'
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2010-11-07 18:59:13 +01:00
|
|
|
# Check if this host already exists
|
2011-06-15 22:18:50 +02:00
|
|
|
|
|
|
|
grep -qw "$ip" /var/log/nagios/objects.cache > /dev/null 2>&1
|
2010-11-07 18:59:13 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
RES=`host $ip`
|
|
|
|
if [ $? -gt 0 ]; then
|
|
|
|
HOSTN=$ip
|
|
|
|
else
|
2010-11-08 22:23:13 +01:00
|
|
|
HOSTN=`echo $RES | head -n 1 | sed 's/.*name pointer //' | sed 's/\.$//'`
|
2010-11-07 18:59:13 +01:00
|
|
|
fi
|
2011-06-15 22:18:50 +02:00
|
|
|
echo $ip = $HOSTN `is_windows $HOSTN` `is_linux $HOSTN`
|
|
|
|
#addhost --host $HOSTN --ip $ip --group misc --templates autodiscover
|
2010-11-07 18:59:13 +01:00
|
|
|
done
|
|
|
|
|
2011-06-15 22:18:50 +02:00
|
|
|
|
|
|
|
|