this is obsolete doc -- see http://doc.nethence.com/ instead

Setting up Nagios service checks 

 

Defining hosts and services 

Eventually use this script to prepare several hosts at once, 

  vi scmake.ksh 

like, 

#!/bin/ksh 

set -e 

 

[[ -z $1 ]] && print missing hostname as argument && exit 1 

 

host=$1 

hostip=`host $host` 

ip=`echo $hostip | awk '{print $NF}'` 

 

cat <<EOF 

define host { 

use generic-host 

host_name $host 

alias none 

address $ip 

 

define service { 

use generic-service 

host_name $host 

service_description Ping 

check_command check_ping!100.0,20%!500.0,60% 

 

define service{ 

use generic-service 

host_name $host 

service_description SSH 

check_command check_ssh 

 

EOF 

 

unset host hostip ip 

 

And execute it e.g., 

  vi hostlist 

  while read line; do ./scmake.ksh $line; done < hostlist >> /etc/nagios/conf.d/hosts.cfg 

 

HTTP methods 

Either use the default commands, 

  less /etc/nagios-plugins/config/http.cfg 

or make your own ones, 

  cd /etc/nagios/ 

  #cd /etc/nagios3/ 

  vi commands.cfg 

like, 

# HTTP methods 

define command{ 

command_name check_http_port 

command_line /usr/lib/nagios/plugins/check_http -H '$HOSTADDRESS$' -I '$HOSTADDRESS$' -p $ARG1$ 

 

define command{ 

command_name check_https_port 

command_line /usr/lib/nagios/plugins/check_http -S -H $HOSTADDRESS$ -I '$HOSTADDRESS$' -p $ARG1$ 

#command_line $USER1$/check_http -S -H $HOSTADDRESS$ -p $ARG1$ 

 

Then use the command in the hosts config, e.g. http, 

  cd /etc/nagios/conf.d/ 

define service { 

use generic-service 

host_name HOSTNAME 

service_description HTTP 9200 

check_command check_http_port!9200 

or https, 

define service { 

use generic-service 

host_name HOSTNAME 

service_description HTTPS 9443 

check_command check_https_port!9443 

 

Custom scripts 

Write your plugin e.g., 

  cd /usr/lib/nagios/plugins/ 

  vi check_elastic 

like, 

#!/bin/ksh 

set -e 

 

[[ -z $1 ]] && print argument missing -- hostname to check && exit 1 

 

output=`curl --connect-timeout 3 -sS "http://$1.example.local:9200/_cat/nodes?v=true"` 

eahosts=`echo "$output" | grep ^ea- | awk '{print $1}'` 

 

if (( `echo "$eahosts" | wc -l` == 3 )); then 

print OK - cluster up 

exit 0 

elif (( `echo "$eahosts" | wc -l` == 2 )); then 

print WARNING - node missing 

exit 1 

else 

print FAILED - cluster down 

exit 2 

fi 

 

unset eahosts output 

 

Define the command, 

cd /etc/nagios/ 

vi commands.cfg 

like, 

define command{ 

command_name check_elastic 

command_line /usr/lib/nagios/plugins/check_elastic $HOSTADDRESS$ 

 

Define the service, 

cd /etc/nagios/conf.d/ 

vi hosts.cfg 

like, 

define service { 

use generic-service 

host_name target_server 

service_description elastic cluster 

check_command check_elastic