Title here
Summary here
Details on configuring Zabbix Agent on OpenWrt, including a helper script to collect the list of packages installed.
mkdir -p /srv/tmp
chmod 1777 /srv/tmp
mkdir -p /srv/log/zabbix
chown root:zabbix /srv/log/zabbix
chmod g+rwX /srv/log/zabbix
Add the following as /etc/zabbix_scripts/package_list
, then
chmod a+x /etc/zabbix_scripts/package_list
#!/bin/sh
echo "["
opkg info 2>/dev/null| \
awk 'BEGIN { RS=ORS="\n\n\n"; FS=OFS="\n" } { print $0 }' | \
awk 'BEGIN { RS="\n\n"; FS="\n" } /Status: install ok installed/ { print $0 "\n\n" }' | \
awk 'BEGIN { FS="\n" } $1 ~ /Package|Version|Size|Architecture|Installed-Time/ { print $0 }' | \
awk 'BEGIN { RS="\n", FS=": " }
$1 == "Package" { print "\"name\": " "\"" $2 "\"," }
$1 == "Version" { print "\"version\": " "\"" $2 "\"," }
$1 == "Size" { print "\"size\": " $2 "," }
$1 == "Architecture" { print "\"arch\": " "\"" $2 "\"," }
$1 == "Installed-Time" { print "\"buildtime\": {\n\"timestamp\": 0,\n\"value\": \"\"\n},\n\"installtime\": {\n\"timestamp\": " $2 ",\n\"value\": \"" strftime("%b %d %H:%M:%S %Y %Z",$2) "\"\n}\n}," }
' | \
awk 'BEGIN { FS="\n" }
/name/ { print "{\n" $0 "\n\"manager\": \"opkg\"," }
$0 !~ /name/ { print $0 }
' | \
sed -e '$s%,%%'
echo "]"
Update zabbix_agentd.conf
as appropriate. For example (comments trimmed;
see /rom/etc/zabbix_agentd.conf
to see an unmodified config file):
LogType=file
LogFile=/srv/log/zabbix/zabbix_agent.log
Server=127.0.0.1,::1,yourhostname,yourhostname.example.com
StartAgents=1
Hostname=yourhostname
Include=/etc/zabbix_agentd.conf.d/
####### USER-DEFINED MONITORED PARAMETERS #######
### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
UserParameter=system.sw.owrt_packages.get,./package_list
### Option: UserParameterDir
# Directory to execute UserParameter commands from. Only one entry is allowed.
# When executing UserParameter commands the agent will change the working directory to the one
# specified in the UserParameterDir option.
# This way UserParameter commands can be specified using the relative ./ prefix.
#
# Mandatory: no
# Default:
UserParameterDir=/etc/zabbix_scripts
To make use of the package collection user script:
f2fs|ubifs
E.g. update ‘Expressions’ to ^(btrfs|ext2|ext3|ext4|f2fs|reiser|xfs|ffs|ufs|jfs|jfs2|vxfs|hfs|apfs|refs|ntfs|fat32|ubifs|zfs)$
{$VFS.FS.FSTYPE.MATCHES}
to be ^(btrfs|ext2|ext3|ext4|f2fs|reiser|xfs|ffs|ufs|jfs|jfs2|vxfs|hfs|apfs|refs|ntfs|fat32|ubifs|zfs)$