WebApi

WebApi(self, check_mk_url, username, secret)

Abstraction for Check_Mk Web API

Arguments

  • check_mk_url (str): URL to Check_Mk web application, multiple formats are supported
  • username (str): Name of user to connect as. Make sure this is an automation user.
  • secret (str): Secret for automation user. This is different from the password!

Examples

WebApi('http://checkmk.company.com/monitor/check_mk/webapi.py', 'automation', 'secret')
WebApi('http://checkmk.company.com/monitor/check_mk', 'automation', 'secret')
WebApi('http://checkmk.company.com/monitor', 'automation', 'secret')

DiscoverMode

WebApi.DiscoverMode(self, /, *args, **kwargs)

Members

  • NEW: Only discover new services
  • REMOVE: Remove exceeding services
  • FIXALL: Remove exceeding services and discover new services (Tabula Rasa)
  • REFRESH: Start from scratch

ActivateMode

WebApi.ActivateMode(self, /, *args, **kwargs)

Members

  • DIRTY: Update sites with changes
  • ALL: Update all slave sites
  • SPECIFIC: Only update specified sites

make_request

WebApi.make_request(self, action, query_params=None, data=None)

Make arbitrary request to Check_Mk Web API

Arguments

  • action (str): Action request, e.g. add_host
  • query_params (dict): dict of path parameters
  • data (dict): dict that will be sent as request body

Raises

  • CheckMkWebApiResponseException: Raised when the HTTP status code != 200
  • CheckMkWebApiException: Raised when the action's result_code != 0

add_host

WebApi.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

edit_host

WebApi.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

delete_host

WebApi.delete_host(self, hostname)

Deletes a host from the Check_MK inventory

Arguments

  • hostname (str): Name of host to delete

delete_hosts

WebApi.delete_hosts(self, hostnames)

Deletes multiple hosts from the Check_MK inventory

Arguments

  • hostnames (list): Name of hosts to delete

delete_all_hosts

WebApi.delete_all_hosts(self)

Deletes all hosts from the Check_MK inventory

get_host

WebApi.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

get_all_hosts

WebApi.get_all_hosts(self, effective_attributes=False)

Gets all hosts

Arguments

  • effective_attributes (bool): If True attributes with default values will be returned

get_hosts_by_folder

WebApi.get_hosts_by_folder(self, folder, effective_attributes=False)

Gets hosts in folder

Arguments

  • folder (str): folder to get hosts for
  • effective_attributes (bool): If True attributes with default values will be returned

discover_services

WebApi.discover_services(self, hostname, mode=<DiscoverMode.NEW: 'new'>)

Discovers the services of a specific host

Arguments

  • hostname (str): Name of host to discover services for
  • mode (DiscoverMode): see WebApi.DiscoverMode

discover_services_for_all_hosts

WebApi.discover_services_for_all_hosts(self, mode=<DiscoverMode.NEW: 'new'>)

Discovers the services of all hosts

Arguments

  • mode (DiscoverMode): see WebApi.DiscoverMode

bulk_discovery_all_hosts

WebApi.bulk_discovery_all_hosts(self, mode=<DiscoverMode.NEW: 'new'>, use_cache=True, do_scan=True, bulk_size=10, ignore_single_check_errors=True)

Bulk discovers the services of all hosts

Arguments

  • mode (DiscoverMode): see WebApi.DiscoverMode
  • use_cache (bool): use cache for discovery
  • do_scan (bool): do scan
  • bulk_size (int): number of hosts to handle at once
  • ignore_single_check_errors (bool): Ignore errors in single check plugins

bulk_discovery_start

WebApi.bulk_discovery_start(self, hostnames, mode=<DiscoverMode.NEW: 'new'>, use_cache=True, do_scan=True, bulk_size=10, ignore_single_check_errors=True)

Start bulk discovery for multiple hosts

Arguments

  • mode (DiscoverMode): see WebApi.DiscoverMode
  • use_cache (bool): use cache for discovery
  • do_scan (bool): do scan
  • bulk_size (int): number of hosts to handle at once
  • ignore_single_check_errors (bool): Ignore errors in single check plugins

bulk_discovery_status

WebApi.bulk_discovery_status(self)

Get status of bulk discovery

get_user

WebApi.get_user(self, user_id)

Gets a single user

Arguments

  • user_id (str): ID of user to get

get_all_users

WebApi.get_all_users(self)

Gets all users and their attributes

add_user

WebApi.add_user(self, user_id, username, password, **custom_attrs)

Adds a new user

Arguments

  • user_id (str): user ID that will be used to log in
  • username (str): name of the user to create
  • password (str): password 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

add_automation_user

WebApi.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

edit_user

WebApi.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

delete_user

WebApi.delete_user(self, user_id)

Deletes a user

Arguments

  • user_id (str): ID of user to delete

get_folder

WebApi.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

get_all_folders

WebApi.get_all_folders(self)

Gets all folders

