Discovery rules

General options

A discovery rule allows to dynamically create services and to link them to a host, based on the elements discovered by the probes. The created unit services will be attached to a service template so that Centreon’s functionalities can be used (inheritance, overloading and more).

To create a rule, go to Configuration > Services > Auto Discovery > Rules and click on the Add button:

../_images/create_rule_1.png

Fill the first fields:

../_images/create_rule_2.png

Here is the description of the firsts fields located inside the General tab:

  • Rule name: the rule’s name
  • Command Macro: discovery command which allow to list available XML attributes
  • Command Discover: discovery command which will be executed to enumerate the elements
  • Service template: the service template used to dynamically create new services based on the discovery

Go to the second Inclusions / Exclusions & Macros tab. You should see available XML attributes:

../_images/create_rule_3.png

Come back to the first General tab, define the Service display name and select values for the other fields:

../_images/create_rule_4.png

Note

The service name can contain a macro corresponding to an XML stream’s attribute. For example: when looking for network interfaces, the interface name will be given by the name attribute. Traffic-$name$ will be replaced by Traffic-eth0 if the interface’s name is eth0. The XML attribute’s name must be described between two $ characters. You can use many XML attributes to build the service name.

Here is the description of the other fields located inside the General tab:

  • Hosts templates: the templates used to retrieve the list of hosts for which a discovery rule should be run
  • Contacts: contacts that will be notified about creation or deactivation during a discovery
  • Contact groups: contact groups that will be notified about creation or deactivation during a discovery
  • Disable elements not found: let the module deactivate services associated to elements that cannot be found anymore
  • Activate: activate or deactivate the rule (will be ignored by the discovery process if deactivated)

Click on the Save button to save the discovery rule.

Inclusions / Exclusions & Macros

The Inclusions / Exclusions & Macros tab works as follows:

../_images/create_rule_5.png

The Inclusions / Exclusions part allows elements to be included or excluded during the discovery. This inclusion/exclusion is relative to an XML attribute.

The inclusion/exclusion rules, are defined using the following algorithm:

  • If only inclusion rules are present, the attribute’s value corresponding to at least one inclusion will be considered
  • If only exclusion rules are present, every element will be considered, except the ones corresponding to an exclusion
  • If both types are present, the process checks if the element corresponds to an inclusion and then checks if it is not listed into the exclusion list

The second part Macros allows to define matches between an XML attribute and a service’s template macro. For all created services the macros’ values will be replaced by the attributes’ values.

../_images/create_rule_6.png

Note

On the image above all macros will be created for the service because the checkbox Empty are selected. To don’t create them do not check the Empty checkbox. The $_SERVICEINTERFACEID macro created on the service will contain the value of $interfaceid from the value of XML element.

Advanced options

On the last Advanced tab you can apply a regexp on the Service display name. Click on Add a new entry button and define Pattern and expression result:

../_images/create_rule_7.png

The regexp can be apply on String field for:

  • @SERVICENAME@: The name of service will be created
  • All XML attributes defined by $attribute_name$

The second part Customize code allows to use Perl code.

Custom display scan gives you the capability to change the display of a manual scan. By default, manual scan display the service name. Here an example to add the size of the disk:

my ($value, $unit) = change_bytes(value => $total$);
$description = "<span style='color: red; font-weight: bold'>@SERVICENAME@</span> [size = <b>$value $unit</b>]";

Custom variables gives you the capability to create some custom macros. Here an example to have dynamic threshold according the disk size:

my $total_gb = $total$ / 1000 / 1000 / 1000;
if ($total_gb < 100) {
    $warning$ = 80;
    $critical$ = 90;
} elsif ($total_gb < 500) {
    $warning$ = 90;
    $critical$ = 95;
} else {
    $warning$ = 95;
    $critical$ = 98;
}

Now, you could use $warning$ and $critical$ macro in Macros part.