From ae38a45b7e2db667074cf45f1c5802f2f1a43c03 Mon Sep 17 00:00:00 2001 From: Adam Bishop Date: Tue, 26 Jan 2021 05:13:31 +0000 Subject: [PATCH] Add a button to reset port state history (#12457) * Add API function to reset port state * Log the activity * Make StyleCI Happy * Update FAQ.md Add FAQ explaining problem and use --- doc/Support/FAQ.md | 19 +++++ includes/html/forms/reset-port-state.inc.php | 73 +++++++++++++++++++ .../html/pages/device/edit/device.inc.php | 31 +++++++- 3 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 includes/html/forms/reset-port-state.inc.php diff --git a/doc/Support/FAQ.md b/doc/Support/FAQ.md index 6eaf457c2e..8ca0831fb7 100644 --- a/doc/Support/FAQ.md +++ b/doc/Support/FAQ.md @@ -43,6 +43,7 @@ path: blob/master/doc/ - [How do I use trend prediction in graphs](#how-do-i-use-trend-prediction-in-graphs) - [How do I move only the DB to another server](#move-db-to-another-server) - [What are the "optional requirements message" when I add SNMPv3 devices](#optional-requirements-for-snmpv3-sha2-auth) +- [How do I clean up alerts from my switches and routers about ports being down or changing speed](#network-config-permanent-change) # Developing @@ -372,6 +373,24 @@ However, ignore tag can be read in alert rules. For example on device, if `devic or `macros.device = 1` condition is is set and ignore alert tag is on, the alert rule won't match. The alert rule is ignored. +## How do I clean up alerts from my switches and routers about ports being down or changing speed + +Some properties used for alerting (ending in `_prev`) are only updated when a +change is detected, and not every time the poller runs. This means that if you +make a permanant change to your network such as removing a device, performing a +major firmware upgrade, or downgrading a WAN connection, you may be stuck with +some unresolvable alerts. + +If a port will be permantly down, it's best practice to configure it to be +administratively down on the device to prevent malicious access. You can then +only run alerts on ports with `ifAdminStatus = up`. Otherwise, you'll need to +reset the device port state history. + +On the device generating alerts, use the cog button to go to the edit device +page. At the top of the _device settings_ pane is a button labelled `Reset Port +State` - this will clear the historic state for all ports on that device, +allowing any active alerts to clear. + ## How do I add support for a new OS? Please see [Supporting a new OS](../Developing/Support-New-OS.md) if you are adding all diff --git a/includes/html/forms/reset-port-state.inc.php b/includes/html/forms/reset-port-state.inc.php new file mode 100644 index 0000000000..7ec7d54963 --- /dev/null +++ b/includes/html/forms/reset-port-state.inc.php @@ -0,0 +1,73 @@ +. + * + * @link http://librenms.org + * @copyright 2021 Adam Bishop + * @author Adam Bishop + */ + +use App\Models\Device; + +if (! Auth::user()->hasGlobalAdmin()) { + $response = [ + 'status' => 'error', + 'message' => 'Need to be admin', + ]; + echo _json_encode($response); + exit; +} + +if (isset($_POST['device_id'])) { + if (! is_numeric($_POST['device_id'])) { + $status = 'error'; + $message = 'Invalid device id ' . $_POST['device_id']; + } else { + $device = Device::find($_POST['device_id']); + + log_event('Port state history reset by ' . Auth::user()->username, $device); + + try { + foreach ($device->ports()->get() as $port) { + $port->ifSpeed_prev = null; + $port->ifHighSpeed_prev = null; + $port->ifOperStatus_prev = null; + $port->ifAdminStatus_prev = null; + + $port->save(); + } + $status = 'ok'; + $message = 'Port state cleared successfully'; + } catch (Exception $e) { + $status = 'error'; + $message = 'Clearing port state failed: $e'; + } + } +} else { + $status = 'Error'; + $message = 'Undefined POST keys received'; +} + +$output = [ + 'status' => $status, + 'message' => $message, +]; + +header('Content-type: application/json'); +echo _json_encode($output); diff --git a/includes/html/pages/device/edit/device.inc.php b/includes/html/pages/device/edit/device.inc.php index 7ff55eb782..bd58dd057e 100644 --- a/includes/html/pages/device/edit/device.inc.php +++ b/includes/html/pages/device/edit/device.inc.php @@ -97,22 +97,26 @@ $disable_notify = get_dev_attrib($device, 'disable_notify');

Device Settings

-
+ +
-
+
- +
+
+ +

@@ -216,7 +220,7 @@ $disable_notify = get_dev_attrib($device, 'disable_notify');
-