You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sensu自定义Handler未触发求助:附配置及日志信息

Troubleshooting: My Custom Sensu Handler Isn't Being Called

I’ve set up a new custom Sensu handler, but it fails to trigger when my check runs. Below is my relevant configuration and a snippet of the server log:

Check Configuration (/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" 
    } 
  }
}

Handler Configuration (/etc/sensu/conf.d/handlers.json)

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

Server Log Snippet

{ "timestamp":"...", ... }


Let’s walk through the most common fixes and checks to get your handler working:

1. Confirm Sensu Services Reloaded After Config Changes

First off, configuration changes won’t take effect until you reload the Sensu server and API. Run these commands to verify status and reload:

sudo systemctl status sensu-server sensu-api
sudo systemctl reload sensu-server sensu-api

If you’re using Sensu Go, use sensu-backend restart instead—same idea, just adjusted for the newer stack.

2. Make Sure the Check Is Actually Triggering a State Change

Sensu only runs handlers when a check changes state (e.g., OK → CRITICAL) or is in a non-OK state. Test your check manually to see if it returns a non-zero exit code:

python3.6 /srv/custom_check.py
echo $?

If the exit code is 0 (OK), the handler won’t fire unless you explicitly configure it to run on OK states (which you haven’t here). Temporarily modify your check to force a failure to test the handler flow.

3. Validate Handler Script Path & Permissions

The most common culprit here is a wrong path or missing permissions for the Sensu user:

  • Double-check that /srv/custom-sensu-handlers/handler.py actually exists on your system.
  • Test if the Sensu user can run the script:
ls -l /srv/custom-sensu-handlers/handler.py
sudo -u sensu python3.6 /srv/custom-sensu-handlers/handler.py

If the sudo -u sensu command fails, fix permissions with chmod +x /srv/custom-sensu-handlers/handler.py and ensure the Sensu user has read access to the parent directory.

4. Dig Into Full Sensu Logs for Errors

Your log snippet cuts off, but the full Sensu server logs will have specific errors if the handler failed to execute. Search for references to custom_handler:

grep "custom_handler" /var/log/sensu/sensu-server.log

Look for messages like "command not found" (wrong Python path or script path) or "permission denied"—these will point you straight to the issue.

5. Verify the Client Is Subscribed to the Right Check

Make sure the client running your check is subscribed to the remote-checks subscription. Check the client’s config (usually /etc/sensu/conf.d/client.json):

{
  "client": {
    "name": "your-client-name",
    "subscriptions": ["remote-checks", ...]
  }
}

If the client isn’t subscribed, the check won’t run at all—so the handler never gets a chance to trigger.

6. Test the Handler Script Directly

Bypass Sensu entirely to rule out issues with the script itself. Pipe a sample Sensu event JSON into it:

echo '{
  "check": {
    "name": "custom_check",
    "status": 2,
    "output": "Test critical error"
  },
  "client": {
    "name": "my-check-target"
  }
}' | python3.6 /srv/custom-sensu-handlers/handler.py

If this doesn’t produce your expected result (e.g., an alert, log entry), the problem is with the handler script, not Sensu’s configuration.


内容的提问来源于stack exchange,提问作者johndough

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 07:04:36