Create a new plugin from scratch by example pt. 1 (LLDP)

This series shows you how to create plugins from scratch!

First of all, know the plugins! Install every plugin on a test machine and try them out. Why? Because you have to know how each plugin works and what to copy from. Let’s assume you just need one page with some fields to enter, but no user management where to add multiple entries (like Freeradius – Users). Then the collectd plugin is fine, it’s just one page with some fields. If you need more, e.g. some fields but also a user management, have a look at the siproxd plugin.

For our case – LLDP – we just need one page with some default values to configure (collectd) and a second page to print out the current status (Quagga – Diagnostics – Show running-config).

So, where do we start? First of all we fork the plugins project and copy the collectd plugins to lldpd. Checking the ports collection of OPNsense you see that collectd and lldpd reside both in net-mgmt so you can stay in this directory.

After copying rename all files/folders with collectd to lldpd and all files/folders with Collectd to Lldpd. Then open the Makefile and adjust the values. Version should be 0.1 for the beginning and also add a PLUGIN_DEVEL = YES. Then you can adjust the pkg-desc file, just surf to the webpage and copy some lines describing the package.

nut/src/etc/inc/plugins.inc.d/lldpd.inc controls the service, so you have to check for the correct pid file location and as always check if collectd was replaced by lldpd. In the ports tree you can see in one of the pkg files alls folders/files to be created. Check the /var folders for lldpd and add them to setup.sh script in src/opnsense/scripts/OPNsense/Lldp/

Next thing is to search&replace all collectd/Collectd content in all files in opnsense/mvc/app/ and be sure to be case sensitive!

 

In the next part we’ll cover the model and the forms!