Exemple #1
0
    def generate(self):
        save_global_settings(self._initial_global_settings())

        # A contact group for all hosts and services
        groups = {
            "contact": {
                'all': {
                    'alias': u'Everything'
                }
            },
        }
        save_group_information(groups)

        self._initialize_tag_config()

        # Rules that match the upper host tag definition
        ruleset_config = {
            # Make the tag 'offline' remove hosts from the monitoring
            'only_hosts': [
                {
                    'condition': {
                        'host_tags': {
                            'criticality': {
                                '$ne': 'offline'
                            }
                        }
                    },
                    'value': True,
                    'options': {
                        'description':
                        u'Do not monitor hosts with the tag "offline"'
                    },
                },
            ],

            # Rule for WAN hosts with adapted PING levels
            'ping_levels': [
                {
                    'condition': {
                        'host_tags': {
                            'networking': 'wan',
                        }
                    },
                    'value': {
                        'loss': (80.0, 100.0),
                        'packets': 6,
                        'timeout': 20,
                        'rta': (1500.0, 3000.0)
                    },
                    'options': {
                        'description':
                        u'Allow longer round trip times when pinging WAN hosts'
                    },
                },
            ],

            # All hosts should use SNMP v2c if not specially tagged
            'bulkwalk_hosts': [
                {
                    'condition': {
                        'host_tags': {
                            'snmp': 'snmp',
                            'snmp_ds': {
                                '$ne': 'snmp-v1'
                            },
                        },
                    },
                    'value': True,
                    'options': {
                        'description':
                        u'Hosts with the tag "snmp-v1" must not use bulkwalk'
                    },
                },
            ],

            # Put all hosts and the contact group 'all'
            'host_contactgroups': [
                {
                    'condition': {},
                    'value': 'all',
                    'options': {
                        'description':
                        u'Put all hosts into the contact group "all"'
                    },
                },
            ],

            # Docker container specific host check commands
            'host_check_commands': [
                {
                    'condition': {
                        'host_labels': {
                            u'cmk/docker_object': u'container'
                        }
                    },
                    'value': ('service', u'Docker container status'),
                    'options': {
                        'description':
                        u'Make all docker container host states base on the "Docker container status" service',
                    },
                },
            ],

            # Enable HW/SW inventory + status data inventory for docker containers and Check-MK servers by default to
            # simplify the setup procedure for them
            'active_checks': {
                'cmk_inv': [
                    {
                        'condition': {
                            'host_labels': {
                                u'cmk/docker_object': u'node',
                            }
                        },
                        'value': {
                            'status_data_inventory': True
                        },
                    },
                    {
                        'condition': {
                            'host_labels': {
                                u'cmk/check_mk_server': u'yes',
                            }
                        },
                        'value': {
                            'status_data_inventory': True
                        },
                    },
                ]
            },

            # Interval for HW/SW-Inventory check
            'extra_service_conf': {
                'check_interval': [
                    {
                        'condition': {
                            'service_description': [{
                                '$regex':
                                'Check_MK HW/SW Inventory$'
                            }]
                        },
                        'value': 1440,
                        'options': {
                            'description':
                            u'Restrict HW/SW-Inventory to once a day'
                        },
                    },
                ],
            },

            # Disable unreachable notifications by default
            'extra_host_conf': {
                'notification_options': [
                    {
                        'condition': {},
                        'value': 'd,r,f,s'
                    },
                ],
            },

            # Periodic service discovery
            'periodic_discovery': [
                {
                    'condition': {},
                    'value': {
                        'severity_unmonitored': 1,
                        'severity_vanished': 0,
                        'check_interval': 120.0,
                        'inventory_check_do_scan': True
                    },
                    'options': {
                        'description':
                        u'Perform every two hours a service discovery'
                    },
                },
            ],

            # Include monitoring of checkmk's tmpfs
            'inventory_df_rules': [
                {
                    'condition': {
                        'host_labels': {
                            u'cmk/check_mk_server': u'yes',
                        },
                    },
                    'value': {
                        'ignore_fs_types':
                        ['tmpfs', 'nfs', 'smbfs', 'cifs', 'iso9660'],
                        'never_ignore_mountpoints':
                        [u'~.*/omd/sites/[^/]+/tmp$']
                    }
                },
            ],
        }

        rulesets = FolderRulesets(Folder.root_folder())
        rulesets.load()
        rulesets.from_config(Folder.root_folder(), ruleset_config)
        rulesets.save()

        notification_rules = [
            {
                'allow_disable': True,
                'contact_all': False,
                'contact_all_with_email': False,
                'contact_object': True,
                'description':
                'Notify all contacts of a host/service via HTML email',
                'disabled': False,
                'notify_plugin': ('mail', {}),
            },
        ]
        save_notification_rules(notification_rules)
