Sometimes we need to monitoring public area services, such as http, ftp. We can not install the client side agent on the public server, anyway, we can monitoring the status of them by some plugins.
Http service
1. Define the check_http command
# 'check_http' command definition define command{ command_name check_http command_line $USER1$/check_http -H $HOSTADDRESS$ $ARG1$ }
2. create a host configuration file for the webserver
cd /usr/local/nagios/etc/objects/
then create a configuration file for your webserver, I name it as test.cfg, the usl of the website is www.test.com
define host { use linux-server ; Inherit default values from a template host_name test ; The name we're giving to this host alias test ; A longer name associated with the host address xxx.xxx.xxx.xxx ; IP address of the host }
Http
define service { use generic-service ; Inherit default values from a template host_name test service_description HTTP check_command check_http!www.test.com }
If you also want to test the sub pages, eg. www.test.com/news/, use switch -u
define service { use generic-service ; Inherit default values from a template host_name au123 service_description news check_command check_http!www.test.com -u http://www.test.com/news/ }
Https
To monitor the https service, add -S
switch.
check_command check_http!www.test.com -S
Check service on different port
Use switch -p port_number
Certificate validation
You can check whether a SSL certificate of the website expires within the next X number of days with switch -C
.
check_http -H google.com -C 200
The result will be either Ok or warning.
3. Let the nagios load the configuration file
vi /usr/local/nagios/etc/nagios.cfg
Then add following lines:
# Definitions for monitoring website cfg_file=/usr/local/nagios/etc/objects/test.cfg
Reference
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/monitoring-publicservices.html