opnsense / plugins

OPNsense plugin collection
https://opnsense.org/
BSD 2-Clause "Simplified" License
832 stars 619 forks source link

vnstat: doesn't handle interface alias updates #3688

Closed nijave closed 3 months ago

nijave commented 9 months ago

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

Describe the bug vnstat data doesn't load when the WAN interface is changed from em0 to igc0

To Reproduce Steps to reproduce the behavior:

  1. Change opnsense hardware such that a different network driver is used

Expected behavior vnstat database is updated when the WAN interface alias changes or the settings page displays NICs instead of aliases (it seems misleading to show alias as the selectable options when it doesn't handle alias changes)

Screenshots If applicable, add screenshots to help explain your problem.

Relevant log files

[5c9d1c7e-8a83-406d-b58d-a8f604d1a427] Script action failed with Command '/usr/local/bin/vnstat -y ' returned non-zero exit status 1. at Traceback (most recent call last): File "/usr/local/opnsense/service/modules/actions/script_output.py", line 44, in execute subprocess.check_call(script_command, env=self.config_environment, shell=True, File "/usr/local/lib/python3.9/subprocess.py", line 373, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '/usr/local/bin/vnstat -y ' returned non-zero exit status 1.

Additional context I changed the hardware opnsense was running on. vnstat pages stopped loading. In the console I tried:

# vnstat -y
Error: No interface matching "igc0" found in database.

# sqlite3 vnstat.db
sqlite> select * from interface;
id  name     alias  active  created              updated              rxcounter      txcounter      rxtotal          txtotal
--  -------  -----  ------  -------------------  -------------------  -------------  -------------  ---------------  --------------
1   em0             0       2020-02-23 14:50:17  2023-09-04 14:34:30  1343772700801  267108630737   122286736085342  72349966271782
2   em1             0       2020-02-23 14:50:17  2023-09-04 14:34:30  210405477676   1280003894333  51781416797633   80583240678396
3   enc0            1       2020-02-23 14:50:17  2023-11-27 18:50:00  0              0              0                0
4   pfsync0         1       2020-02-23 14:50:17  2023-11-27 18:50:00  0              0              0                0
5   pflog0          1       2020-02-23 14:50:17  2023-11-27 18:50:00  0              4943227487     0                113444346962
6   ovpns1          1       2020-02-23 14:50:17  2023-11-27 18:50:00  519359212      392566597      140920312250     7836394869
7   ovpns3          1       2020-02-23 14:50:17  2023-11-27 18:50:00  0              0              2072217582       137202580147
8   ovpnc2          1       2020-02-23 14:50:17  2023-11-27 18:50:00  0              0              0                0
9   bridge0         1       2020-02-23 14:50:17  2023-11-27 18:50:00  7002180338     1722971228964  165081667817     79988616230160
sqlite> update interface set name='igc0' where name='em0';
sqlite> update interface set name='igc3' where name='em1';
sqlite>.quit

Then I switch from WAN to WAN,LAN in the GUI, save, then switch back to WAN and it's working again with historical data before the hardware change.

Environment OPNsense 23.7.6-amd64 although I think I was on 23.1 when I switched hardware

mimugmail commented 9 months ago

The InterfaceField type always lists the alias, imho a hit on save or reboot should be sufficient. For historical migration its a really rare edge case and not easy to implement. Maybe a good place to put your guide in the documentation?

nijave commented 9 months ago

It'd be good if the vnstat page showed errors. It looks like when an error comes back from the api, the page just fails to load and stays empty.

MOST2K2 commented 4 months ago

You saved my day, thanks for the sql update fix ;)

OPNsense-bot commented 3 months ago

This issue has been automatically timed-out (after 180 days of inactivity).

For more information about the policies for this repository, please read https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md for further details.

If someone wants to step up and work on this issue, just let us know, so we can reopen the issue and assign an owner to it.