Ryre
Ryre

Reputation: 6181

How to avoid redundancy in Nagios service definitions?

I have a lot of services that are defined like this:

define service {
    use generic-service
    host_name some.host.com
    service_description Some Description 1
    check_command check_generic!some_task_1
}

define service {
    use generic-service
    host_name some.host.com
    service_description Some Description 2
    check_command check_generic!some_task_2
}
....

I would like to remove the redundant portions of each service (use generic-service and host_name some.host.com). Is there a way to globally assign these values?

Upvotes: 0

Views: 98

Answers (1)

Bruno9779
Bruno9779

Reputation: 1669

No, the grouping is done the other way around: you can assign multiple hosts to a check in the same definition, but you can only define one service per definition.

EDIT: There is an hacky way to do this. You could try to put the host name in the service template.

Something on these lines:

define service{
        name                            host1-service 
        use                             generic-service     
        host_name                       host1
        register                        0     ## this marks it as a template##                 
}

then:

define service {
    use                        host1-service
    service_description        Some Description 1
    check_command              check_generic!some_task_1
}

This is not the intended way to configure nagios with templates, I'd advise against it.

On a last note, Icinga2 (15 days from stable release) allows for conditional service and host checks declaration.

Upvotes: 1

Related Questions