Repository: librenms/librenms (language: php)

Issue:
APC Diagnostic Test Status Missing, Breaking Alert Templates
### The problem

After discovery moved to yaml based method, I guess a few OIDs not included for UPS devices. But there are template alerts for APC and generic UPS alerts like "UPS Switched to Battery Power" that depends on these fields. upsAdvTestDiagnosticsResults is one of them. 

Adding following snippet to includes/definitions/discovery/apc.yaml file and rediscovering the device fixed the issue for APC UPS'es. 

```
                    oid: upsAdvTestDiagnosticsResults
                    num_oid: '.1.3.6.1.4.1.318.1.1.1.7.2.3.0'
                    descr: UPS diagnostics status
                    states:
                        - { descr: ok, graph: 0, value: 1, generic: 0 }
                        - { descr: failed, graph: 0, value: 2, generic: 3 }
                        - { descr: invalidTest, graph: 0, value: 3, generic: 1 }
                        - { descr: testInProgress, graph: 0, value: 4, generic: 1 }
```

### Output of ./validate.php

```txt
n/a
```


### What was the last working version of LibreNMS?

_No response_

### Anything in the logs that might be useful for us?

_No response_


Discussion / hints:
Please submit a pull request with the changes. It's as easy as browsing the file here on github and press edit!
sorry I don't have a test environment and can't provide test data or fix any possible build issues related to commits. at best this is what I can provide. sorry for half-a**'ing it and thanks for your efforts in maintaining librenms. 
@sjtarik it would be better to fix the alert rule.
But then it will alert even when APC UPS does a load test which is frequent. That alert template basically checks if test flag is on but when that flag oid is not collected by snmp even the actual power outage not alerting due to test condition

Tarik

> On Nov 21, 2021, at 10:06 AM, Tony Murray ***@***.***> wrote:
> 
> ﻿
> @sjtarik it would be better to fix the alert rule.
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or unsubscribe.
> Triage notifications on the go with GitHub Mobile for iOS or Android. 


Fix patch:
diff --git a/includes/definitions/discovery/apc.yaml b/includes/definitions/discovery/apc.yaml
index 6752c4a00281..f9324eea45a3 100644
--- a/includes/definitions/discovery/apc.yaml
+++ b/includes/definitions/discovery/apc.yaml
@@ -604,6 +604,15 @@ modules:
                         - { descr: largeMomentarySpike, graph: 0, value: 8, generic: 0 }
                         - { descr: selfTest, graph: 0, value: 9, generic: 0 }
                         - { descr: rateOfVoltageChange, graph: 0, value: 10, generic: 0 }
+                -
+                    oid: upsAdvTestDiagnosticsResults
+                    num_oid: '.1.3.6.1.4.1.318.1.1.1.7.2.3.0'
+                    descr: UPS diagnostics status
+                    states:
+                        - { descr: ok, graph: 0, value: 1, generic: 0 }
+                        - { descr: failed, graph: 0, value: 2, generic: 3 }
+                        - { descr: invalidTest, graph: 0, value: 3, generic: 1 }
+                        - { descr: testInProgress, graph: 0, value: 4, generic: 1 }
 
         temperature:
             data:
diff --git a/misc/alert_rules.json b/misc/alert_rules.json
index 3390fae0481e..161498255ca9 100644
--- a/misc/alert_rules.json
+++ b/misc/alert_rules.json
@@ -175,7 +175,7 @@
     "name": "APC UPS Diagonstics Test Result"
   },
   {
-    "builder": {"condition":"AND","rules":[{"condition":"AND","rules":[{"id":"sensors.sensor_current","field":"sensors.sensor_current","type":"string","input":"text","operator":"equal","value":"3"},{"id":"sensors.sensor_type","field":"sensors.sensor_type","type":"string","input":"text","operator":"equal","value":"upsBasicOutputStatus"}]},{"condition":"AND","rules":[{"id":"sensors.sensor_current","field":"sensors.sensor_current","type":"string","input":"text","operator":"not_equal","value":"4"},{"id":"sensors.sensor_type","field":"sensors.sensor_type","type":"string","input":"text","operator":"equal","value":"upsAdvTestDiagnosticsResults"}]}],"valid":true},
+    "builder": {"condition":"AND","rules":[{"condition":"AND","rules":[{"id":"sensors.sensor_current","field":"sensors.sensor_current","type":"string","input":"text","operator":"equal","value":"3"},{"id":"sensors.sensor_type","field":"sensors.sensor_type","type":"string","input":"text","operator":"equal","value":"upsBasicOutputStatus"}]}],"valid":true},
     "name": "APC UPS Switched to Battery Power"
   },
   {


Test patch: