add dhcp-stats tests and update for v3 of the extend (#15378)

* update dhcp polling for version 3 of the extend

* add initial lease display for dhcp

* note where I copied it from

* document the new ISC DHCP stuff

* add in displaying pool and subnet info

* finalize the docs the new dhcpd stuff

* rework the dhcp page to display more information in a cleaner manner

* now display port and device info if known for a lease

* minor comment cleanup for the dhcp page

* add tests

* do not display the optionbar if the extend is not 3+

* update dhcp-stats doc for -w

* poke includes/html/functions.inc.php with php-cs-fixer

* poke includes/html/pages/device/apps/dhcp-stats.inc.php with php-cs-fixer

* derp... add the tests and not the snmprec twice

* strftime -> date

* fix naming of the linux dhcp-stats test data files

* minor tweaks to the rest results

* test fix

* more test cleanup

* minor test fix

* set the data value for v3

* minor test tweak

* add sortable_table blade template

* no longer need render_table

* formatting fix

* add regexp to make sure the mac is sane

* style fix

* formatting cleanup

* some more formatting fixes
This commit is contained in:
Zane C. Bowers-Hadley
2024-02-21 14:33:17 -06:00
committed by GitHub
parent 7c59e64b7a
commit 56471e63d7
8 changed files with 542 additions and 21 deletions

View File

@@ -1074,33 +1074,46 @@ extend icecast /etc/snmp/icecast-stats.sh
A small python3 script that reports current DHCP leases stats and pool usage of ISC DHCP Server.
Also you have to install the dhcpd-pools Package.
Under Ubuntu/Debian just run `apt install dhcpd-pools` or under
FreeBSD `pkg install dhcpd-pools`.
Also you have to install the dhcpd-pools and the required Perl
modules. Under Ubuntu/Debian just run `apt install
cpanminus ; cpanm Net::ISC::DHCPd::Leases Mime::Base64 File::Slurp` or under FreeBSD
`pkg install p5-JSON p5-MIME-Base64 p5-App-cpanminus p5-File-Slurp ; cpanm Net::ISC::DHCPd::Leases`.
### SNMP Extend
1. Copy the shell script to the desired host.
```
wget https://github.com/librenms/librenms-agent/raw/master/snmp/dhcp.py -O /etc/snmp/dhcp.py
wget https://github.com/librenms/librenms-agent/raw/master/snmp/dhcp -O /etc/snmp/dhcp
```
2. Make the script executable
```
chmod +x /etc/snmp/dhcp.py
chmod +x /etc/snmp/dhcp
```
3. Edit your config file, Content of an example /etc/snmp/dhcp.json
3. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add:
```
{"leasefile": "/var/lib/dhcp/dhcpd.leases" }
# without using cron
extend dhcpstats /etc/snmp/dhcp -Z
# using cron
extend dhcpstats /bin/cat /var/cache/dhcp_extend
```
Key 'leasefile' specifies the path to your lease file.
4. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add:
4. If on a slow system running it via cron may be needed.
```
extend dhcpstats /etc/snmp/dhcp.py
*/5 * * * * /etc/snmp/dhcp -Z -w /var/cache/dhcp_extend
```
The following options are also supported.
| Option | Description |
|------------|---------------------------------|
| `-c $file` | Path to dhcpd.conf. |
| `-l $file` | Path to lease file. |
| `-Z` | Enable GZip+Base64 compression. |
| `-d` | Do not de-dup. |
| `-w $file` | File to write it out to. |
5. Restart snmpd on your host
The application should be auto-discovered as described at the top of