Icinga API


I’m trying to use icinga API to add some host with python script.
If I try to do it manually no problem, but with some script it doesn’t work…

My part of script with problem:

request_url = “https://localhost:5665/v1/objects/hosts/hostname

headers = {
‘Accept’: ‘application/json’,
‘X-HTTP-Method-Override’: ‘PUT’

data = {
“templates”: [“generic-host”],
“attrs”: {
“vars”: {

r = requests.post(request_url, …

My result return is:
Result: {“results”: [{“code”: 500.0, “errors”: ["Error: Validation failed for object ‘hostname’ of type ‘Host’; Attribute ‘check_command’: Attribute must not be empty.

I tried to add a command_check but it doesnt work anymore. (same error)
“check_command”: “hostalive”,

And if I try to curl command directly on my master.icinga it works…
I’m looking on API doc but for the moment no idea…
If someone has, it should be great.


How and where in your request?


Example here:

                    data = {
                        "templates": ["generic-host"],
                        "attrs": {
                                 "check_command": "hostalive",
                                 "vars": {

And result:
Error: Validation failed for object ‘hostname’ of type ‘Host’; Attribute ‘check_command’: Attribute must not be empty.

And you’re really using hostalive which exists at /v1/objects/checkcommands/hostalive? Please also share the output of icinga2 --version on that host.


1 Like

curl -k -s -u XXX:XXX -H ‘Accept: application/json’ -H ‘X-HTTP-Method-Override: GET’ ‘https://localhost:5665/v1/objects/checkcommands’ | json_pp | grep hostalive
“name” : “hostalive”

so seems yes.

To me more precise:
GET https://localhost:5665/v1/objects/checkcommands/hostalive
returns me all information about hostalive checkcommand

icinga2 - The Icinga 2 network monitoring daemon (version: r2.11.2-1)
System information:
Platform: Debian GNU/Linux
Platform version: 10 (buster)

General paths:
Config directory: /etc/icinga2
Data directory: /var/lib/icinga2
Log directory: /var/log/icinga2
Cache directory: /var/cache/icinga2
Spool directory: /var/spool/icinga2
Run directory: /run/icinga2

Thanks for help

And what is really strange for me is that if I curl directly a cul command it works fine (without to precise a checkcommand)

curl -vv -k -X PUT -u “admin:${XXXXXXX}” -H ‘Accept: application/json’ -H ‘Content-Type: application/json’ -L “https://localhost:5665/v1/objects/hosts/myhostnameToAdd” -d “{“templates”:
“attrs”: {
“address”: “IPToAdd”, “zone”: “zonre1”

  • Connection #0 to host localhost left intact
    {“results”:[{“code”:200.0,“status”:“Object was created”}]}

Sorry I’m dumb… I forget to pass data=json.dumps(data)) on my request.post script …
Now it works!
Thanks for help!

1 Like