大网数据广告活动
服务器运维问答

How to get Zabbix to report out of date packages?

· 52CE 我爱测

How do I configure Zabbix to report for Linux servers that have out of date packages? The following shell command reports if package updates are available: /usr/bin/yum --debuglevel 2 --security check-update 2>/dev/null \ | grep …

问题原文

原帖链接 · Greg Pagendam-Turner · CC BY-SA 3.0

How do I configure Zabbix to report for Linux servers that have out of date packages?

The following shell command reports if package updates are available:

/usr/bin/yum --debuglevel 2 --security check-update 2>/dev/null \
    | grep -P '(?<! 0 packages) available$'

If no updates is returns an empty string. If updates are available returns:

10 packages available

已采纳解答

原帖链接 · asaveljevs · CC BY-SA 3.0

You should create a user parameter with content similar to the following:

UserParameter=yum.updates,/usr/bin/yum --debuglevel 2 --security check-update 2>/dev/null | grep -P '(?<! 0 packages) available$'

Place this line either into the main configuration file for Zabbix agent (zabbix_agentd.conf) or into a separate file (which might be better if you are planning on distributing this user parameter on a lot of servers) and include it or its directory using Include directive.

In the current form, you have a user parameter than returns a string, so in Zabbix frontend you would configure an item with key yum.updates and type of "Character". A trigger would then be:

{host:yum.updates.strlen()}#0

However, the problem with string items is that they cannot be graphed. It would be nice to have an item that returns an integer with the number of updates available, like so (note the trailing part):

UserParameter=yum.updates,/usr/bin/yum --debuglevel 2 --security check-update 2>/dev/null | grep -P '...' || echo 0

You will also have to change the regular expression in the grep so that it returns only an integer.

The benefit of this approach is that the number of available updates can be graphed and you can also set a higher threshold for the trigger:

{host:yum.updates.last()}>10

See also official documentation on user parameters for full details.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-03-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。