[LINUX] Monitor ISC DHCP status with ZABBIX

When I tried to monitor the IP address allocation status on the ISC DHCP server with ZABBIX, for some reason I could only find an example of using a fairly large script written in Perl etc., so I implemented it myself using WAK I tried it.

In the shell script saved in / usr / local / bin / dhcpd_status, ISC DHCP release record (dhcpd.leases) is analyzed by awk and used (active), released (free), unassigned (noassign), Shows each available and the number allocated to the pool (quota).

/usr/local/bin/dhcpd_status


#!/bin/sh
pattern=`echo -n "${1}"|sed -e 's/\./\\\\\\\\./g'`
active=`awk -v pattern="$pattern" '/^lease / { if ( $2 ~ pattern ) { curlease = $2; } else { curlease = "" } } /^  binding state / { if ( curlease != "" ) { lstates[curlease] = $3; } } END { for (curl in lstates) { tstates[lstates[curl]]++; } print tstates["active;"]; }' /var/lib/dhcpd/dhcpd.leases`
free=`awk -v pattern="$pattern" '/^lease / { if ( $2 ~ pattern ) { curlease = $2; } else { curlease = "" } } /^  binding state / { if ( curlease != "" ) { lstates[curlease] = $3; } } END { for (curl in lstates) { tstates[lstates[curl]]++; } print tstates["free;"]; }' /var/lib/dhcpd/dhcpd.leases`
pattern=`echo -n "^[\\t ]*range[\\t ]*${1}"|sed -e 's/\./\\\\\\\\./g'`
quota=`awk -F'[\t; ]*' -v pattern="$pattern" 'BEGIN { ttl = 0; } $0 ~ pattern { split($3, ip_from, "."); split($4, ip_to, "."); ttl += ip_to[4] - ip_from[4]; } END { print ttl; }' /etc/dhcp/dhcpd.conf`
noassign=$(($quota-$active-$free))
echo active: $active
echo free: $free
echo noassign: $noassign
available=$(($free+$noassign))
echo available: $available
echo quota: $quota

Calculated as the sum of all subnets when executed without parameters

python


# /usr/local/bin/dhcpd_status
active: 55
free: 313
noassign: 328
available: 641
quota: 696

Calculates the value of the specified subnet given the network address of the subnet part (including the period) in the parameter

python


[root@zeus ~]# /usr/local/bin/dhcpd_status 192.168.1.
active: 41
free: 128
noassign: 0
available: 128
quota: 169

In / etc / suders, the shell script mentioned earlier is set to be able to be executed with root privileges.

/etc/suders


zabbix    ALL=(ALL)       NOPASSWD: /usr/local/bin/dhcpd_status
Defaults!/usr/local/bin/dhcpd_status !requiretty

/etc/zabbix/zabbix_agentd.conf calls the shell script prepared earlier in response to the request from zabbix_server.

/etc/zabbix/zabbix_agentd.conf


UserParameter=isc.dhcpd[*],sudo /usr/local/bin/dhcpd_status $1 | grep $2 | cut -d' ' -f 2

Confirm that the value can be obtained by the test command of zabbix-agentd

python


# zabbix_agentd -t isc.dhcpd[192.168.1.,active]
isc.dhcpd[192.168.1.,active]                  [t|72]

Check with zabbix-get as well

python


# zabbix_get -s 127.0.0.1 -k isc.dhcpd[192.168.1.,active]
isc.dhcpd[192.168.1.,active]                  [t|72]

After that, you can get the desired value by adding DHCP related items to the monitoring items of the host running the ISC DHCP server on ZABBIX server. The key of the item is ʻisc.dhcpdThe parameter is[subnet IP, item you want to get]` スクリーンショット 2020-10-06 8.09.41.png

Recommended Posts

Monitor ISC DHCP status with ZABBIX
[blackbird-redis] Monitor Redis with blackbird
[blackbird-nginx] Monitor Nginx with blackbird
[blackbird-aerospike] Monitor Aerospike with blackbird
[blackbird-mysql] Monitor mysql with blackbird
[blackbird-memcached] Monitor Memcached with blackbird
Monitor Tomcat process with Zabbix-agent
How to monitor the execution status of sqlldr with the pv command