naparuba/shinken — pull request #996 by geektophe (2013-09-18 19:55:27+00:00)
Title: Added complex business rules expansion

This patch adds complex business rules expansion on hosts, services, or a combination on both.

As of hosts expansion in business rules introduced in https://github.com/naparuba/shinken/pull/956, services use flags to select expansion type with the following pattern: `flags:expression`.

Host expansion flags are:
- `g` **hostgroup expansion**: expands the `hostgroup` content
- `r` **regex expansion**: expands to hosts which `host_name` matches the regex
- `t` **tag expansion**: expands to hosts which have the tag in their`business_rule_tags` attribute

Service expansion flags are:
- `g` **servicegroup expansion**: expands the `servicegroup` content
- `r` **regex expansion**: expands to services which `service_description` matches the regex
- `t` **tag expansion**: expands to services which have the tag in their`business_rule_tags` attribute

In addition
- An empty host in an expression (looks like `,service name`) means *the host the business rule is bound to*.
- An host or a service with `*` means *any host* or *any service*

To be able to combine expansion expressions on both host and service, the `DependencyNodeFactory` class has been refactored to use closer functional scope methods for better maintainability and readability, and a filter based strategy has been implemented: each expression on host or service is represented by one or more filter callable objects used as callback. They are passed all the hosts or services, and only those having passed all of them are selected.

Examples:

With the following configuration

define host{
host_name test_host_01
hostgroups hostgroup_01
business_rule_tags tag_01
...
}

define host{
host_name test_host_02
hostgroups hostgroup_01
business_rule_tags tag_01
...
}

define service{
hostgroup_name hostgroup_01
service_description srv1
servicegroups servicegroup_01
business_rule_tags tag_02
...
}

The following business rules have exactly the same result:
- `test_host_01,srv1 & test_host_02,srv1`
- `g:hostgroup_01,srv1`
- `r:test_host_0[12],srv1`
- `*,g:servicegroup_01`
- `r:test_host_0[12],t:tag_02`
- `g:hostgroup_01,r:srv[1]`
- `t:tag_01,r:srv[1]`

Also fixed some minor bugs, and fixed some typos.