Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added complex business rules expansion #996

Merged
merged 5 commits into from Oct 14, 2013

Conversation

Projects
None yet
3 participants
@geektophe
Copy link
Contributor

geektophe commented Sep 18, 2013

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

As of hosts expansion in business rules introduced in #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
  • l label expansion: expands to hosts which have the label in theirbusiness_rule_labels attribute

Service expansion flags are:

  • g servicegroup expansion: expands the servicegroup content
  • r regex expansion: expands to services which service_description matches the regex
  • l label expansion: expands to services which have the label in theirbusiness_rule_labels 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_labels           label_01
  ...
}

define host{
  host_name                      test_host_02
  hostgroups                     hostgroup_01
  business_rule_labels           label_01
  ...
}

define service{
  hostgroup_name                 hostgroup_01
  service_description            srv1
  servicegroups                  servicegroup_01
  business_rule_labels           label_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],l:label_02
  • g:hostgroup_01,r:srv[1]
  • l:label_01,r:srv[1]

Also fixed some minor bugs, and fixed some typos.

geektophe added some commits Sep 11, 2013

Refactored dependencynode.py file.
Splitted long methods into smaller ones with smaller context to enhance
readability, maintenance, and to ease futur features integration.
Implemented complex business rules expansion
Business rules can now accept expansion expression on both host and service
items parts, allowing to write complex expnasion expression.

Expansion is now implemented using a filter based search allowing to
easily extend expansion criteria types.
@naparuba

This comment has been minimized.

Copy link
Owner

naparuba commented Sep 24, 2013

I'm in holidays with a poor internet connexion, but I'll give a close look
at soon as I'm back :)

On Wed, Sep 18, 2013 at 9:55 PM, Christophe Simon
notifications@github.comwrote:

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

As of hosts expansion in business rules introduced in #956#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_descriptionmatches 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.

You can merge this Pull Request by running

git pull https://github.com/geektophe/shinken bp_rule_service_tag

Or view, comment on, or merge it at:

#996
Commit Summary

  • Refactored dependencynode.py file.
  • Implemented complex business rules expansion
  • Fixed a bug in business rule output processing.
  • Added tags expansion to hosts and fixed some typos

File Changes

  • M shinken/dependencynode.pyhttps://github.com//pull/996/files#diff-0(487)
  • M shinken/objects/host.pyhttps://github.com//pull/996/files#diff-1(2)
  • M shinken/objects/item.pyhttps://github.com//pull/996/files#diff-2(16)
  • M shinken/objects/schedulingitem.pyhttps://github.com//pull/996/files#diff-3(6)
  • M shinken/objects/service.pyhttps://github.com//pull/996/files#diff-4(2)
  • M shinken/util.pyhttps://github.com//pull/996/files#diff-5(120)
  • M test/etc/business_correlator_expand_expression/hosts.cfghttps://github.com//pull/996/files#diff-6(2)
  • A test/etc/business_correlator_expand_expression/servicegroups.cfghttps://github.com//pull/996/files#diff-7(7)
  • M test/etc/business_correlator_expand_expression/services.cfghttps://github.com//pull/996/files#diff-8(220)
  • M
    test/etc/business_correlator_expand_expression/services_broken.cfghttps://github.com//pull/996/files#diff-9(18)
  • M test/etc/nagios_business_correlator_expand_expression.cfghttps://github.com//pull/996/files#diff-10(1)
  • M test/test_business_correlator_expand_expression.pyhttps://github.com//pull/996/files#diff-11(90)
  • M test/test_properties_defaults.pyhttps://github.com//pull/996/files#diff-12(2)

Patch Links:

@geektophe

This comment has been minimized.

Copy link
Contributor Author

geektophe commented Sep 24, 2013

So you're forced to have a break, what a pity... ;)

Enjoy your holidays :)

@ghost ghost assigned naparuba Oct 14, 2013

naparuba added a commit that referenced this pull request Oct 14, 2013

Merge pull request #996 from geektophe/bp_rule_service_tag
Added complex business rules expansion

@naparuba naparuba merged commit 376df0c into naparuba:master Oct 14, 2013

@naparuba

This comment has been minimized.

Copy link
Owner

naparuba commented Oct 14, 2013

Thanks a lot for this huge work :)

@geektophe geektophe deleted the geektophe:bp_rule_service_tag branch Oct 14, 2013

@DessaiImrane

This comment has been minimized.

Copy link
Contributor

DessaiImrane commented Feb 27, 2014

Hi,
I know it is an old PR but I have a question
How this bp_rule will be expand ?

(l:fw-site,BP-eth0 | (l:fw-site,BP-eth1 & l:fw-site,BP-tun0) )

into :

(host-A,BP-eth0 | (host-A,BP-eth1 & host-A,BP-tun0) )  
&
(host-B,BP-eth0 | (host-B,BP-eth1 & host-B,BP-tun0) )  

or

(
  ( HOST-A,BP-eth0 & HOST-B,BP-eth0 ) 
    | 
  ( 
      (HOST-A,BP-eth1 & HOST-B,BP-eth1)
      & 
       (HOST-A,BP-tun0 & HOST-B,BP-tun0
  ) 

)

Of course, it is the first one that i'm interested in :p

If it is not the case, is there a way of doing the fisrt case ? (like a duplicate_foreach in bp rule)

@geektophe

This comment has been minimized.

Copy link
Contributor Author

geektophe commented Feb 28, 2014

Sorry for the delay.

It would be expanded as your second statement:

(
  (HOST-A,BP-eth0 & HOST-B,BP-eth0)
  |
  (
    (HOST-A,BP-eth1 & HOST-B,BP-eth1)
    &
    (HOST-A,BP-tun0 & HOST-B,BP-tun0)
  )
)

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.