Configure Zabbix Agent

Details on configuring Zabbix Agent on OpenWrt, including a helper script to collect the list of packages installed.

Prepare for Zabbix Agent

  1. mkdir -p /srv/tmp
  2. chmod 1777 /srv/tmp
  3. mkdir -p /srv/log/zabbix
  4. chown root:zabbix /srv/log/zabbix
  5. chmod g+rwX /srv/log/zabbix

Add a helper script for package list collection

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):

Configure the Zabbix Agent

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:

  1. Go to the web interface for Zabbix
  2. Go to ‘Data collection|Templates’ and clone the ‘Linux by Zabbix agent’ as ‘Linux on OpenWrt by Zabbix Agent’
  3. Select ‘Items’ for ‘Linux on OpenWrt by Zabbix Agent’
  4. Select ‘Number of installed packages’
  5. Change ‘Key’ to ‘system.sw.owrt_packages.get’
  6. Change ‘Update interval’ to 1h
  7. Set ‘Timeout’ to ‘Override’ ‘1m’
  8. Select ‘Enabled’
  9. Select ‘Update’
  10. Select ‘Monitoring’
  11. Select ‘Hosts’
  12. Select ‘Zabbix server’
  13. Under ‘Configuration’, Select ‘Host’
  14. In the Templates section add ‘Linux on OpenWrt by Zabbix Agent’
  15. ‘Unlink and clear’ ‘Linux by Zabbix Agent’
  16. Select ‘Update’

Enable data collection for f2fs or ubifs filesystems

  1. Select ‘Administration|General|Regular expressions’
  2. Update ‘Filesystems for discovery to include 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)$
  3. Select ‘Update’
  4. Select ‘Data collection|Templates|Linux on OpenWrt by Zabbix agent’
  5. Select ‘Macros’
  6. Edit {$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)$
  7. Select ‘Update’