python - Sensu 处理程序未触发
问题描述
似乎我的新 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
搜索“严重性”,了解如何在处理程序定义中自定义此属性。
一个事件要么是创建,要么是解决,要么是摆动。
https://docs.sensu.io/sensu-core/1.2/reference/events/#event-actions
您的客户端日志显示“状态:0”,这意味着检查已通过,因此没有创建任何事件,也没有理由为该事件执行处理程序。尝试将您的检查设置为有目的地失败:sys.exit(2)
,以便报告“状态:2”,并执行处理程序。
处理程序可以处理已解决的事件类型。例如,您可能希望通过 HipChat、Slack 或电子邮件收到事件已清除的通知。(即从“状态: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 目录之外。
推荐阅读
- java - 为什么java程序中的这个输出打印值300
- debugging - Pytorch 错误:无法使用来自“CUDATensorId”后端的参数运行“aten::slow_conv3d_forward”
- java - 通过“冒泡排序”按字母顺序对几个名称进行排序,并附上注释
- wso2 - Wso2 用户自行注册到租户域返回 401 Unauthorized
- python - 通过 Python Subprocess' Popen over external 命令流式传输内存数据
- reactjs - Material-ui 可编辑表格单元格,带有货币掩码和表格页脚用于总计
- windows - 连接到 Windows VM 上的共享文件夹
- python - 使用 pandas df 突出显示热图中每一列的平均值数据单元格的自定义颜色
- javascript - 在 Javascript 后端使用无符号数字类型
- c++ - 类型转换不会产生预期的行为