Define a new service in Nagios

To define a new service in Nagios you need to do the following:

1) Add the necessary commands to /etc/nagios/objects/commands.cfg
2) Define the host and service in /etc/nagios/objects/templates.cfg
3) Define a host definition in /etc/nagios/objects/.cfg

Command definition in commands.cfg

define command{
command_name check-ssl-cert
command_line $USER1$/check_ssl_certificate -H $ARG1$ -p $ARG2$ -c $ARG3$ -w $ARG4$

The command (in this case check_ssl_certificate) expects parameters to be passed like this:

Usage: check_ssl_certificates -H [-p ] [-c :] [-w :]

So the arguments are passed as: -H $ARG1$ -p $ARG2$ -c $ARG3$ -w $ARG4$
The more astute reader will notice I have ignored the : and opted to pass a single value here only.

Service definition: (in templates.cfg)

define service{
name ssl-checks
use generic-service
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
register 0

Host definition: (in templates.cfg)

define host{
name ssl-checks
use generic-host
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 4
check_command check-ssl-cert
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
hostgroups ssl-checks
register 0

You can now make use of your new service by adding it to an (or creating a new) object in /etc/nagios/servers

define service {
use ssl-checks
service_description SSL Certificate checks
check_command check-ssl-cert!!443!2!20
# check_command check_ssl_certificate -H -p 443 -c 2 -w 7
notifications_enabled 1

Step 3:
Create the ssl-checks.cfg – this is an arbitrary name.

define host{
use ssl-checks ; Inherit default values from a template
host_name winserver ; The name we're giving to this host
alias DNS Server ; A longer name associated with the host
address ; IP address of the host

define hostgroup{
hostgroup_name SSL-Checks ; The name of the hostgroup
alias SSL certificate checks ; Long name of the group

define service {
use generic-service
hostgroup_name www-servers
host_name www-server
service_description ssl-checks


admin has written 88 articles