是否有可能在Nagios有一个主机使用多个模板?
我试图监视一些MSSQL服务器。 其中一些是具有单个实例的独立单一服务器,另一些则使用MSCS形成双节点HA群集。
我想在特定服务器上监视的事情与我想要监视特定SQL实例的事情不同。 例如,我想使用一个模板windows-server来告诉我有关给定服务器的Windows的一般事情。 同样,我想要使用一个名为sql-instance的特定SQL模板来监视特定于SQL的事情,如连接用户,批量请求等。
对于我的2个节点集群,这很容易 – 我有三个主机定义:每个特定节点的一个windows-server和一个指向集群DNS名称的sql-instance 。
对于单个实例,我希望能够有一个主机,它同时使用windows-server和sql-instance模板,因为它们都应该指向相同的主机名。 但是,任何尝试做:
define host { use windows-server, sql-instance }
要么
define host { use windows-server use sql-instance }
导致nagios只拾取其中一个模板而忽略另一个模板。
那么如何在Nagios中做到多重模板inheritance呢?
我通过使用解决方法解决了这个问题。 我没有从多个模板inheritance特定的主机,而是将我的服务连接到不同的主机组,并将每个主机放在多个主机组中:
define host { use generic-host hostgroups sql-servers,sql-instances }
如何让一个模板从另一个模板inheritance? 这就是我在我的老虎机上做的事情。 你可以在sql-instance服务器模板定义中use windows-server ,然后任何使用sql-instance定义的东西也将inheritancewindows-server的定义。 在这种情况下,您可能还想将sql-instance重命名为win-sql-instance。
到目前为止,我记得,每当你有一个新的主机时,你都需要重新定义host {}。
类似的东西:
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 }
希望这会帮助你。
ps:如果你愿意的话,我可以把你放到我的nagiosconfiguration文件中。
我在我的Icinga环境中尝试过这个方法,它适用于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 }
我不确定Nagios,但它不应该太相同。
在我的nagios cfg文件中,具有多个“use template template1,template2”条目的所有引用在第一个模板的逗号和第二个模板之间没有空格。 我在第二个模板之前加了一个空格,nagios抱怨道:
Error: Template ' template_name' specified in host definition could not be not found (config file '/usr/local/nagios/etc/objects/hosts.cfg'
将sql-instance定义为主机模板,然后使用windows-server作为模板。
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 }
然后,在你的实际主机定义中,只需use sql-instance并设置register 1 。
从3.x开始,Nagios支持开箱即用的第一个示例的语法:
define host { use windows-server,sql-instance }
请参阅http://nagios.sourceforge.net/docs/3_0/objectinheritance.html中的 “具有多个inheritance源的优先级”一节,以及变更日志中的“对象inheritance”。
(我会join这个作为评论接受的答案,但没有要求的声誉这样做)