簡體   English   中英

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

搜索“嚴重性”,以了解如何在處理程序定義中自定義此屬性。

事件是創建,解決或波動。

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目錄之外。

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