enigma619
(Enigma)
December 17, 2019, 4:11pm
1
Hi
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”: {
“address”:ip,
“vars”: {
“zone”:“zone1”,
},
}
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.
Thanks
Alex
dnsmichi
(Michael Friedrich)
December 17, 2019, 4:17pm
2
How and where in your request?
Cheers,
Michael
enigma619
(Enigma)
December 17, 2019, 4:19pm
3
Example here:
data = {
"templates": ["generic-host"],
"attrs": {
"address":ip,
"check_command": "hostalive",
"vars": {
"zone":"zone1",
},
}
}
And result:
Error: Validation failed for object ‘hostname’ of type ‘Host’; Attribute ‘check_command’: Attribute must not be empty.
dnsmichi
(Michael Friedrich)
December 17, 2019, 4:32pm
4
And you’re really using hostalive
which exists at /v1/objects/checkcommands/hostalive
? Please also share the output of icinga2 --version
on that host.
Cheers,
Michael
1 Like
enigma619
(Enigma)
December 18, 2019, 7:40am
5
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
enigma619
(Enigma)
December 18, 2019, 8:40am
7
And what is really strange for me is that if I curl directly a cul command it works fine (without to precise a checkcommand)
Example:
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”:
[“generic-host”],
“attrs”: {
“address”: “IPToAdd”, “zone”: “zonre1”
}
}”
Connection #0 to host localhost left intact
{“results”:[{“code”:200.0,“status”:“Object was created”}]}
enigma619
(Enigma)
December 18, 2019, 9:28am
8
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