kirschm
(Matthias Kirsch)
January 22, 2021, 7:43am
1
Hi,
I want to set a schedule downtime for a hostgroup over the api.
With curl -k -s -u xxxxxxxxx:xxxxxxxxx ‘https://localhost:5665/v1/objects/hosts ’
I become an output.
When I run the command :
curl -k -s -u xxxxxxx:xxxxxxxx -H ‘Accept: application/json’
-X POST ‘https://localhost:5665/v1/actions/schedule-downtime ’
-d “$(jo -p pretty=true type=Host filter=“match(“update ”, hosts.group)” all_services=true author=icingaadmin comment=“stepnova release” fixed=true start_time=$(date +%s -d “+0 hour”) end_time=$(date +%s -d “+1 hour”))”
I get
“error”: 404.0,
“status”: “No objects found.”
permissions are [*]
I must say that we use for the configuration the icinga director.
Thanks for help.
Matthias
ritzgu
January 22, 2021, 9:06am
2
Hi @kirschm
the host variable for groups is host.groups
and not hosts.group
.
Also the quotation marks have to be escaped in the json body and you may also require a wildcard to match groups like:
filter="match(\"*update*\", host.groups)"
Kind regards,
ritzgu
kirschm
(Matthias Kirsch)
January 26, 2021, 5:56am
3
Hi,
the error ist away. Thank You .But i get with the query :
curl -k -s -u xxxxxxxx:xxxxxxx -H ‘Accept: application/json’
-X POST ‘https://localhost:5665/v1/actions/schedule-downtime ’
-d “$(jo -p pretty=true type=Host filter=“match(“update ”, host.groups)” all_services=true author=icingaadmin comment=“stepnova release” fixed=true start_time=$(date +%s -d “+0 hour”) end_time=$(date +%s -d “+1 hour”))”
{
“results”: []
}
And in the group update are servers.
object Host “cn01” { import “generic-host-stufe-5 ” display_name = “cn01” address = “xxxxxxxxxxx” groups = [ “generic-host-stufe-5”, “tc-clusternodes”, “update” ] vars.Betriebssystem = [ “Linux” ] vars.Standort = [ “Kiel” ] vars.xinethost = [ “ja” ] }
Kind regards
Matthias
kirschm
(Matthias Kirsch)
January 26, 2021, 6:28am
4
Hi,
I find the solution. filter="match(“update ”, host.groups, MatchAny) . MatchAny must be set if the servers are in more the one group.
Thanks und Kind regards
Matthias
ritzgu
January 26, 2021, 8:05am
5
Hi,
glad that you solved it. There are also other ways for that:
filter="host.groups.contains("update")"
or
filter=""update" in host.groups"
but i think these don’t work with wildcards.
Kind regards