aleatorvb
Dabbler
- Joined
- Nov 14, 2012
- Messages
- 10
You can monitor remote disk with nagios over ssh.
Ssh script to be copied on the freenas server, I used /mnt/pool1/users/nagios/check_diskfree.sh
Configure nagios to monitor
- using check_diskfree.sh script
- dataset /mnt/pool1
- warning at 90%, critical at 95%
Works like a charm.
Attention!
This requires having the nagios user being able to ssh to the freenas_host_ip_address with passwordless login using ssh-keys.
Create a nagios user on freenas and allow it to remotely login via ssh.
Also select a home folder for it.
Create public/private key pair
..and then copy the key to freenas (using ubuntu as example here)
.. now we're back on nagios server. To test passwordless login type
Ssh script to be copied on the freenas server, I used /mnt/pool1/users/nagios/check_diskfree.sh
Code:
case $1 in
--help | -h )
echo "Usage: check_diskfree [dev] [warn] [crit]"
echo " [warn] and [crit] as int"
echo " Example: check_diskfree hda1 70 90"
exit 3
;;
* )
;;
esac
if [ ! "$1" -o ! "$2" -o ! "$3" ]; then
echo "Usage: check_diskfree [dev] [warn] [crit]"
echo " [warn] and [crit] as int"
echo " Example: check_diskfree hda1 70 90"
echo "Unknown: Options missing"
exit 3
fi
used=`df /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \ -f3`
free=`df /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \ -f4`
full=`echo $(($used+$free))`
percent=`echo $((( $free * 100 ) / $full))`
warn=`echo $((( $full * $2 ) / 100 ))`
crit=`echo $((( $full * $3 ) / 100 ))`
if [ "$warn" -gt "$crit" -o "$warn" -eq "$crit" ]; then
echo "Unknown: [crit] must be larger than [warn]"
exit 3
fi
if [ "$used" -lt "$warn" -o "$used" -eq "$warn" ]; then
echo "OK. Free Space: `df -h /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \ -f4`B, $percent%"
exit 0
elif [ "$used" -gt "$warn" -a "$used" -lt "$crit" ]; then
echo "Warning. Free Space: `df -h /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \ -f4`B, $percent%"
exit 1
elif [ "$used" -gt "$crit" ]; then
echo "Critical. Free Space: `df -h /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \ -f4`B, $percent%"
exit 2
else
echo "Unknown"
exit 3
fi
Configure nagios to monitor
- using check_diskfree.sh script
- dataset /mnt/pool1
- warning at 90%, critical at 95%
Code:
define service{
use local-service
host_name freenas_host_name
service_description Disk Usage
check_command check_by_ssh!22!/mnt/pool1/users/nagios/check_diskfree.sh!mnt/pool1!90!95$
max_check_attempts 3
check_interval 5
retry_interval 3
check_period 24x7
}
Works like a charm.
Attention!
This requires having the nagios user being able to ssh to the freenas_host_ip_address with passwordless login using ssh-keys.
Create a nagios user on freenas and allow it to remotely login via ssh.
Also select a home folder for it.
Create public/private key pair
Code:
# login to nagios server with the nagios user cd ~ mkdir .ssh chmod -R 700 .ssh cd .ssh ssh-keygen -t rsa # do not enter any password if you want passwordless login
..and then copy the key to freenas (using ubuntu as example here)
Code:
ssh-copy-id freenas_host_ip #enter password exit exit
.. now we're back on nagios server. To test passwordless login type
Code:
ssh freenas_host_ip