Exemple #2
0
    def generate(self):
        save_global_settings(self._initial_global_settings())

        # A contact group for all hosts and services
        groups = {
            "contact": {
                'all': {
                    'alias': u'Everything'
                }
            },
        }
        save_group_information(groups)

        self._initialize_tag_config()

        # Rules that match the upper host tag definition
        ruleset_config = {
            # Make the tag 'offline' remove hosts from the monitoring
            'only_hosts': [
                {
                    'id': '10843c55-11ea-4eb2-bfbc-bce65cd2ae22',
                    'condition': {
                        'host_tags': {
                            'criticality': {
                                '$ne': 'offline'
                            }
                        }
                    },
                    'value': True,
                    'options': {
                        'description':
                        u'Do not monitor hosts with the tag "offline"'
                    },
                },
            ],

            # Rule for WAN hosts with adapted PING levels
            'ping_levels': [
                {
                    'id': '0365b634-30bf-40a3-8516-08e86051508e',
                    'condition': {
                        'host_tags': {
                            'networking': 'wan',
                        }
                    },
                    'value': {
                        'loss': (80.0, 100.0),
                        'packets': 6,
                        'timeout': 20,
                        'rta': (1500.0, 3000.0)
                    },
                    'options': {
                        'description':
                        u'Allow longer round trip times when pinging WAN hosts'
                    },
                },
            ],

            # All hosts should use SNMP v2c if not specially tagged
            'bulkwalk_hosts': [
                {
                    'id': 'b92a5406-1d57-4f1d-953d-225b111239e5',
                    'condition': {
                        'host_tags': {
                            'snmp': 'snmp',
                            'snmp_ds': {
                                '$ne': 'snmp-v1'
                            },
                        },
                    },
                    'value': True,
                    'options': {
                        'description':
                        u'Hosts with the tag "snmp-v1" must not use bulkwalk'
                    },
                },
            ],

            # All SNMP managment boards should use SNMP v2c if not specially tagged
            'management_bulkwalk_hosts': [
                {
                    'id': '59d84cde-ee3a-4f8d-8bec-fce35a2b0d15',
                    'condition': {},
                    'value': True,
                    'options': {
                        'description':
                        u'All management boards use SNMP v2 (incl. bulk walks) by default'
                    },
                },
            ],

            # Put all hosts and the contact group 'all'
            'host_contactgroups': [
                {
                    'id': 'efd67dab-68f8-4d3c-a417-9f7e29ab48d5',
                    'condition': {},
                    'value': 'all',
                    'options': {
                        'description':
                        u'Put all hosts into the contact group "all"'
                    },
                },
            ],

            # Docker container specific host check commands
            'host_check_commands': [
                {
                    'id': '24da4ccd-0d1b-40e3-af87-0097df8668f2',
                    'condition': {
                        'host_labels': {
                            u'cmk/docker_object': u'container'
                        }
                    },
                    'value': ('service', u'Docker container status'),
                    'options': {
                        'description':
                        u'Make all docker container host states base on the "Docker container status" service',
                    },
                },
            ],

            # Enable HW/SW inventory + status data inventory for docker
            # containers, kubernetes objects and Check-MK servers by default to
            # simplify the setup procedure for them
            'active_checks': {
                'cmk_inv': [
                    {
                        'id': '7ba2ac2a-5a49-47ce-bc3c-1630fb191c7f',
                        'condition': {
                            'host_labels': {
                                u'cmk/docker_object': u'node',
                            }
                        },
                        'value': {
                            'status_data_inventory': True
                        },
                    },
                    {
                        'id': 'b4b151f9-c7cc-4127-87a6-9539931fcd73',
                        'condition': {
                            'host_labels': {
                                u'cmk/check_mk_server': u'yes',
                            }
                        },
                        'value': {
                            'status_data_inventory': True
                        },
                    },
                    {
                        'id': '2527cb37-e9da-4a15-a7d9-80825a7f6661',
                        'condition': {
                            'host_labels': {
                                'cmk/kubernetes': 'yes',
                            }
                        },
                        'value': {
                            'status_data_inventory': True
                        },
                    },
                ]
            },

            # Interval for HW/SW-Inventory check
            'extra_service_conf': {
                'check_interval': [
                    {
                        'id': 'b3847203-84b3-4f5b-ac67-0f06d4403905',
                        'condition': {
                            'service_description': [{
                                '$regex':
                                'Check_MK HW/SW Inventory$'
                            }]
                        },
                        'value': 1440,
                        'options': {
                            'description':
                            u'Restrict HW/SW-Inventory to once a day'
                        },
                    },
                ],
            },

            # Disable unreachable notifications by default
            'extra_host_conf': {
                'notification_options': [
                    {
                        'id': '814bf932-6341-4f96-983d-283525b5416d',
                        'condition': {},
                        'value': 'd,r,f,s'
                    },
                ],
            },

            # Periodic service discovery
            'periodic_discovery': [
                {
                    'id': '95a56ffc-f17e-44e7-a162-be656f19bedf',
                    'condition': {},
                    'value': {
                        'severity_unmonitored': 1,
                        'severity_vanished': 0,
                        'check_interval': 120.0,
                    },
                    'options': {
                        'description':
                        u'Perform every two hours a service discovery'
                    },
                },
            ],

            # Include monitoring of checkmk's tmpfs
            'inventory_df_rules': [
                {
                    'id': 'b0ee8a51-703c-47e4-aec4-76430281604d',
                    'condition': {
                        'host_labels': {
                            u'cmk/check_mk_server': u'yes',
                        },
                    },
                    'value': {
                        'ignore_fs_types':
                        ['tmpfs', 'nfs', 'smbfs', 'cifs', 'iso9660'],
                        'never_ignore_mountpoints':
                        [u'~.*/omd/sites/[^/]+/tmp$']
                    }
                },
            ],
        }

        rulesets = FolderRulesets(Folder.root_folder())
        rulesets.load()
        rulesets.from_config(Folder.root_folder(), ruleset_config)
        rulesets.save()

        notification_rules = [
            {
                'allow_disable': True,
                'contact_all': False,
                'contact_all_with_email': False,
                'contact_object': True,
                'description':
                'Notify all contacts of a host/service via HTML email',
                'disabled': False,
                'notify_plugin': ('mail', {}),
            },
        ]
        save_notification_rules(notification_rules)
