Icinga: How to enable maintenance mode through remote api or tool?

1.1k Views Asked by At

I am using Icinga Version 2.4.2 to monitor services on several hosts. I would like to be able to place certain hosts in maintenance mode for a set amount of time using a cli tool or rest API instead of the Web UI.

Is this possible and if so what tool/api should I use? If I cannot do this through a remote tool/api what command should I use on the server or client to place clients in maintenance mode?

Update: It seems like the rest api has a solution. This set of permissions works:

object ApiUser "root" {
  password = "foobar"
  permissions = [ "console", "objects/query/Host", "objects/query/Service", "actions/schedule-downtime", "actions/remove-downtime"]
}

Then the following allows me to make and remove downtimes:

curl -k -s -u root:foobar -H 'Accept: application/json' -X POST "https://localhost:5665/v1/actions/schedule-downtime?filter=host.name==%22${TARGET}%22&type=Host" -d '{ "start_time": "1528239116", "end_time": "1528325561", "duration": 1000, "author": "root", "comment": "downtime on $TARGET" }' | jq .

curl -k -s -u root:foobar -H 'Accept: application/json' -X POST "https://localhost:5665/v1/actions/remove-downtime?filter=host.name==%22${TARGET}%22&type=Host" | jq .

Right now the only issue with this I am having is how to pass in variables for the start and stop dates. Attempting this keeps resulting in the following error:

{
  "status": "Invalid request body: Error: lexical error: invalid char in json text.\n                                        { \"start_time\": $current_time,\n                     (right here) ------^\n\n",
  "error": 400
}
0

There are 0 best solutions below