Icinga:如何通过远程api或工具启用维护模式?

时间:2018-06-04 20:12:33

标签: monitoring icinga icinga2

我正在使用Icinga版本2.4.2来监控多台主机上的服务。我希望能够使用cli工具或rest API而不是Web UI将某些主机置于维护模式一段时间。

这是否可行,如果可以,我应该使用什么工具/ api? 如果我不能通过远程工具/ api执行此操作,我应该在服务器或客户端上使用什么命令将客户端置于维护模式?

更新:好像是rest api has a solution。这组权限有效:

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

然后,以下内容允许我制作和删除停机时间:

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 .

现在我唯一的问题是如何传入开始和停止日期的变量。尝试此操作会导致以下错误:

{
  "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 个答案:

没有答案