Exemple #3
0
def _create_sample_config():
    """Create a very basic sample configuration

    But only if none of the
    files that we will create already exists. That is e.g. the case
    after an update from an older version where no sample config had
    been created.
    """
    if not _need_to_create_sample_config():
        return

    # Global configuration settings
    save_global_settings({
        "use_new_descriptions_for": [
            "df",
            "df_netapp",
            "df_netapp32",
            "esx_vsphere_datastores",
            "hr_fs",
            "vms_diskstat.df",
            "zfsget",
            "ps",
            "ps.perf",
            "wmic_process",
            "services",
            "logwatch",
            "logwatch.groups",
            "cmk-inventory",
            "hyperv_vms",
            "ibm_svc_mdiskgrp",
            "ibm_svc_system",
            "ibm_svc_systemstats.diskio",
            "ibm_svc_systemstats.iops",
            "ibm_svc_systemstats.disk_latency",
            "ibm_svc_systemstats.cache",
            "casa_cpu_temp",
            "cmciii.temp",
            "cmciii.psm_current",
            "cmciii_lcp_airin",
            "cmciii_lcp_airout",
            "cmciii_lcp_water",
            "etherbox.temp",
            "liebert_bat_temp",
            "nvidia.temp",
            "ups_bat_temp",
            "innovaphone_temp",
            "enterasys_temp",
            "raritan_emx",
            "raritan_pdu_inlet",
            "mknotifyd",
            "mknotifyd.connection",
            "postfix_mailq",
            "nullmailer_mailq",
            "barracuda_mailqueues",
            "qmail_stats",
            "http",
            "mssql_backup",
            "mssql_counters.cache_hits",
            "mssql_counters.transactions",
            "mssql_counters.locks",
            "mssql_counters.sqlstats",
            "mssql_counters.pageactivity",
            "mssql_counters.locks_per_batch",
            "mssql_counters.file_sizes",
            "mssql_databases",
            "mssql_datafiles",
            "mssql_tablespaces",
            "mssql_transactionlogs",
            "mssql_versions",
        ],
        "enable_rulebased_notifications": True,
        "ui_theme": "facelift",
        "lock_on_logon_failures": 10,
    })

    # A contact group for all hosts and services
    groups = {
        "contact": {
            'all': {
                'alias': u'Everything'
            }
        },
    }
    save_group_information(groups)

    _initialize_tag_config()

    # Rules that match the upper host tag definition
    ruleset_config = {
        # Make the tag 'offline' remove hosts from the monitoring
        'only_hosts': [(['!offline'], ['@all'], {
            'description': u'Do not monitor hosts with the tag "offline"'
        }),],

        # Rule for WAN hosts with adapted PING levels
        'ping_levels': [({
            'loss': (80.0, 100.0),
            'packets': 6,
            'rta': (1500.0, 3000.0),
            'timeout': 20
        }, ['wan'], ['@all'], {
            'description': u'Allow longer round trip times when pinging WAN hosts'
        }),],

        # All hosts should use SNMP v2c if not specially tagged
        'bulkwalk_hosts': [(['snmp', '!snmp-v1'], ['@all'], {
            'description': u'Hosts with the tag "snmp-v1" must not use bulkwalk'
        }),],

        # Put all hosts and the contact group 'all'
        'host_contactgroups': [('all', [], ALL_HOSTS, {
            'description': u'Put all hosts into the contact group "all"'
        }),],

        # Interval for HW/SW-Inventory check
        'extra_service_conf': {
            'check_interval': [(1440, [], ALL_HOSTS, ["Check_MK HW/SW Inventory$"], {
                'description': u'Restrict HW/SW-Inventory to once a day'
            }),],
        },

        # Disable unreachable notifications by default
        'extra_host_conf': {
            'notification_options': [('d,r,f,s', [], ALL_HOSTS, {}),],
        },

        # Periodic service discovery
        'periodic_discovery': [({
            'severity_unmonitored': 1,
            'severity_vanished': 0,
            'inventory_check_do_scan': True,
            'check_interval': 120.0
        }, [], ALL_HOSTS, {
            'description': u'Perform every two hours a service discovery'
        }),],
    }

    rulesets = FolderRulesets(Folder.root_folder())
    rulesets.from_config(Folder.root_folder(), ruleset_config)
    rulesets.save()

    notification_rules = [
        {
            'allow_disable': True,
            'contact_all': False,
            'contact_all_with_email': False,
            'contact_object': True,
            'description': 'Notify all contacts of a host/service via HTML email',
            'disabled': False,
            'notify_plugin': ('mail', {}),
        },
    ]
    save_notification_rules(notification_rules)

    try:
        import cmk.gui.cee.plugins.wato.sample_config  # pylint: disable=redefined-outer-name
        cmk.gui.cee.plugins.wato.sample_config.create_cee_sample_config()
    except ImportError:
        pass

    # Initial baking of agents (when bakery is available)
    if has_agent_bakery():
        import cmk.gui.cee.plugins.wato.agent_bakery
        bake_job = cmk.gui.cee.plugins.wato.agent_bakery.BakeAgentsBackgroundJob()
        bake_job.set_function(cmk.gui.cee.plugins.wato.agent_bakery.bake_agents_background_job)
        try:
            bake_job.start()
        except background_job.BackgroundJobAlreadyRunning:
            pass

    # This is not really the correct place for such kind of action, but the best place we could
    # find to execute it only for new created sites.
    import cmk.gui.werks as werks
    werks.acknowledge_all_werks(check_permission=False)

    cmk.gui.wato.mkeventd.save_mkeventd_sample_config()

    userdb.create_cmk_automation_user()
Exemple #4
0
    def generate(self):
        save_global_settings({
            "use_new_descriptions_for": [
                "df",
                "df_netapp",
                "df_netapp32",
                "esx_vsphere_datastores",
                "hr_fs",
                "vms_diskstat.df",
                "zfsget",
                "ps",
                "ps.perf",
                "wmic_process",
                "services",
                "logwatch",
                "logwatch.groups",
                "cmk-inventory",
                "hyperv_vms",
                "ibm_svc_mdiskgrp",
                "ibm_svc_system",
                "ibm_svc_systemstats.diskio",
                "ibm_svc_systemstats.iops",
                "ibm_svc_systemstats.disk_latency",
                "ibm_svc_systemstats.cache",
                "casa_cpu_temp",
                "cmciii.temp",
                "cmciii.psm_current",
                "cmciii_lcp_airin",
                "cmciii_lcp_airout",
                "cmciii_lcp_water",
                "etherbox.temp",
                "liebert_bat_temp",
                "nvidia.temp",
                "ups_bat_temp",
                "innovaphone_temp",
                "enterasys_temp",
                "raritan_emx",
                "raritan_pdu_inlet",
                "mknotifyd",
                "mknotifyd.connection",
                "postfix_mailq",
                "nullmailer_mailq",
                "barracuda_mailqueues",
                "qmail_stats",
                "http",
                "mssql_backup",
                "mssql_counters.cache_hits",
                "mssql_counters.transactions",
                "mssql_counters.locks",
                "mssql_counters.sqlstats",
                "mssql_counters.pageactivity",
                "mssql_counters.locks_per_batch",
                "mssql_counters.file_sizes",
                "mssql_databases",
                "mssql_datafiles",
                "mssql_tablespaces",
                "mssql_transactionlogs",
                "mssql_versions",
            ],
            "enable_rulebased_notifications":
            True,
            "ui_theme":
            "facelift",
            "lock_on_logon_failures":
            10,
        })

        content = "# Written by WATO Basic config (%s)\n\n" % time.strftime(
            "%Y-%m-%d %H:%M:%S")
        content += 'df_use_fs_used_as_metric_name = True\n'
        store.save_file(
            os.path.join(cmk.utils.paths.omd_root,
                         'etc/check_mk/conf.d/fs_cap.mk'), content)

        # A contact group for all hosts and services
        groups = {
            "contact": {
                'all': {
                    'alias': u'Everything'
                }
            },
        }
        save_group_information(groups)

        self._initialize_tag_config()

        # Rules that match the upper host tag definition
        ruleset_config = {
            # Make the tag 'offline' remove hosts from the monitoring
            'only_hosts': [
                {
                    'condition': {
                        'host_tags': {
                            'criticality': {
                                '$ne': 'offline'
                            }
                        }
                    },
                    'value': True,
                    'options': {
                        'description':
                        u'Do not monitor hosts with the tag "offline"'
                    },
                },
            ],

            # Rule for WAN hosts with adapted PING levels
            'ping_levels': [
                {
                    'condition': {
                        'host_tags': {
                            'networking': 'wan',
                        }
                    },
                    'value': {
                        'loss': (80.0, 100.0),
                        'packets': 6,
                        'timeout': 20,
                        'rta': (1500.0, 3000.0)
                    },
                    'options': {
                        'description':
                        u'Allow longer round trip times when pinging WAN hosts'
                    },
                },
            ],

            # All hosts should use SNMP v2c if not specially tagged
            'bulkwalk_hosts': [
                {
                    'condition': {
                        'host_tags': {
                            'snmp': 'snmp',
                            'snmp_ds': {
                                '$ne': 'snmp-v1'
                            },
                        },
                    },
                    'value': True,
                    'options': {
                        'description':
                        u'Hosts with the tag "snmp-v1" must not use bulkwalk'
                    },
                },
            ],

            # Put all hosts and the contact group 'all'
            'host_contactgroups': [
                {
                    'condition': {},
                    'value': 'all',
                    'options': {
                        'description':
                        u'Put all hosts into the contact group "all"'
                    },
                },
            ],

            # Enable HW/SW inventory + status data inventory for docker containers by default to
            # simplify the setup procedure of docker monitoring
            'active_checks': {
                'cmk_inv': [
                    {
                        'condition': {
                            'host_labels': {
                                u'cmk/docker_object': u'node'
                            }
                        },
                        'value': {
                            'status_data_inventory': True
                        },
                    },
                ]
            },

            # Interval for HW/SW-Inventory check
            'extra_service_conf': {
                'check_interval': [
                    {
                        'condition': {
                            'service_description': [{
                                '$regex':
                                'Check_MK HW/SW Inventory$'
                            }]
                        },
                        'value': 1440,
                        'options': {
                            'description':
                            u'Restrict HW/SW-Inventory to once a day'
                        },
                    },
                ],
            },

            # Disable unreachable notifications by default
            'extra_host_conf': {
                'notification_options': [
                    {
                        'condition': {},
                        'value': 'd,r,f,s'
                    },
                ],
            },

            # Periodic service discovery
            'periodic_discovery': [
                {
                    'condition': {},
                    'value': {
                        'severity_unmonitored': 1,
                        'severity_vanished': 0,
                        'check_interval': 120.0,
                        'inventory_check_do_scan': True
                    },
                    'options': {
                        'description':
                        u'Perform every two hours a service discovery'
                    },
                },
            ],
        }

        rulesets = FolderRulesets(Folder.root_folder())
        rulesets.load()
        rulesets.from_config(Folder.root_folder(), ruleset_config)
        rulesets.save()

        notification_rules = [
            {
                'allow_disable': True,
                'contact_all': False,
                'contact_all_with_email': False,
                'contact_object': True,
                'description':
                'Notify all contacts of a host/service via HTML email',
                'disabled': False,
                'notify_plugin': ('mail', {}),
            },
        ]
        save_notification_rules(notification_rules)
