似乎我的新Sensu Handler没有被调用。 但首先,我的配置。 在/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 ...)
答案 0 :(得分:1)
处理程序仅在以下状态类型上执行:
https://docs.sensu.io/sensu-core/1.4/reference/handlers/#handler-attributes
搜索"严重性",了解如何在处理程序定义中自定义此属性。
事件是创建,解决或拍打。
https://docs.sensu.io/sensu-core/1.2/reference/events/#event-actions
您的客户端日志显示"状态:0",表示已通过检查,因此未创建任何事件,并且没有理由为该事件执行处理程序。尝试将支票设置为故意失败:sys.exit(2)
,以便"状态:2"将被报告,处理程序将执行。
处理程序可以处理已解决的事件类型。例如,您可能希望通过HipChat,Slack或Email通知事件已清除。 (即从"状态:2",到"状态: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用户/组递归拥有,因为它超出了默认的/ etc / sensu / plugins目录。