Mak*_*abi 25 linux bash shell nagios ubuntu
首先让我说我被禁止在我们的 Ubuntu 服务器上启用自动更新,用于安全和常规包。
当我登录到我的四个 Ubuntu 服务器中的任何一个时,欢迎消息包含以下内容:
39 packages can be updated.
26 updates are security updates.
Run Code Online (Sandbox Code Playgroud)
但是,当我运行监控 APT 的 Nagios 插件时,我得到:
% /usr/lib/nagios/plugins/check_apt
APT WARNING: 33 packages available for upgrade (0 critical updates).
Run Code Online (Sandbox Code Playgroud)
我需要知道如何正确检测有待处理的安全更新和定期更新。一旦我能做到这一点,我计划编写一个 Nagios 脚本,该脚本将对挂起的定期更新返回WARNING,对挂起的安全更新返回CRITICAL。
有谁知道如何检测这两个条件?
Mak*_*abi 31
事实证明,可以使用以下方法找到挂起的定期更新的数量:
/usr/lib/update-notifier/apt-check 2>&1 | cut -d ';' -f 1
Run Code Online (Sandbox Code Playgroud)
可以使用以下方法找到待处理的安全更新的数量:
/usr/lib/update-notifier/apt-check 2>&1 | cut -d ';' -f 2
Run Code Online (Sandbox Code Playgroud)
最后,我的Nagios插件如下:
#!/bin/sh
#
# Standard Nagios plugin return codes.
STATUS_OK=0
STATUS_WARNING=1
STATUS_CRITICAL=2
STATUS_UNKNOWN=3
# Query pending updates.
updates=$(/usr/lib/update-notifier/apt-check 2>&1)
if [ $? -ne 0 ]; then
echo "Querying pending updates failed."
exit $STATUS_UNKNOWN
fi
# Check for the case where there are no updates.
if [ "$updates" = "0;0" ]; then
echo "All packages are up-to-date."
exit $STATUS_OK
fi
# Check for pending security updates.
pending=$(echo "${updates}" | cut -d ";" -f 2)
if [ "$pending" != "0" ]; then
echo "${pending} security update(s) pending."
exit $STATUS_CRITICAL
fi
# Check for pending non-security updates.
pending=$(echo "${updates}" | cut -d ";" -f 1)
if [ "$pending" != "0" ]; then
echo "${pending} non-security update(s) pending."
exit $STATUS_WARNING
fi
# If we've gotten here, we did something wrong since our "0;0" check should have
# matched at the very least.
echo "Script failed, manual intervention required."
exit $STATUS_UNKNOWN
Run Code Online (Sandbox Code Playgroud)
小智 12
Nagios 插件/usr/lib/nagios/plugins/check_apt无法正确检测 Ubuntu 中的关键更新,因为它通过apt结合 Ubuntu 非关键更新的发布方式来检测关键更新。更多细节在此处的错误中:https : //bugs.launchpad.net/bugs/1031680
使用/usr/lib/update-notifier/apt-check反而是一个可靠的解决方法。
| 归档时间: |
|
| 查看次数: |
23732 次 |
| 最近记录: |