Exemplo n.º 1
0
    def logout_site(self, site_id):
        """
        Logs out of site

        # Arguments
        site_id (str): ID of site to log out of
        """
        data = NoNoneValueDict({'site_id': site_id})

        return self.make_request('logout_site', data=data)
Exemplo n.º 2
0
    def delete_site(self, site_id):
        """
        Deletes a connection to a site

        # Arguments
        site_id (str): ID of site to delete the connection to
        """
        data = NoNoneValueDict({'site_id': site_id})

        return self.make_request('delete_site', data=data)
Exemplo n.º 3
0
    def set_hosttags(self, hosttags):
        """
        Sets host tags

        # Arguments
        hosttags (dict): new host tags that will be set, have a look at return value of #WebApi.get_hosttags
        """
        data = NoNoneValueDict({hosttags})

        return self.make_request('set_hosttags', data=data)
Exemplo n.º 4
0
    def delete_folder(self, folder):
        """
        Deletes an existing folder

        # Arguments
        folder (str): name of folder to delete
        """
        data = NoNoneValueDict({'folder': folder})

        return self.make_request('delete_folder', data=data)
Exemplo n.º 5
0
    def delete_host(self, hostname):
        """
        Deletes a host from the Check_MK inventory

        # Arguments
        hostname (str): Name of host to delete
        """
        data = NoNoneValueDict({'hostname': hostname})

        return self.make_request('delete_host', data=data)
Exemplo n.º 6
0
    def get_site(self, site_id):
        """
        Gets a site

        # Arguments
        site_id (str): ID of site to get
        """
        data = NoNoneValueDict({'site_id': site_id})

        return self.make_request('get_site',
                                 data=data,
                                 query_params={'output_format': 'python'})
Exemplo n.º 7
0
    def delete_servicegroup(self, group):
        """
        Deletes a service group

        # Arguments
        group (str): name of group to delete
        """
        data = NoNoneValueDict({
            'groupname': group,
        })

        return self.make_request('delete_servicegroup', data=data)
Exemplo n.º 8
0
    def get_ruleset(self, ruleset):
        """
        Gets one rule set

        # Arguments
        ruleset (str): name of rule set to get
        """
        data = NoNoneValueDict({
            'ruleset_name': ruleset,
        })

        return self.make_request('get_ruleset', data=data, query_params={'output_format': 'python','request_format': 'python'})
Exemplo n.º 9
0
    def delete_user(self, user_id):
        """
        Deletes a user

        # Arguments
        user_id (str): ID of user to delete
        """
        data = NoNoneValueDict({
            'users': [user_id]
        })

        return self.make_request('delete_users', data=data)
Exemplo n.º 10
0
    def add_host(self,
                 hostname,
                 folder='/',
                 ipaddress=None,
                 alias=None,
                 tags=None,
                 **custom_attrs):
        """
        Adds a nonexistent host to the Check_MK inventory

        # Arguments
        hostname (str): Name of host to add
        folder (str): Name of folder to add the host to
        ipaddress (str): IP address of host
        alias (str): Alias for host
        tags (dict): Dictionary of tags, prefix tag_ can be omitted
        custom_attrs (dict): dict that will get merged with generated attributes, mainly for compatibility reasons
        """
        data = NoNoneValueDict({
            'hostname': hostname,
            'folder': folder,
        })

        attributes = NoNoneValueDict()

        attributes['ipaddress'] = ipaddress
        attributes['alias'] = alias

        if tags:
            for tag, value in tags.items():
                prefix = 'tag_'
                if tag.startswith(prefix):
                    attributes[tag] = value
                else:
                    attributes[prefix + tag] = value

        attributes.update(custom_attrs)
        data['attributes'] = attributes

        return self.make_request('add_host', data=data)
Exemplo n.º 11
0
    def set_ruleset(self, ruleset, ruleset_config):
        """
        Edits one rule set

        # Arguments
        ruleset (str): name of rule set to edit
        ruleset_config (dict): config that will be set, have a look at return value of #WebApi.get_ruleset
        """
        data = NoNoneValueDict({
            'ruleset_name': ruleset,
            'ruleset': ruleset_config if ruleset_config else {}
        })

        return self.make_request('set_ruleset', data=data, query_params={'request_format': 'python'})
Exemplo n.º 12
0
    def edit_servicegroup(self, group, alias):
        """
        Edits a service group

        # Arguments
        group (str): name of group to edit
        alias (str): new alias for group
        """
        data = NoNoneValueDict({
            'groupname': group,
            'alias': alias,
        })

        return self.make_request('edit_servicegroup', data=data)
Exemplo n.º 13
0
    def add_servicegroup(self, group, alias):
        """
        Adds a service group

        # Arguments
        group (str): name of group to add
        alias (str): alias for group
        """
        data = NoNoneValueDict({
            'groupname': group,
            'alias': alias,
        })

        return self.make_request('add_servicegroup', data=data)
