简体   繁体   English

Sensu处理程序未触发

[英]Sensu Handler not triggering

it seems my new Sensu Handler does not get called. 看来我的新Sensu处理程序没有被调用。 But first, my config. 但首先,我的配置。 in /etc/sensu/conf.d/checks.json: 在/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"
   }
}

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

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

in the server logs, i see: 在服务器日志中,我看到:

 {
  "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"]
}

the client logs: 客户端记录:

{
  "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
    }
  }
}

And then, the logs stop to produce anything regarding the check. 然后,日志停止生成任何有关检查的内容。 I can't find anything I am doing wrong. 我找不到我做错的任何事情。 I even added a line of code to write to a logfile in the handler once it gets called, but nothing. 甚至在调用处理程序时,我甚至添加了一行代码写入日志文件,但没有执行任何操作。
Any clues? 有什么线索吗?
(if you are wondering, i am using python because i am not familiar with ruby...) (如果您想知道,我正在使用python,因为我对ruby不熟悉...)

Handlers will only be executed on the following status types: 处理程序将仅在以下状态类型上执行:

  • warning 警告
  • critical 危急
  • unknown 未知

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

Search for "severities", on how to customize this attribute in your handler definition. 搜索“严重性”,以了解如何在处理程序定义中自定义此属性。

An event is either create, resolve or flapping. 事件是创建,解决或波动。

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

Your client log is showing "status: 0", which means the check passed, so no event is created and there's no reason to execute a handler for the event. 您的客户日志显示“状态:0”,这表示已通过检查,因此不会创建任何事件,也没有理由执行该事件的处理程序。 Try setting your check to purposefully fail: sys.exit(2) , so that "status: 2" will be reported, and the handler will execute. 尝试将检查设置为有意失败: sys.exit(2) ,这样将报告“状态:2”,并且将执行处理程序。

Handlers can deal with resolved event types. 处理程序可以处理已解决的事件类型。 As an example, you might want to be notified via HipChat, Slack or Email that an event has cleared. 例如,您可能希望通过HipChat,Slack或Email收到事件已清除的通知。 (ie. gone from "status: 2", to "status: 0") (即,从“状态:2”变为“状态:0”)

Python example of how we look at check event status: 我们如何查看检查事件状态的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"

I would also make sure your /srv/custom-sensu-handlers/handler.py is owned by the sensu:sensu user/group recursively because it is outside of the default /etc/sensu/plugins directory. 我还要确保您的/srv/custom-sensu-handlers/handler.py递归sensu:sensu用户/组所有,因为它位于默认的/ etc / sensu / plugins目录之外。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM