Example #1
0
    def _from_vars(self) -> None:
        edit_group = request.get_ascii_input("edit")  # missing -> new group
        self._name = GroupName(edit_group) if edit_group else None
        self._new = self._name is None

        if self._new:
            clone_group = request.get_ascii_input("clone")
            if clone_group:
                self._name = GroupName(clone_group)
                self.group = self._get_group(self._name)
            else:
                self.group = {}
        else:
            assert self._name is not None
            self.group = self._get_group(self._name)

        self.group.setdefault("alias", self._name)
Example #2
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)