看来我的新Sensu Handler没有接到电话。但首先,我的配置。在/etc/sensu/conf.d.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.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.)
发布于 2018-05-23 16:57:28
处理程序将只在以下状态类型上执行:
https://docs.sensu.io/sensu-core/1.4/reference/handlers/#handler-attributes
搜索“严重程度”,说明如何在处理程序定义中自定义此属性。
事件要么创建,要么解析,要么拍打。
https://docs.sensu.io/sensu-core/1.2/reference/events/#event-actions
客户端日志显示"status: 0",这意味着通过了检查,因此没有创建事件,也没有理由为事件执行处理程序。尝试将您的检查设置为:sys.exit(2),以便报告"status: 2“,并执行处理程序。
处理程序可以处理已解析的事件类型。例如,您可能希望通过HipChat、Slack或电子邮件通知事件已被清除。(即)从“状态: 2”改为“状态: 0")
Python示例,说明我们如何看待check事件状态:
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/定制感觉处理程序/handler.py是由sensu用户/group递归拥有的,因为它位于默认的/etc/sensu/plugins目录之外。
https://stackoverflow.com/questions/50015189
复制相似问题