Exemplo n.º 14
0
    def edit_folder(self, folder, **attributes):
        """
        Edits an existing folder

        # Arguments
        folder (str): name of folder to edit
        attributes (dict): attributes to set for the folder, look at output from #WebApi.get_folder
        """
        data = NoNoneValueDict({
            'folder': folder,
            'attributes': attributes if attributes else {}
        })

        return self.make_request('edit_folder', data=data)
Exemplo n.º 15
0
    def login_site(self, site_id, user, password):
        """
        Logs in to site

        # Arguments
        site_id (str): ID of site to log in to
        """
        data = NoNoneValueDict({
            'site_id': site_id,
            'username': user,
            'password': password
        })

        return self.make_request('login_site', data=data)
Exemplo n.º 16
0
    def set_site(self, site_id, site_config):
        """
        Edits the connection to a site

        # Arguments
        site_id (str): ID of site to edit
        site_config: config that will be set, have a look at return value of #WebApi.get_site
        """
        data = NoNoneValueDict({
            'site_id': site_id,
            'site_config': site_config if site_config else {}
        })

        return self.make_request('set_site',
                                 data=data,
                                 query_params={'request_format': 'python'})
Exemplo n.º 17
0
    def edit_host(self, hostname, unset_attributes=None, **custom_attrs):
        """
        Edits the properties of an existing host

        # Arguments
        hostname (str): Name of host to edit
        unset_attributes (list): List of attributes to unset
        custom_attrs (dict): dict that will get merged with generated attributes, mainly for compatibility reasons
        """
        data = NoNoneValueDict({
            'hostname': hostname,
            'unset_attributes': unset_attributes,
            'attributes': custom_attrs
        })

        return self.make_request('edit_host', data=data)
Exemplo n.º 18
0
    def get_folder(self, folder, effective_attributes=False):
        """
        Gets one folder

        # Arguments
        folder (str): name of folder to get
        effective_attributes (bool): If True attributes with default values will be returned
        """
        data = NoNoneValueDict({'folder': folder})

        query_params = {
            'effective_attributes': 1 if effective_attributes else 0
        }

        return self.make_request('get_folder',
                                 data=data,
                                 query_params=query_params)
Exemplo n.º 19
0
    def edit_user(self, user_id, attributes, unset_attributes=None):
        """
        Edits an existing user

        # Arguments
        user_id (str): ID of user to edit
        attributes (dict): attributes to set for given host
        unset_attributes (list): list of attribute keys to unset
        """
        data = NoNoneValueDict({
            'users': {
                user_id: {
                    'set_attributes': attributes,
                    'unset_attributes': unset_attributes if unset_attributes else []
                }
            }
        })

        return self.make_request('edit_users', data=data)
Exemplo n.º 20
0
    def get_host(self, hostname, effective_attributes=False):
        """
        Gets one host

        # Arguments
        hostname (str): Name of host to get
        effective_attributes (bool): If True attributes with default values will be returned
        """
        data = NoNoneValueDict({
            'hostname': hostname,
        })

        query_params = {
            'effective_attributes': 1 if effective_attributes else 0
        }

        return self.make_request('get_host',
                                 query_params=query_params,
                                 data=data)
Exemplo n.º 21
0
    def activate_changes(self,
                         mode=ActivateMode.DIRTY,
                         sites=None,
                         allow_foreign_changes=False):
        """
        Activates all changes previously done

        # Arguments
        mode (ActivateMode): see #WebApi.ActivateMode
        sites (list): List of sites to activates changes on
        allow_foreign_changes (bool): If True changes of other users will be applied as well
        """
        data = NoNoneValueDict({'sites': sites})

        query_params = {
            'mode': mode.value,
            'allow_foreign_changes': 1 if allow_foreign_changes else 0
        }

        return self.make_request('activate_changes',
                                 query_params=query_params,
                                 data=data)
Exemplo n.º 22
0
    def add_automation_user(self, user_id, username, secret, **custom_attrs):
        """
        Adds a new automation user

        # Arguments
        user_id (str): user ID that will be used to log in
        username (str): name of the user to create
        secret (str): secret that will be used to log in
        custom_attrs (dict): attributes that can be set for a user, look at output from #WebApi.get_all_users
        """
        data = NoNoneValueDict({
            'users': {
                user_id: {
                    'alias': username,
                    'automation_secret': secret
                }
            }
        })

        data['users'][user_id].update(custom_attrs)

        return self.make_request('add_users', data=data)
Exemplo n.º 23
0
    def discover_services(self, hostname, mode=DiscoverMode.NEW):
        """
        Discovers the services of a specific host

        # Arguments
        hostname (str): Name of host to discover services for
        mode (DiscoverMode): see #WebApi.DiscoverMode
        """
        data = NoNoneValueDict({
            'hostname': hostname,
        })

        query_params = {'mode': mode.value}

        result = self.make_request('discover_services',
                                   data=data,
                                   query_params=query_params)

        counters = {}
        for k, regex in WebApiBase.__DISCOVERY_REGEX.items():
            counters[k] = regex.match(result).group(1)

        return counters