From 90b16bab811795925655bdfa8c85f656c6056a31 Mon Sep 17 00:00:00 2001 From: Justin Lentz Date: Mon, 31 Jul 2023 22:26:21 -0500 Subject: [PATCH] port_error_perc macro (#15016) * port_error_perc * Update macros.json * Update macros.json * Update querybuilder.json * Revert * Update macros.json * Change macro names so they match usage_perc * Try *100.0 * Attempt 2 - Encapsulate in parenthesis * Undo Parenthesis * Trying laf's suggestions * Update QueryBuilderFilter.php --- LibreNMS/Alerting/QueryBuilderFilter.php | 2 +- misc/macros.json | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/LibreNMS/Alerting/QueryBuilderFilter.php b/LibreNMS/Alerting/QueryBuilderFilter.php index f3bf426d93..e26c90626e 100644 --- a/LibreNMS/Alerting/QueryBuilderFilter.php +++ b/LibreNMS/Alerting/QueryBuilderFilter.php @@ -70,7 +70,7 @@ class QueryBuilderFilter implements \JsonSerializable continue; // don't include the time based macros, they don't work like that } - if (Str::endsWith($key, '_usage_perc') || Str::startsWith($key, 'packet_loss_')) { + if (Str::endsWith($key, '_perc') || Str::startsWith($key, 'packet_loss_')) { $this->filter[$field] = [ 'id' => $field, 'type' => 'integer', diff --git a/misc/macros.json b/misc/macros.json index 3758dd04a7..f657ee39d9 100644 --- a/misc/macros.json +++ b/misc/macros.json @@ -20,6 +20,8 @@ "past_30m": "DATE_SUB(NOW(),INTERVAL 30 MINUTE)", "past_60m": "DATE_SUB(NOW(),INTERVAL 60 MINUTE)", "port": "(%ports.deleted = 0 && %ports.ignore = 0 && %ports.disabled = 0)", + "port_out_error_perc": "((%ports.ifOutErrors_rate) \/ %ports.ifOutUcastPkts_rate)*100", + "port_in_error_perc": "((%ports.ifInErrors_rate) \/ %ports.ifInUcastPkts_rate)*100", "port_down": "(%ports.ifOperStatus = \"down\" && %ports.ifAdminStatus != \"down\" && %macros.port)", "port_up": "(%ports.ifOperStatus = \"up\" && %ports.ifAdminStatus = \"up\" && %macros.port)", "port_usage_perc": "((SELECT IF(%ports.ifOutOctets_rate>%ports.ifInOctets_rate, %ports.ifOutOctets_rate, %ports.ifInOctets_rate)*8) \/ %ports.ifSpeed)*100",