通过Prometheus警报管理器执行shell脚本

bybem2ql  于 2022-11-16  发布在  Shell
关注(0)|答案(2)|浏览(1280)

请告诉我是否可以在Prometheus/alertmanager所在的服务器上执行shell脚本以触发警报?如果可以,请帮助我进行配置。

clj7thdc

clj7thdc1#

你也可以使用Prometheus-am-executor来运行任何shell甚至python脚本。
以下是示例.yml文件

listen_address: ":8094" # Where alertmanager sending alerts
# Display more output
verbose: true
commands:
  - cmd: python3
    args: ["script.py"] # Script which you want to execute
kqqjbcuj

kqqjbcuj2#

另一个可维护的替代方案是https://github.com/adnanh/webhook,它允许您安装附加脚本的本地webhook。
配置示例:

- id: redeploy-webhook
  execute-command: "/var/scripts/redeploy.sh"
  command-working-directory: "/var/webhook"

webhook进程的默认端口为9000,因此以下URL将执行redeploy.sh上述配置示例中的www.example.com脚本。

http://yourserver:9000/hooks/redeploy-webhook

然后可以在alertmanager配置中使用该参数:

receivers:
- name: 'general'
  webhook_config:
  - url: http://yourserver:9000/hooks/redeploy-webhook

相关问题