First of all, sorry to put this into the wrong subsection, but I do not have enough posts yet to put this into the HOW-TO area. If people find it useful, maybe some moderator can move it there.
The purpose of this tutorial is to explain how you can setup your icinga (I'm using icinga2) host to monitor your freenas server with the help of nrpe. This how-to was created using FreeNAS-9.3-STABLE-201412090314 build. But it might work with other versions as well.
1. Collection of necessary packages
In order to install nrpe2 successfully you need the following packages. You can download them from -> http://mirror.neolabs.kz/pub/FreeBSD/ports/amd64/packages-9-stable/Latest/
scp *.tbz root@nasbox:/tmp
root@nasbox:$ pkg_add libiconv.tbz
root@nasbox:$ pkg_add gettext.tbz
root@nasbox:$ pkg_add perl5-5.16.3_6.tbz
root@nasbox:$ pkg_add nagios-plugins.tbz
root@nasbox:$ pkg_add nrpe2.tbz
3. Edit rc.conf and sudoers
root@nasbox:$ mount -uw/
root@nasbox:$ vi /conf/base/etc/rc.conf
---> add the following:
# Start nrpe2
nrpe2_enable="YES"
root@nasbox:$ vi /conf/base/etc/sudoers
---> add the following:
nagios ALL=NOPASSWD:/usr/local/libexec/nagios/
(Editing the sudoers-file is only neccessary if you want to run specific scripts with sudo permission. In my case I wanted to do so. But this has some security implications!)
4. Create nrpe-Config
root@nasbox:$ cp /usr/local/etc/nrpe.cfg.sample /etc/nrpe.cfg
---> or use my sample nrpe.cfg posted at the end of this how-to
You have to edit at least the following: allowed_hosts=%youricingahostip%
5. Add to Startup-Script in GUI
On FreeNAS-GUI add TASK -> Init/ShutdownScripts and add:
Command: /usr/local/sbin/nrpe2 -c /etc/nrpe.cfg -d
6. Customize icinga2-Config
Customize your icinga2-Hosts configs e.g.:
object Host "freenas"{
import "generic-host"
address = "192.168.0.50"
check_command = "hostalive"
}
object CheckCommand "check_nrpe_nossl" {
import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_nrpe" ]
arguments = {
"-H" = "$nrpe_address$"
"-c" = "$nrpe_command$"
"-n" = ""
}
}
object Service "Disk /" {
host_name = "freenas"
check_command = "check_nrpe_nossl"
vars.nrpe_command = "check_root"
vars.nrpe_address = "192.168.0.50"
}
In my case nrpe communication was not possible with ssl, that's why I had to use the -n option!
Hope this helps others who want to achieve similar things.
PS: You should have at least basic knowledge about freenas and icinga before doing this!
------------------------------------------------------------------------------------------------------------------
Appendix A: nrpe.cfg
[...]
command[check_users]=/usr/local/libexec/nagios/check_users -w 5 -c 10
command[check_load]=/usr/local/libexec/nagios/check_load -w 15,10,5 -c 30,25,20
command[check_root]=/usr/local/libexec/nagios/check_disk -w 20% -c 10% -p /
command[check_var]=/usr/local/libexec/nagios/check_disk -w 20% -c 10% -p /var
command[check_nas-data]=/usr/local/libexec/nagios/check_disk -w 20% -c 10% -p /mnt/%yourpoolname%
command[check_zombie_procs]=/usr/local/libexec/nagios/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/libexec/nagios/check_procs -w 150 -c 200
command[check_free_mem]=/usr/local/libexec/nagios/check_mem.pl -f -w 7 -c 2
command[check_used_mem]=/usr/local/libexec/nagios/check_mem.pl -u -w 95 -c 100
command[check_hdd1]=sudo /usr/local/libexec/nagios/check_smart_own /dev/da1
command[check_hdd2]=sudo /usr/local/libexec/nagios/check_smart_own /dev/da2
command[check_hdd3]=sudo /usr/local/libexec/nagios/check_smart_own /dev/da3
command[check_hdd4]=sudo /usr/local/libexec/nagios/check_smart_own /dev/da4
[...]
Appendix B: check_smart_own - Script:
#!/bin/bash
smart_status=`/usr/local/sbin/smartctl -H $1 | grep health | awk '{print $6}'`
case $smart_status in
("PASSED")
echo "OK - $1 status is Healthy"
exit 0
;;
("")
echo "WARNING - $1 status is EMPTY -> check script"
exit 1
;;
("FAILED")
echo "CRITICAL - $1 smart-test FAILED -> check HDD"
exit 2
;;
*)
echo "UNKNOWN - $1 status UNKNOWN -> check manually"
exit 3
;;
esac
The purpose of this tutorial is to explain how you can setup your icinga (I'm using icinga2) host to monitor your freenas server with the help of nrpe. This how-to was created using FreeNAS-9.3-STABLE-201412090314 build. But it might work with other versions as well.
1. Collection of necessary packages
In order to install nrpe2 successfully you need the following packages. You can download them from -> http://mirror.neolabs.kz/pub/FreeBSD/ports/amd64/packages-9-stable/Latest/
- nrpe2.tbb
- gettext.tbz
- nagios-plugins.tbz
- libiconv.tbz
- perl5-5.16.3_6.tbz
scp *.tbz root@nasbox:/tmp
root@nasbox:$ pkg_add libiconv.tbz
root@nasbox:$ pkg_add gettext.tbz
root@nasbox:$ pkg_add perl5-5.16.3_6.tbz
root@nasbox:$ pkg_add nagios-plugins.tbz
root@nasbox:$ pkg_add nrpe2.tbz
3. Edit rc.conf and sudoers
root@nasbox:$ mount -uw/
root@nasbox:$ vi /conf/base/etc/rc.conf
---> add the following:
# Start nrpe2
nrpe2_enable="YES"
root@nasbox:$ vi /conf/base/etc/sudoers
---> add the following:
nagios ALL=NOPASSWD:/usr/local/libexec/nagios/
(Editing the sudoers-file is only neccessary if you want to run specific scripts with sudo permission. In my case I wanted to do so. But this has some security implications!)
4. Create nrpe-Config
root@nasbox:$ cp /usr/local/etc/nrpe.cfg.sample /etc/nrpe.cfg
---> or use my sample nrpe.cfg posted at the end of this how-to
You have to edit at least the following: allowed_hosts=%youricingahostip%
5. Add to Startup-Script in GUI
On FreeNAS-GUI add TASK -> Init/ShutdownScripts and add:
Command: /usr/local/sbin/nrpe2 -c /etc/nrpe.cfg -d
6. Customize icinga2-Config
Customize your icinga2-Hosts configs e.g.:
object Host "freenas"{
import "generic-host"
address = "192.168.0.50"
check_command = "hostalive"
}
object CheckCommand "check_nrpe_nossl" {
import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_nrpe" ]
arguments = {
"-H" = "$nrpe_address$"
"-c" = "$nrpe_command$"
"-n" = ""
}
}
object Service "Disk /" {
host_name = "freenas"
check_command = "check_nrpe_nossl"
vars.nrpe_command = "check_root"
vars.nrpe_address = "192.168.0.50"
}
In my case nrpe communication was not possible with ssl, that's why I had to use the -n option!
Hope this helps others who want to achieve similar things.
PS: You should have at least basic knowledge about freenas and icinga before doing this!
------------------------------------------------------------------------------------------------------------------
Appendix A: nrpe.cfg
[...]
command[check_users]=/usr/local/libexec/nagios/check_users -w 5 -c 10
command[check_load]=/usr/local/libexec/nagios/check_load -w 15,10,5 -c 30,25,20
command[check_root]=/usr/local/libexec/nagios/check_disk -w 20% -c 10% -p /
command[check_var]=/usr/local/libexec/nagios/check_disk -w 20% -c 10% -p /var
command[check_nas-data]=/usr/local/libexec/nagios/check_disk -w 20% -c 10% -p /mnt/%yourpoolname%
command[check_zombie_procs]=/usr/local/libexec/nagios/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/libexec/nagios/check_procs -w 150 -c 200
command[check_free_mem]=/usr/local/libexec/nagios/check_mem.pl -f -w 7 -c 2
command[check_used_mem]=/usr/local/libexec/nagios/check_mem.pl -u -w 95 -c 100
command[check_hdd1]=sudo /usr/local/libexec/nagios/check_smart_own /dev/da1
command[check_hdd2]=sudo /usr/local/libexec/nagios/check_smart_own /dev/da2
command[check_hdd3]=sudo /usr/local/libexec/nagios/check_smart_own /dev/da3
command[check_hdd4]=sudo /usr/local/libexec/nagios/check_smart_own /dev/da4
[...]
Appendix B: check_smart_own - Script:
#!/bin/bash
smart_status=`/usr/local/sbin/smartctl -H $1 | grep health | awk '{print $6}'`
case $smart_status in
("PASSED")
echo "OK - $1 status is Healthy"
exit 0
;;
("")
echo "WARNING - $1 status is EMPTY -> check script"
exit 1
;;
("FAILED")
echo "CRITICAL - $1 smart-test FAILED -> check HDD"
exit 2
;;
*)
echo "UNKNOWN - $1 status UNKNOWN -> check manually"
exit 3
;;
esac