0

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
}
Alex Cohen
  • 5,596
  • 16
  • 54
  • 104
  • It looks like there is an [icingacli](https://github.com/deltaDNA/icingacli) [that might fit my needs](https://www.icinga.com/docs/icinga2/latest/doc/11-cli-commands/). – Alex Cohen Jun 04 '18 at 20:36
  • 1
    The lexical error could mean a missing or ill escaped quote. Your $TARGET is probably not expanded because it's in a single-quoted string('). Surrounding the variable with another set of single quotes probably does the trick. – Herman van Rink Jun 11 '18 at 09:48

0 Answers0