librenms / librenms-agent

LibreNMS Agent & Scripts
GNU General Public License v2.0
116 stars 187 forks source link

Address script failure with parameters #449

Closed arrmo closed 1 year ago

arrmo commented 1 year ago

The current script fails to run if any parameters are set for the interface, like (for example), FwMark ... the reason is,

wg show all dump

outputs this info as well, which doesn't work with the current logic.

bnerickson commented 1 year ago

Thanks, @arrmo

Can you share an example of the sanitized wg show all dump output as-is?

arrmo commented 1 year ago

Sure, NP! But ... is there an easy way to sanitize (vs. manual)?

bnerickson commented 1 year ago

@arrmo I only want to see one line of output with the additional parameter displayed, so just one line sanitized (manually) will do. Any line except the very first line that is.

arrmo commented 1 year ago

Sure, NP! Here you go - make sense?

wg0     ---removed---    ---removed---    ---wg0Port---   off
wg1     ---removed---    ---removed---    ---wg2Port---   0xbb74

0xbb74 is the fwmark. Nothing else on these two lines (in the output).

Thanks!

bnerickson commented 1 year ago

Thanks @arrmo . Okay, that makes sense. Your change definitely works, but the bug is actually because I filter out the first line which is the interface-specific dump (see https://github.com/librenms/librenms-agent/blob/master/snmp/wireguard.py#L231). Since I only have one wireguard interface, I didn't catch what would happen with multiple interfaces.

Instead of dumping with "all" or checking that the number of columns equals "9", I'll update the script to grab the list of wireguard interfaces with wg show interfaces, then execute a wg show <wg_interface> dump for each interface discovered. This way if the number of columns for the client endpoint ever changes (exceeds or is less than 9), the script won't break (hopefully). I can get around to doing this in a couple weeks after the holidays.

arrmo commented 1 year ago

Works for me, thanks! Your solution makes sense to me - and yes, that wg1 line is about half way through the output.

Have a great break!

Jellyfrog commented 1 year ago

I can get around to doing this in a couple weeks after the holidays.

So should this be closed then?

bnerickson commented 1 year ago

@Jellyfrog Yes, this should be closed.

@arrmo If you want to test out my fixes, they are here: https://github.com/librenms/librenms-agent/pull/452

arrmo commented 1 year ago

@arrmo If you want to test out my fixes, they are here: #452

Works great, thanks!