how do i set up my service dependency correctly?

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
mliebherr
Posts: 6
Joined: Sat Mar 21, 2015 10:06 am

how do i set up my service dependency correctly?

Post by mliebherr »

Hello,

this is my test case. In my real world i have a few linux boxes and some active checks which uses ssh. If the ssh daemon fails, i get also notified for all the other dozend services which USE ssh.

Now i would like to define a Host Group and Assign Services to it. Here we go:
====================================================================================

Code: Select all



## Host definition.
# This is a normal linux box
define host{
        use                     ha-linux-server
        host_name               MarioTest
        address                 mario.example.com
        hostgroups              basic_linux_server
        }


# Define Hostgroup

define hostgroup{
        hostgroup_name  basic_linux_server
        }




## check disk by ssh
define service{
        use                             TLS_ha-generic-service
        service_description             Basic Linux Service Disk Check
        check_command                   TLS_check_disk_by_ssh!15%!10%!-x /backup!
        hostgroup                       basic_linux_server
        servicegroups                   ssh_driven_checks
        }

# check ssh service itself
define service{
        use                             TLS_ha-generic-service         ; Name of service template to use
        service_description             Basic Linux Service SSH Check
        check_command                   TLS_check_ssh
        hostgroup                       basic_linux_server
        normal_check_interval           1
        retry_check_interval            1
        }



define servicegroup{
        servicegroup_name               ssh_driven_checks
        alias                           ssh_driven_checks
        }

#
# => this seems to the problem!!!!
# If the „Basic Linux Service SSH Check“ fails, the other checks which use ssh should be ignored
#
# => in this config i still get notifications for the disk service if ssh fails
define servicedependency{
        service_description             Basic Linux Service SSH Check
        dependent_servicegroup_name     ssh_driven_checks
        execution_failure_criteria      w,u,c
        notification_failure_criteria   w,u,c
}




# commands
define command{
        command_name    TLS_check_disk_by_ssh
        command_line    openssh root@$HOSTADDRESS$ "/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -x /dev -x /proc $ARG3$"
        }

define command{
        command_name    TLS_check_ssh
        command_line    $USER1$/check_ssh $ARG1$ $HOSTADDRESS$
        }



# templates
define host{
        name                            TLS_ha-linux-server    ; The name of this host template
        use                             generic-host    ; This template inherits other values from the generic-host template
        check_period                    24x7            ; By default, Linux hosts are checked round the clock
        check_interval                  2               ; Actively check the host every 5 minutes
        retry_interval                  1               ; Schedule host check retries at 1 minute intervals
        max_check_attempts              3               ; Check each Linux host 10 times (max)
        check_command                   check-host-alive ; Default command to check Linux hosts
        notification_period             24x7            ; Linux admins hate to be woken up, so we only notify during the day
                                                        ; Note that the notification_period variable is being overridden from
                                                        ; the value that is inherited from the generic-host template!
        notification_interval           30              ; Resend notifications every 2 hours
        notification_options            d,r           ; Only send notifications for specific host states
        contact_groups                  TLS_admins-email, TLS_admins-sms
        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        icon_image                      dot.png' alt="" border="0"></a><A TARGET="_blank" HREF="graphs.cgi?host=$HOSTNAME$&service=check-host-alive"><img src="/nagios/images/logos/graph.png"

        }


define service{
        name                            TLS_ha-generic-service         ; The 'name' of this service template
        active_checks_enabled           1                       ; Active service checks are enabled
        passive_checks_enabled          1                       ; Passive service checks are enabled/accepted
        parallelize_check               1                       ; Active service checks should be parallelized (disabling this can lead to major performance problems)
        obsess_over_service             1                       ; We should obsess over this service (if necessary)
        check_freshness                 0                       ; Default is to NOT check service 'freshness'
        notifications_enabled           1                       ; Service notifications are enabled
        event_handler_enabled           1                       ; Service event handler is enabled
        flap_detection_enabled          0                       ; Flap detection is enabled
        failure_prediction_enabled      1                       ; Failure prediction is enabled
        process_perf_data               1                       ; Process performance data
        retain_status_information       1                       ; Retain status information across program restarts
        retain_nonstatus_information    1                       ; Retain non-status information across program restarts
        is_volatile                     0                       ; The service is not volatile
        check_period                    24x7                    ; The service can be checked at any time of the day
        max_check_attempts              5                       ; Re-check the service up to 3 times in order to determine its final (hard) state
        normal_check_interval           2                      ; Check the service every 10 minutes under normal conditions
        retry_check_interval            2                       ; Re-check the service every two minutes until a hard state can be determined
        contact_groups                  TLS_admins-email, TLS_admins-sms
        notification_options            w,u,c,r                 ; Send notifications about warning, unknown, critical, and recovery events
        notification_interval           30                     ; Re-notify about service problems every hour
        notification_period             24x7                    ; Notifications can be sent out at any time
         register                        0                      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }


