tomaae / homeassistant-mikrotik_router

Mikrotik router integration for Home Assistant
Apache License 2.0
312 stars 55 forks source link

Counter Reset #311

Closed Extrapilot1 closed 1 year ago

Extrapilot1 commented 1 year ago

Summary of enhancement request

Ability to reset accumulators/counters for ports via the API

Describe the solution you'd like

Ideally, there would be a direct API call that will permit arbitrary reset of all counters, as can be done via the Winbox GUI. More ideal would be per counter control, but I dont believe that functionality even exists in Winbox or CLI.

Describe alternatives you've considered

Global script(s) called remotely via HA switch

Additional context

Mikrotik has added a number of CLI options for Firewall, Filter and Interface accumulator/counter resets. And, this works via remote calls from HA via this integration. But it is difficult to manage. A script like '/interface/reset-counters' wants an interface ID. And while you can call it by its index (via print detail) or its name, I dont see an easy way to clear them all via a single command. And I dont believe there is a way to pass an argument to a script via the API, so it probably requires a lot of manual scripting, which becomes a challenge with changes. They may even be a dynamic component with multiple APs, or failover hardware, or other advanced mechanisms like Link Aggregation.

If these calls are available via the API, it would simplify things. Entirely possible this exists in the Integration and I missed it.

tomaae commented 1 year ago

What would be an use case for this?

Extrapilot1 commented 1 year ago

There are a number of them. Counter reset exists for every accumulator in most every router- and that implies this is useful for users. There are a number of use cases that come to mind. Being able to do metering based on rules/automations, and/or setting alarms for unusual bandwidth changes. Deltas on this are complicated, where we would have to persist values across restarts, and where restarts of the router would require exception logic. Here you could just set an automation to run every day or month to clear out accumulators being tracked.

Another is tracking/metering dynamic entities (i.e. IP traffic via Kid Control), where with DHCP and dynamic addressing, it would be difficult to manage this with HA-side scripting. Of course all of this can be done HA-side, but there is a lot of capability enabled by your Integration that is outside the reach of most people- who dont want to deal with a bunch of scrips per port/IP, or delta calculations to simply capture bandwidth by port or IP or service for eval graphically.

tomaae commented 1 year ago

what I mean, these counters are not presented to HA. so not sure how reseting them could be used

Extrapilot1 commented 1 year ago

Well, they are with my install of your Integration. Maybe something changed with a more recent rev of MT firmware? Regardless, I have totals accumulators via your integration for ports, vlans, firewall rules, and filters. Attached is a screen grab where I just setup an Auto-entities card with a mikrotik filter. This is just a subsection showing a section that has the 'totals' entities. I created a script to reset a group of accumulators/counters, and running that via your Integration indeed cases the MT to clear them, and that shows up o the next data polling cycle-

MT1

tomaae commented 1 year ago

those are just traffic totals set it total_increasing mode for HA endless statistics. If you reset them on mikrotik side, ha will show it like that on sensor itself, but on HA counter it will not reset. Look up utility meters in HA, this sensor is made for it and it may actually be exactly what you want in this case.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 5 days with no activity.