mc_icinga2 / icinga functions

The first level of subdictionaries is for distinguish configuration files. There is one subdictionary per configuration file. The key used for subdictionary correspond to the name of the file but the ”.” is replaced with a “_”

The subdictionary “modules” contains a subsubdictionary for each module. In each module subdictionary, there is a subdictionary per file. The key “enabled” in each module dictionary is for enabling or disabling the module.

The “nginx” and “uwsgi” sub-dictionaries are given to macros in **kwargs parameter.

The key “package” is for listing packages installed between pre-install and post-install hooks

The keys “has_pgsql” and “has_mysql” determine if a local postgresql or mysql instance must be installed. The default value is computed from default database parameters If the connection is made through a unix pipe or with the localhost hostname, the booleans are set to True.

mc_states.modules.mc_icinga2.add_notification(attrs, notification_list=None, default_notifiers=None, is_service=None, is_host=None)

Add a basic per-mail notification If you want that a notification becomes the default one, just set vars.default_email_notification: true in your notification object definition

mc_states.modules.mc_icinga2.format(dictionary, quote_keys=False, quote_values=True, init=True)

function to transform all values in a dictionary in string and adding quotes. The main goal is to print values with quotes like “value” but we don’t want print list with quotes like “[v1, v2]”. This should be [“v1”, “v2”] this can be done in jinja template but the template is already complex

mc_states.modules.mc_icinga2.get_settings_for_object(target=None, obj=None, attr=None)

expand the subdictionaries which are not cached in mc_icinga2.settings.objects

mc_states.modules.mc_icinga2.load_objects(core=True, ttl=120)

function to load extra icinga settings from pillar

they contains the objects definitions to add in icinga2

Idea is to use them differently not to use all the RAM in cache for the states construction.

the autoconfigured_hosts_definitions dictionary contains the definitions of hosts created with the configuration_add_auto_host macro

the objects_definitions dictionary contains the defintinions of objects created with the configuration_add_object_macro

the purges list contains the files to delete

the “notification” and “parents” are under “attrs” but in fact it creates other objects like HostDependency or Notification

example:

icinga2_definitions:
   autoconfigured_hosts:
    localhost:
      hostname: "localhost"
      attrs:
        address: 127.0.0.1
        display_name: "localhost"
      ssh: true
      services_attrs:
        web:
          www.foo.com: bar
   objects:
     mycommand:
       attrs:
        parents:
          - parent1
          - parent2
        notification:
          command: "notify-by-email"
          users = ["user1"]
        command: /usr/bin/mycommand
        arguments:
          - arg: value
     name: mycommand
     file: command.conf
     type: CheckCommand
     template: false
   purges:
     - commands.conf
mc_states.modules.mc_icinga2.remove_configuration_objects()

Add the file in the file’s list to be removed

mc_states.modules.mc_icinga2.settings()

icinga2 settings

location
installation directory
package
list of packages to install icinga
has_pgsql
install and configure a postgresql service in order to be used with ido2db module
has_mysql
install and configure a mysql service in order to be used with ido2db module
user
icinga user
group
icinga group
cmdgroup
group for the command file
pidfile
file to store icinga2 pid
niceness
priority of icinga process
configuration_directory
directory to store configuration
objects
dictionary to configure objects
directory
directory in which objects will be stored. The directory should be listed in “include_recursive” values
icinga_conf
include
list of configuration files quotes have to be added for real directories
include_recursive
list of directory containing files configuration
constants_conf
values for constants conf
zones_conf
values for zones conf
modules
perfdata
enabled
enable the perfdata module
livestatus
enabled
enable the livestatus module
ido2db
enabled
enable the ido2db module