Why does the dependency not work? Why do i get notified for all related services?

Thanks a lot,
Mario
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: how do i set up my service dependency correctly?

Post by Box293 »

The host and service that is being "depended on" (master host/service) needs to be defined and then so does the "dependent host(s)/service(s)" (the ones that rely on the master).

Here's a simpler configuration to get you started:

Code: Select all

define servicedependency{
	host_name						MarioTest
	service_description			    Basic Linux Service SSH Check
	dependent_host_name				MarioTest
	dependent_servicegroup_name     ssh_driven_checks
	execution_failure_criteria      w,u,c
	notification_failure_criteria   w,u,c
}
Does this make sense?

http://nagios.sourceforge.net/docs/3_0/ ... dependency
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
mliebherr
Posts: 6
Joined: Sat Mar 21, 2015 10:06 am

Re: how do i set up my service dependency correctly?

Post by mliebherr »

Well, that sucks :-P

I have a lot of linux machines. And i do a lot of active checks by ssh.

How else could i solve it to keep my configuration simple?

If i have 100 Hosts with 10 active by ssh checks, then i would have to define:

100x10 = 1000 Serice dependency definitions?

Is there a waay to but the active checks into a group. And all those services in that group should depend on the ssh check?
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: how do i set up my service dependency correctly?

Post by jdalrymple »

I *think* this is your ticket:

Code: Select all

 Same Host Dependencies:
If you want to create service dependencies for multiple services that are dependent on services on the same host, leave the dependent_host_name and dependent_hostgroup_name directives empty. The example below assumes that hosts HOST1 and HOST2 have at least the following four services associated with them: SERVICE1, SERVICE2, SERVICE3, and SERVICE4. In this example, SERVICE3 and SERVICE4 on HOST1 will be dependent on both SERVICE1 and SERVICE2 on HOST1. Similiarly, SERVICE3 and SERVICE4 on HOST2 will be dependent on both SERVICE1 and SERVICE2 on HOST2.


	define servicedependency{

		host_name			HOST1,HOST2

		service_description		SERVICE1,SERVICE2

		dependent_service_description	SERVICE3,SERVICE4

		other dependency directives ...

		}

mliebherr
Posts: 6
Joined: Sat Mar 21, 2015 10:06 am

Re: how do i set up my service dependency correctly?

Post by mliebherr »

Hm...i dont think this is what i want. This will get very complex with a few hosts and services.

Lets try it the other way round: How would you write a nagios configuration for this:

Hosts:
----------
- Host A (just a SSH Box)
- Host B (Linux Webserver)
- Host C (Linux Webserver)
- Host D (Linux Mailserver)
- Host E (Linux Mailserver)


Services:
---------------
- SSH
- HTTP
- HTTPs
- SMTP
- Disk Free (by ssh)
- Free Memory (by ssh)
- Processes (by ssh)
- Load (by ssh)



Can i not just create the Service Groups with its dependencies?:
----------------------------------------------------------------------------------
1.) Basic Linux Services (such as SSH, Disk Free, Free Mem, Proccesses, Load)
2.) Webserver Services (additional to Basic Linux Services + HTTP + HTTPs)
3.) Mailserver Services (additional to Basic Linux Services + SMTP)


Maybe i am asking too much for Nagios here. :-/
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: how do i set up my service dependency correctly?

Post by jdalrymple »

What about this misses the mark, you're just worried about all your services being dependent upon sshd because you're using check_by_ssh right?

Code: Select all

define servicedependency{
      hostgroup_name         webhosts
      service_description      ssh
      dependent_service_description   disk,swap,httpd,mysql
      other dependency directives ...
      }
	  
define servicedependency{
      hostgroup_name         mailhosts
      service_description      ssh
      dependent_service_description   disk,swap,postfix,imapd
      other dependency directives ...
      }	  
Not tested in my lab - if you need me to though I can build it up.
mliebherr
Posts: 6
Joined: Sat Mar 21, 2015 10:06 am

Re: how do i set up my service dependency correctly?

Post by mliebherr »

that helped me a lot!

Thanks!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: how do i set up my service dependency correctly?

Post by tmcdonald »

Are we all set to close this?
Former Nagios employee
mliebherr
Posts: 6
Joined: Sat Mar 21, 2015 10:06 am

Re: how do i set up my service dependency correctly?

Post by mliebherr »

Yes. Thank you
Locked