Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to have a host in Nagios use multiple templates?

I'm trying to monitor some MSSQL servers. Some of these are standalone single servers with a single instance, and others are using MSCS to form 2-node HA clusters.

The things I want to monitor on a particular server are different to the things I want to monitor for a particular SQL instance. e.g. I want to use a template windows-server to tell me generic things about windows for a given server. Similarly, I'd want to use a specific SQL template called sql-instance to monitor SQL-specific things, like connected users, batch requests etc.

For my 2 node clusters, this is quite easy - I have three host definitions: a windows-server for each specific node and a sql-instance pointing at the cluster dns name.

For single instances, I'd like to be able to have a single host, which uses both the windows-server and sql-instance templates together, because they both should point at the same hostname. However, any attempts to do:

define host {
    use windows-server, sql-instance
}

or

define host {
    use windows-server
    use sql-instance
}

results in nagios only picking up one of the templates and ignoring the other.

So how best can I do multiple template inheritance in Nagios?

share|improve this question

7 Answers 7

up vote 1 down vote accepted

I solved this by using a workaround. Instead of having a particular host inherit from multiple templates, I attached my services to various hostgroups and just placed each host in more than one hostgroup:

define host {
    use             generic-host
    hostgroups      sql-servers,sql-instances
 }
share|improve this answer
    
Could you please mark this answer as the accepted answer for other people to benefit? –  Bart De Vos Jun 21 '11 at 21:59
1  
I can in 11 hours :) –  growse Jun 21 '11 at 22:12

How about having one template inherit from the other? That's how I do it on my nagios. You can put use windows-server in the sql-instance server template definition, and then anything that uses the sql-instance definition will also inherit the windows-server definition. In this case you may also want to rename sql-instance to win-sql-instance.

share|improve this answer
    
Yes. See example I posted. –  dmourati Jun 21 '11 at 3:09

So far I remember, you'll need to redeclare define host{} every time you have a new host.

Something like that:

define host{
   use             windows-server
   host_name       lan
   alias           lan
   address         WWW.XXX.YYY.ZZZ
}

define host{
   use             sql-instance
   host_name       lan
   alias           lan
   address         WWW.XXX.YYY.ZZZ
}

Hope this will help you.

ps : I can you onto my nagios config file if you want.

share|improve this answer
    
Unfortunately, that gives me a "Duplicate definition found for host 'hostname'" error. –  growse Jun 20 '11 at 10:32
    
In looking in my nagios, I remembered that I create .cfg for every servers I monitore. DHCP.cfg with define host{use windows-server} in, and so on. Try creating different .cfg and put your define host in them. –  Anarko_Bizounours Jun 20 '11 at 11:20

I tried this in my Icinga-environment and it works for Icinga:

define host {
                host_name                             Testhost
                address                               192.168.220.1
                check_command                         check-host-alive
                notification_interval                 15
                notification_options                  d,u,r
                max_check_attempts                    3
                active_checks_enabled                 1
                passive_checks_enabled                0
                notifications_enabled                 1
                check_period                          24x7
                notification_period                   24x7
                contact_groups                        admins
                parents                               Email Prim,Source
                use                                   Default_timeperiod_interval_1,Default_timeperiod_interval_10
}

I'm not sure about Nagios, but it shouldn't be too different.

share|improve this answer

in my nagios cfg files all references that have multiple entries for "use template template1,template2" have no spaces in between the first template the comma and the second template. i added a space before the second template and nagios complained :

Error: Template ' template_name' specified in host definition could not be not found (config file '/usr/local/nagios/etc/objects/hosts.cfg'
share|improve this answer

Define sql-instance as a host template that in turn uses windows-server as a template.

define host{
        name                    windows-server  ; The name of this host template
        use                     generic-host    ; Inherit default values from the generic-host template
        check_period            24x7            ; By default, Windows servers are monitored round the clock
        check_interval          5               ; Actively check the server every 5 minutes
        max_check_attempts      10              ; Check each server 10 times (max)
        check_command           check-host-alive        ; Default command to check if servers are "alive"
        notification_period     24x7            ; Send notification out at any time - day or night
        notification_interval   30              ; Resend notifications every 30 minutes
        notification_options    d,r             ; Only send notifications for specific host states
        contact_groups          admins          ; Notifications get sent to the admins by default
        hostgroups              windows-servers ; Host groups that Windows servers should be a member of
        register                0               ; DONT REGISTER THIS - ITS JUST A TEMPLATE
        }

define host{
        name                    sql-instance    ; The name of this host template
        use                     windows-server  ; Inherit default values from the 
        register                0
        }

Then, in your actual host definition, just use sql-instance and set register 1.

share|improve this answer
    
Unfortunately, this means that Nagios will try to monitor host-specific things (CPU load, disk space) about a virtual cluster name, which I don't want it to do. –  growse Jun 21 '11 at 8:10
    
I don't think that is true. Test it and find out. –  dmourati Jun 21 '11 at 16:40
    
Unless I'm misunderstanding what growse is saying, it's not at all true. It will monitor those things under the name of the host. –  James Jun 29 '11 at 17:21

As of 3.x, Nagios supports the syntax from your first example out of the box:

define host {
  use windows-server,sql-instance
}

See the section "Precedence With Multiple Inheritance Sources" in http://nagios.sourceforge.net/docs/3_0/objectinheritance.html, and "Object Inheritance" in the changelog.

(I would have added this as a comment to the accepted answer, but do not have the required reputation to do so)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.