Using regex host matches in service definitions

Andreas Ericsson ae at op5.se
Wed Aug 24 18:00:17 CEST 2005


Dominic J. Eidson wrote:
> 
> According to the documentation's section on "Time-Saving Tricks For 
> Object Definitions" - I can use regular expressions to specify which 
> hosts to apply a service to, if I enable the option use_regexp_matching.
> 
> The example they give at 
> http://nagios.sourceforge.net/docs/2_0/templatetricks.html - is as follows:
> 
> All Hosts: If you want to create identical services that are assigned to 
> all hosts that are defined in your configuration files, you can use a 
> wildcard in the host_name directive as follows:
> 
>     define service{
>         host_name        *
>         service_description    SOMESERVICE
>         other service directives ...
>         }
> 
> 
> When I configure this in nagios-2.04b4, I get the following:
> 
> # grep 'regex' nagios.cfg
> # Values: 1 = enable regexp matching, 0 = disable regexp matching
> use_regexp_matching=1
> # (* and ?).  If the option is ENABLED, regexp matching occurs
> use_true_regexp_matching=0
> 

Wildcard matching and regexes are two quite different things. man 
regex(7) and man fnmatch(3) and glob(7) for more info on differences. 
Nagios does only regex matching (the basic POSIX kind), so you need a 
proper regular expression for it to work.

> # less services.cfg
> 
> .. skip template def. ..
> 
> define service {
>         use                             generic-service
>         host_name                       *

Change this to
    host_name  ^.*$
and you'll be good to go.
    host_name .*
would also work, but that would parse a lot slower when matching.

>         name                            ping
>         service_description             PING
>         is_volatile                     0
>         check_period                    24x7
>         max_check_attempts              3
>         normal_check_interval           5
>         retry_check_interval            1
>         contact_groups                  unix-admins
>         notification_interval           240
>         notification_period             24x7
>         notification_options            c,r
>         check_command                   check_ping!170.0,30%!900.0,100%
> }
> 
> # bin/nagios -v etc/nagios.cfg
> 
> Nagios 2.0b4
> Copyright (c) 1999-2005 Ethan Galstad (http://www.nagios.org)
> Last Modified: 08-02-2005
> License: GPL
> 
> Reading configuration data...
> 
> Error: Could not find any host matching '*'
> Error: Could not expand hostgroups and/or hosts specified in service 
> (config file '/usr/local/nagios/etc/services.cfg', starting on line 39)
> 
> Does this mean that the regex matching is broken in the current release 
> of nagios? We'll have several services/hostgroups that include hundreds 
> (if not thousands) of objects, and it would be very benefitial to just 
> use regexp matching, instead of having to list all members of a service 
> (or hostgroup).
> 
> 
>  - d.
> 

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Lead Developer


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list