Exemple #5
0
    def generate(self):
        save_global_settings(self._initial_global_settings())

        content = "# Written by WATO Basic config (%s)\n\n" % time.strftime(
            "%Y-%m-%d %H:%M:%S")
        content += 'df_use_fs_used_as_metric_name = True\n'
        store.save_file(
            os.path.join(cmk.utils.paths.omd_root,
                         'etc/check_mk/conf.d/fs_cap.mk'), content)

        # A contact group for all hosts and services
        groups = {
            "contact": {
                'all': {
                    'alias': u'Everything'
                }
            },
        }
        save_group_information(groups)

        self._initialize_tag_config()

        # Rules that match the upper host tag definition
        ruleset_config = {
            # Make the tag 'offline' remove hosts from the monitoring
            'only_hosts': [
                {
                    'condition': {
                        'host_tags': {
                            'criticality': {
                                '$ne': 'offline'
                            }
                        }
                    },
                    'value': True,
                    'options': {
                        'description':
                        u'Do not monitor hosts with the tag "offline"'
                    },
                },
            ],

            # Rule for WAN hosts with adapted PING levels
            'ping_levels': [
                {
                    'condition': {
                        'host_tags': {
                            'networking': 'wan',
                        }
                    },
                    'value': {
                        'loss': (80.0, 100.0),
                        'packets': 6,
                        'timeout': 20,
                        'rta': (1500.0, 3000.0)
                    },
                    'options': {
                        'description':
                        u'Allow longer round trip times when pinging WAN hosts'
                    },
                },
            ],

            # All hosts should use SNMP v2c if not specially tagged
            'bulkwalk_hosts': [
                {
                    'condition': {
                        'host_tags': {
                            'snmp': 'snmp',
                            'snmp_ds': {
                                '$ne': 'snmp-v1'
                            },
                        },
                    },
                    'value': True,
                    'options': {
                        'description':
                        u'Hosts with the tag "snmp-v1" must not use bulkwalk'
                    },
                },
            ],

            # Put all hosts and the contact group 'all'
            'host_contactgroups': [
                {
                    'condition': {},
                    'value': 'all',
                    'options': {
                        'description':
                        u'Put all hosts into the contact group "all"'
                    },
                },
            ],

            # Docker container specific host check commands
            'host_check_commands': [
                {
                    'condition': {
                        'host_labels': {
                            u'cmk/docker_object': u'container'
                        }
                    },
                    'value': ('service', u'Docker container status'),
                    'options': {
                        'description':
                        u'Make all docker container host states base on the "Docker container status" service',
                    },
                },
            ],

            # Enable HW/SW inventory + status data inventory for docker containers by default to
            # simplify the setup procedure of docker monitoring
            'active_checks': {
                'cmk_inv': [
                    {
                        'condition': {
                            'host_labels': {
                                u'cmk/docker_object': u'node'
                            }
                        },
                        'value': {
                            'status_data_inventory': True
                        },
                    },
                ]
            },

            # Interval for HW/SW-Inventory check
            'extra_service_conf': {
                'check_interval': [
                    {
                        'condition': {
                            'service_description': [{
                                '$regex':
                                'Check_MK HW/SW Inventory$'
                            }]
                        },
                        'value': 1440,
                        'options': {
                            'description':
                            u'Restrict HW/SW-Inventory to once a day'
                        },
                    },
                ],
            },

            # Disable unreachable notifications by default
            'extra_host_conf': {
                'notification_options': [
                    {
                        'condition': {},
                        'value': 'd,r,f,s'
                    },
                ],
            },

            # Periodic service discovery
            'periodic_discovery': [
                {
                    'condition': {},
                    'value': {
                        'severity_unmonitored': 1,
                        'severity_vanished': 0,
                        'check_interval': 120.0,
                        'inventory_check_do_scan': True
                    },
                    'options': {
                        'description':
                        u'Perform every two hours a service discovery'
                    },
                },
            ],
        }

        rulesets = FolderRulesets(Folder.root_folder())
        rulesets.load()
        rulesets.from_config(Folder.root_folder(), ruleset_config)
        rulesets.save()

        notification_rules = [
            {
                'allow_disable': True,
                'contact_all': False,
                'contact_all_with_email': False,
                'contact_object': True,
                'description':
                'Notify all contacts of a host/service via HTML email',
                'disabled': False,
                'notify_plugin': ('mail', {}),
            },
        ]
        save_notification_rules(notification_rules)
