KEA: Adding libdhcp_stat_cmds.so as hook library

Open Beginner friendly
#11,153 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend

Research direction

Open mvc/app/models/OPNsense/Kea/KeaDhcpv4.php and review the existing hooks-libraries list. Add the libdhcp_stat_cmds.so entry as shown in the issue, then check the generated Kea DHCPv4 configuration to confirm the hook library is included.

Written by the indexing model from the issue text.

Description

support

Important notices

Before you add a new report, we ask you kindly to acknowledge the following:

If AI was used, please disclose:

Is your feature request related to a problem? Please describe.

We use to quite an extend Zabbix for monitoring several OPNsense systems. The user facing networks utilize KEA to provide DHCP services. Sometimes it is not clear how many devices to expect and hence we observe the DHCP pool capacity closely.
For this we have implemented a Zabbix UserParameter that is is calling the KEA control agent on Port 8004 and requesting

UserParameter=opnsense.kea.dhcp4.pools,/usr/local/bin/curl -s -X POST http://localhost:8004 -H "Content-Type: application/json" -d '{"command": "stat-lease4-get", "service": ["dhcp4"], "arguments": {}}'

BTW Captive Portal and Control Agent share the same default port...

The REST-Command stat-lease4-get is based on the hook library stat_cmds. Hence, we patch the file /usr/local/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.php after every update to contain ['library' => '/usr/local/lib/kea/hooks/libdhcp_stat_cmds.so'].

Describe the solution you like

It should be enough to simply add the hook library to [‘library’ => ‘/usr/local/lib/kea/hooks/libdhcp_stat_cmds.so’] in /usr/local/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.php.

...
                'hooks-libraries' => [
                    /*
                     * Hook loading order can be important in some cases:
                     * https://kea.readthedocs.io/en/latest/arm/hooks.html#binding-variables
                     */
                    [
                        'library' => '/usr/local/lib/kea/hooks/libdhcp_ping_check.so',
                        'parameters' => [
                            'enable-ping-check' => false,
                        ],
                    ],
                    ['library' => '/usr/local/lib/kea/hooks/libdhcp_lease_cmds.so'],
                    ['library' => '/usr/local/lib/kea/hooks/libdhcp_host_cmds.so'],
                    ['library' => '/usr/local/lib/kea/hooks/libdhcp_stat_cmds.so'],

                ],
...

Describe alternatives you considered

It would be possible to count and calculate the leases from the file /var/db/kea/kea-leases4.csv. However, that seems more like a workaround.

Dominant language
PHP
Stars
4.8k
Forks
1k
Avg merge
1d 20h
Merged PRs (30d)
36

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opnsense/core

All issues in opnsense/core

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.