Sensu 处理程序未触发

Sensu Handler not triggering

我的新 Sensu 处理程序似乎没有被调用。 但首先,我的配置。 在 /etc/sensu/conf.d/checks.json:

{
"checks":
   "custom_check":{
      "command": "python3.6 /srv/custom_check.py",
      "subscribers": ["remote-checks"],
      "interval": 600,
      "ttl": 900,
      "handlers": ["custom_handler"],
      "source":"my-check-target"
   }
}

在/etc/sensu/conf.d/handlers.json:

{
  "handlers": {
    "custom_handler": {
      "type": "pipe",
      "command": "python3.6 /srv/custom-sensu-handlers/handler.py"
}

在服务器日志中,我看到:

 {
  "timestamp":"2018-04-25T07:51:47.253449+0200",
  "level":"info",
  "message":"publishing check request",
  "payload":{"command":"python3.6 /srv/custom_checks/custom_check.py",
  "ttl":900,
  "handlers":["custom_handler"],
  "source":"my-check-target",
  "name":"custom_check",
  "issued":1524635507},
  "subscribers":["remote-checks"]
}

客户端记录:

{
  "timestamp": "2018-04-30T06:24:00.012625+0200",
  "level": "info",
  "message": "received check request",
  "check": {
    "command": "python3.6 /srv/custom_checks/custom_check.py",
    "ttl": 900,
    "handlers": [
      "default",
      "custom_handler"
    ],
    "source": "my_check_target",
    "name": "custom_check",
    "issued": 1525062240
  }
}

{
  "timestamp": "2018-04-30T06:24:00.349912+0200",
  "level": "info",
  "message": "publishing check result",
  "payload": {
    "client": "assensu.internal.defaultoute.eu",
    "check": {
      "command": "python3.6 /srv/custom_checks/custom_check.py",
      "ttl": 900,
      "handlers": [
        "default",
        "custom_handler"
      ],
      "source": "my_check_target",
      "name": "custom_check",
      "issued": 1525062240,
      "subscribers": [
        "remote-checks"
      ],
      "interval": 600,
      "executed": 1525062240,
      "duration": 0.337,
      "output": "Check OK",
      "status": 0
    }
  }
}

然后,日志停止生成与检查有关的任何内容。 我找不到我做错的任何事情。我什至添加了一行代码,一旦它被调用就写入处理程序中的日志文件,但什么也没有。
有什么线索吗?
(如果你想知道,我使用 python 因为我不熟悉 ruby...)

处理程序只会在以下状态类型上执行:

  • 警告
  • 严重
  • 未知

https://docs.sensu.io/sensu-core/1.4/reference/handlers/#handler-attributes

搜索 "severities",了解如何在处理程序定义中自定义此属性。

事件是创建、解决或摆动。

https://docs.sensu.io/sensu-core/1.2/reference/events/#event-actions

您的客户端日志显示 "status: 0",这意味着检查已通过,因此没有创建事件,也没有理由为该事件执行处理程序。尝试将检查设置为故意失败:sys.exit(2),以便报告 "status: 2",然后处理程序将执行。

处理程序可以处理已解决的事件类型。例如,您可能希望通过 HipChat、Slack 或电子邮件收到事件已清除的通知。 (即从 "status: 2" 变为 "status: 0")

Python 我们如何查看检查事件状态的示例:

if data['check']['status'] > 2:
    level = "Unknown"
elif data['check']['status'] == 2:
    level = "Critical"
elif data['check']['status'] == 1:
    level = "Warning"
elif data['check']['status'] == 0:
    level = "Cleared"

我还要确保你的 /srv/custom-sensu-handlers/handler.py 由 sensu:sensu user/group 递归拥有,因为它在默认 /etc/sensu/plugins 目录之外。

https://docs.sensu.io/sensu-core/1.4/reference/handlers/#how-and-where-are-pipe-handler-commands-executed