为 Nagios 插件编写优雅的超时

Writing graceful timeout for Nagios plugin

来自Nagios' Plugin Development Guidelines

Plugins have a very limited runtime - typically 10 sec. As a result, it is very important for plugins to maintain internal code to exit if runtime exceeds a threshold.

All plugins should timeout gracefully, not just networking plugins.

如何在自定义插件中实现超时机制?基本上我希望我的插件在插件超时时 return 状态代码 3 - 未知而不是默认的 1 - 严重,以减少生成的误报数量。

编辑: 我的插件是用 Bash.

编写的

您可以使用 timeout。这是示例用法:

timeout 15 ping google.com
if [ $? -eq 124 ]; then
    echo "UNKNOWN - Time limit exceeded."
    exit 3
if

如果您的命令未在规定时间内完成 - 15

,您将从 timeout 获得 return 退出状态 124