Exemple #6
0
    def generate(self) -> None:
        save_global_settings(self._initial_global_settings())

        # A contact group for all hosts and services
        groups: AllGroupSpecs = {
            "contact": {
                GroupName("all"): {
                    "alias": "Everything"
                }
            },
        }
        save_group_information(groups)

        self._initialize_tag_config()

        # Rules that match the upper host tag definition
        ruleset_config = {
            # Make the tag 'offline' remove hosts from the monitoring
            "only_hosts": [
                {
                    "id": "10843c55-11ea-4eb2-bfbc-bce65cd2ae22",
                    "condition": {
                        "host_tags": {
                            "criticality": {
                                "$ne": "offline"
                            }
                        }
                    },
                    "value": True,
                    "options": {
                        "description":
                        'Do not monitor hosts with the tag "offline"'
                    },
                },
            ],
            # Rule for WAN hosts with adapted PING levels
            "ping_levels": [
                {
                    "id": "0365b634-30bf-40a3-8516-08e86051508e",
                    "condition": {
                        "host_tags": {
                            "networking": "wan",
                        }
                    },
                    "value": {
                        "loss": (80.0, 100.0),
                        "packets": 6,
                        "timeout": 20,
                        "rta": (1500.0, 3000.0),
                    },
                    "options": {
                        "description":
                        "Allow longer round trip times when pinging WAN hosts"
                    },
                },
            ],
            # All hosts should use SNMP v2c if not specially tagged
            "bulkwalk_hosts": [
                {
                    "id": "b92a5406-1d57-4f1d-953d-225b111239e5",
                    "condition": {
                        "host_tags": {
                            "snmp": "snmp",
                            "snmp_ds": {
                                "$ne": "snmp-v1"
                            },
                        },
                    },
                    "value": True,
                    "options": {
                        "description":
                        'Hosts with the tag "snmp-v1" must not use bulkwalk'
                    },
                },
            ],
            # All SNMP managment boards should use SNMP v2c if not specially tagged
            "management_bulkwalk_hosts": [
                {
                    "id": "59d84cde-ee3a-4f8d-8bec-fce35a2b0d15",
                    "condition": {},
                    "value": True,
                    "options": {
                        "description":
                        "All management boards use SNMP v2 (incl. bulk walks) by default"
                    },
                },
            ],
            # Put all hosts and the contact group 'all'
            "host_contactgroups": [
                {
                    "id": "efd67dab-68f8-4d3c-a417-9f7e29ab48d5",
                    "condition": {},
                    "value": "all",
                    "options": {
                        "description":
                        'Put all hosts into the contact group "all"'
                    },
                },
            ],
            # Docker container specific host check commands
            "host_check_commands": [
                {
                    "id": "24da4ccd-0d1b-40e3-af87-0097df8668f2",
                    "condition": {
                        "host_labels": {
                            "cmk/docker_object": "container"
                        }
                    },
                    "value": ("service", "Docker container status"),
                    "options": {
                        "description":
                        'Make all docker container host states base on the "Docker container status" service',
                    },
                },
            ],
            # Enable HW/SW inventory + status data inventory for docker
            # containers, kubernetes objects and Check-MK servers by default to
            # simplify the setup procedure for them
            "active_checks": {
                "cmk_inv": [
                    {
                        "id": "7ba2ac2a-5a49-47ce-bc3c-1630fb191c7f",
                        "condition": {
                            "host_labels": {
                                "cmk/docker_object": "node",
                            }
                        },
                        "value": {
                            "status_data_inventory": True
                        },
                    },
                    {
                        "id": "b4b151f9-c7cc-4127-87a6-9539931fcd73",
                        "condition": {
                            "host_labels": {
                                "cmk/check_mk_server": "yes",
                            }
                        },
                        "value": {
                            "status_data_inventory": True
                        },
                    },
                    {
                        "id": "2527cb37-e9da-4a15-a7d9-80825a7f6661",
                        "condition": {
                            "host_labels": {
                                "cmk/kubernetes": "yes",
                            }
                        },
                        "value": {
                            "status_data_inventory": True
                        },
                    },
                ]
            },
            # Interval for HW/SW-Inventory check
            "extra_service_conf": {
                "check_interval": [
                    {
                        "id": "b3847203-84b3-4f5b-ac67-0f06d4403905",
                        "condition": {
                            "service_description": [{
                                "$regex":
                                "Check_MK HW/SW Inventory$"
                            }]
                        },
                        "value": 1440,
                        "options": {
                            "description":
                            "Restrict HW/SW-Inventory to once a day"
                        },
                    },
                ],
            },
            # Disable unreachable notifications by default
            "extra_host_conf": {
                "notification_options": [
                    {
                        "id": "814bf932-6341-4f96-983d-283525b5416d",
                        "condition": {},
                        "value": "d,r,f,s",
                    },
                ],
            },
            # Periodic service discovery
            "periodic_discovery": [
                {
                    "id": "95a56ffc-f17e-44e7-a162-be656f19bedf",
                    "condition": {},
                    "value": {
                        "severity_unmonitored": 1,
                        "severity_vanished": 0,
                        "check_interval": 120.0,
                    },
                    "options": {
                        "description":
                        "Perform every two hours a service discovery"
                    },
                },
            ],
            # Include monitoring of checkmk's tmpfs
            "inventory_df_rules": [
                {
                    "id": "b0ee8a51-703c-47e4-aec4-76430281604d",
                    "condition": {
                        "host_labels": {
                            "cmk/check_mk_server": "yes",
                        },
                    },
                    "value": {
                        "ignore_fs_types":
                        ["tmpfs", "nfs", "smbfs", "cifs", "iso9660"],
                        "never_ignore_mountpoints":
                        ["~.*/omd/sites/[^/]+/tmp$"],
                    },
                },
            ],
        }

        rulesets = FolderRulesets(Folder.root_folder())
        rulesets.load()
        rulesets.from_config(Folder.root_folder(), ruleset_config)
        rulesets.save()

        notification_rules = [
            {
                "allow_disable": True,
                "contact_all": False,
                "contact_all_with_email": False,
                "contact_object": True,
                "description":
                "Notify all contacts of a host/service via HTML email",
                "disabled": False,
                "notify_plugin": ("mail", {}),
            },
        ]
        save_notification_rules(notification_rules)