1
0
mirror of https://github.com/opinkerfi/nagios-plugins.git synced 2024-09-28 16:33:46 +02:00

Errors now sent to stderr instead of stdout

This commit is contained in:
Pall Sigurdsson 2011-06-15 20:18:50 +00:00
parent f8480dd9a2
commit a55e1cef84

View File

@ -1,18 +1,47 @@
#!/bin/sh #!/bin/bash
IPS=`fping -a -g $1 2>/dev/nul` IPS=`fping -a -g $1 2>/dev/null`
if [ $? -gt 2 ]; then if [ $? -gt 2 ]; then
echo failed to run fping echo failed to run fping
exit 1 exit 1
fi fi
#addgroup --group misc --alias "Misc hosts" #addgroup --group misc --alias "Misc hosts"
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 $?
}
for ip in $IPS; do for ip in $IPS; do
# Check if ip is just fping garbage output
echo $ip | grep -Eq '\[|\]'
if [ $? -eq 0 ]; then
continue
fi
# Check if this host already exists # Check if this host already exists
grep -qw $ip /var/log/nagios/objects.cache
grep -qw "$ip" /var/log/nagios/objects.cache > /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
continue continue
fi fi
@ -22,7 +51,9 @@ for ip in $IPS; do
else else
HOSTN=`echo $RES | head -n 1 | sed 's/.*name pointer //' | sed 's/\.$//'` HOSTN=`echo $RES | head -n 1 | sed 's/.*name pointer //' | sed 's/\.$//'`
fi fi
echo $ip = $HOSTN echo $ip = $HOSTN `is_windows $HOSTN` `is_linux $HOSTN`
addhost --host $HOSTN --ip $ip --group misc --templates autodiscover #addhost --host $HOSTN --ip $ip --group misc --templates autodiscover
done done