add_folder

WebApi.add_folder(self, folder, **attributes)

Adds a new folder

Arguments

  • folder (str): name of folder to add
  • attributes (dict): attributes to set for the folder, look at output from WebApi.get_folder

edit_folder

WebApi.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

delete_folder

WebApi.delete_folder(self, folder)

Deletes an existing folder

Arguments

  • folder (str): name of folder to delete

get_contactgroup

WebApi.get_contactgroup(self, group)

Gets one contact group

Arguments

  • group (str): name of contact group to get

get_all_contactgroups

WebApi.get_all_contactgroups(self)

Gets all contact groups

add_contactgroup

WebApi.add_contactgroup(self, group, alias)

Adds a contact group

Arguments

  • group (str): name of group to add
  • alias (str): alias for group

edit_contactgroup

WebApi.edit_contactgroup(self, group, alias)

Edits a contact group

Arguments

  • group (str): name of group to edit
  • alias (str): new alias for group

delete_contactgroup

WebApi.delete_contactgroup(self, group)

Deletes a contact group

Arguments

  • group (str): name of group to delete

delete_all_contactgroups

WebApi.delete_all_contactgroups(self)

Deletes all contact groups

get_hostgroup

WebApi.get_hostgroup(self, group)

Gets one host group

Arguments

  • group (str): name of host group to get

get_all_hostgroups

WebApi.get_all_hostgroups(self)

Gets all host groups

add_hostgroup

WebApi.add_hostgroup(self, group, alias)

Adds a host group

Arguments

  • group (str): name of group to add
  • alias (str): alias for group

edit_hostgroup

WebApi.edit_hostgroup(self, group, alias)

Edits a host group

Arguments

  • group (str): name of group to edit
  • alias (str): new alias for group

delete_hostgroup

WebApi.delete_hostgroup(self, group)

Deletes a host group

Arguments

  • group (str): name of group to delete

delete_all_hostgroups

WebApi.delete_all_hostgroups(self)

Deletes all host groups

get_all_servicegroups

WebApi.get_all_servicegroups(self)

Gets all service groups

add_servicegroup

WebApi.add_servicegroup(self, group, alias)

Adds a service group

Arguments

  • group (str): name of group to add
  • alias (str): alias for group

edit_servicegroup

WebApi.edit_servicegroup(self, group, alias)

Edits a service group

Arguments

  • group (str): name of group to edit
  • alias (str): new alias for group

delete_servicegroup

WebApi.delete_servicegroup(self, group)

Deletes a service group

Arguments

  • group (str): name of group to delete

delete_all_servicegroups

WebApi.delete_all_servicegroups(self)

Deletes all service groups

get_ruleset

WebApi.get_ruleset(self, ruleset)

Gets one rule set

Arguments

  • ruleset (str): name of rule set to get

get_rulesets

WebApi.get_rulesets(self)

Gets all rule sets

set_ruleset

WebApi.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

get_hosttags

WebApi.get_hosttags(self)

Gets all host tags

set_hosttags

WebApi.set_hosttags(self, hosttags)

Sets host tags

As implemented by Check_MK, it is only possible to write the whole Host Tag Settings within an API-Call You can use the WebApi.get_hosttags to get the current Tags, modify them and write the dict back via set_hosttags
To ensure that no Tags are modified in the meantime you can use the configuration_hash key.

e.g. 'configuration_hash': u'f31ea758a59473d15f378b692110996c'

Arguments

  • hosttags (dict) with 2 mandatory keys: { 'aux_tags' : [], 'tag_groups' : [] }

add_aux_tag

WebApi.add_aux_tag(self, identifier, title, topic=None)

Adds an auxiliary host tag

Arguments

  • identifier (str): unique identifier of the tag to add
  • title (str): title of the tag to add
  • topic (str): topic of the tag to add

add_tag_group

WebApi.add_tag_group(self, identifier, title, tags, topic=None)

Adds a tag group

Arguments

  • identifier (str): unique identifier of the tag to add
  • title (str): title of the tag to add
  • tags (list): tag choices to add, e.g. [{"id": "high", "title": "High Availability", "aux_tags": []}, ...]
  • topic (str): topic of the tag to add

get_site

WebApi.get_site(self, site_id)

Gets a site

Arguments

  • site_id (str): ID of site to get

set_site

WebApi.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

delete_site

WebApi.delete_site(self, site_id)

Deletes a connection to a site

Arguments

  • site_id (str): ID of site to delete the connection to

login_site

WebApi.login_site(self, site_id, user, password)

Logs in to site

Arguments

  • site_id (str): ID of site to log in to

logout_site

WebApi.logout_site(self, site_id)

Logs out of site

Arguments

  • site_id (str): ID of site to log out of

bake_agents

WebApi.bake_agents(self)

Bakes all agents

Enterprise Edition only!

activate_changes

WebApi.activate_changes(self, mode=<ActivateMode.DIRTY: '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