How to create Host automatically

Hi,

we have several Windows virtual machines, where Check_MK-agent is automatically installed when deploying the machine.

Is it possible to automatically create the corresponding host in Check_MK just because of the agent communication? Or is there any other interface to create hosts automatically with?

Best regards,
UT2019

You can use Bulk Discovery:
https://checkmk.de/cms_wato_services.html#bulk_discovery

https://forum.checkmk.com/t/rescan-all-hosts-all-services-and-fix-new-removed/15130

As the agent communication is pull initiated from the monitoring server there is no agent communication before the host is configured in CheckMK.

You can use the WATO API to automate the configuration steps: https://checkmk.com/cms_web_api.html

Bulk Discovery only works after the host has been configured in CheckMK.
You can use “Bulk Import” via CSV, but this cannot be easily automated.

1 Like

new informations for me thank you @r.sander :slight_smile:

OK, thanks for the information. I hoped that the agent would somehow already communicate with CheckMK even if no host is configured.

I will have to try the WATO API then to create the host(s).

Call curl with the IP of the host like:

root@linux# curl “http://myserver/mysite/check_mk/webapi.py?action=add_host&_username=automation&_secret=myautomationsecret” -d ‘request={“hostname”:“myserver123”,“folder”:“munich/network”,“attributes”:{“ipaddress”:“192.168.0.42”,“site”:“prod”,“tag_agent”:“cmk-agent”},“create_folders”:“0”}’

https://checkmk.de/cms_web_api_references.html#add_host

1 Like

As @neeloj said, you can use this for example with your IPAM solution or just do a dns query for all systems and add all missing hostnames with the api :slight_smile:

You can also do it with a network scan (regular). This is an option of a folder. You can decide what is happening to new hosts if they are found.
Hosts -> Folder properties -> Network Scan.

2 Likes

Thanks for all the answers.

I used the add_host-action in combination with Invoke-WebRequest (powershell) and included this in the software, which installs the machines that I want to integrate. It works just as required, thanks!

1 Like

Hello UT2019,

it would be nice if there are some ansible modules for those kind of jobs.

for example:

name: create host myserver123
  cmk_host:
    cmk_server: "{{ cmkserver }}"
    cmk_user: "{{ cmkadm }}"
    cmk_password: "{{ cmkpw }}"
    name: myserver123
    state: present
    folder: munich/network
    attributes:
      ipaddress: 192.168.0.42
      site: prod
      tag_agent: cmk-agent
    create_folders: 0

i found a webapi wrapper https://github.com/brennerm/check-mk-web-api. This might help to create ansible modules. I like to contribute this. What about you?

kind regards
Oliver

2 Likes

Hi,

I do not know Ansible yet and did not use it either. I integrated the creation of the CheckMK-host into our software deployment system (Matrix42 Empirum).

Best regards,
UT2019