Skip to content

Commit db4c0b4

Browse files
mpikzinkPipoCanaja
andauthored
Convert APC sensor "Recommended Replace Date" from count to runtime sensor (librenms#16892)
* Convert APC "Recommended Replace Date" from count to runtime sensor to get a better readability * Update Testdata * Testdata * testdate * testdata * testdata --------- Co-authored-by: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com>
1 parent 52cde84 commit db4c0b4

File tree

6 files changed

+90
-88
lines changed

6 files changed

+90
-88
lines changed

LibreNMS/Util/Time.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ public static function parseAt(string|int $time): int
106106
/**
107107
* Take a date and return the number of days from now
108108
*/
109-
public static function dateToDays(string|int $date): int
109+
public static function dateToMinutes(string|int $date): int
110110
{
111111
$carbon = new Carbon();
112112

113-
return $carbon->diffInDays($date, false);
113+
return $carbon->diffInMinutes($date, false);
114114
}
115115
}

LibreNMS/Util/UserFuncHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function __call(string $name, array $arguments): mixed
3939
throw new UserFunctionExistException("Invalid user function: $name");
4040
}
4141

42-
public function dateToDays(): int
42+
public function dateToRuntime(): int
4343
{
44-
return \LibreNMS\Util\Time::dateToDays($this->value_raw);
44+
return \LibreNMS\Util\Time::dateToMinutes($this->value_raw);
4545
}
4646

4747
public function fsParseChannelValue(): float

includes/definitions/discovery/apc.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,15 +1319,6 @@ modules:
13191319
descr: 'Active Alarms'
13201320
warn_limit: 1
13211321
high_limit: 3
1322-
1323-
-
1324-
oid: upsAdvBatteryRecommendedReplaceDate
1325-
num_oid: '.1.3.6.1.4.1.318.1.1.1.2.2.21.{{ $index }}'
1326-
index: 'upsAdvBatteryRecommendedReplaceDate.{{ $index }}'
1327-
descr: 'Battery Recommended Days Remaining'
1328-
user_func: dateToDays
1329-
low_warn_limit: 30
1330-
low_limit: 0
13311322
-
13321323
oid: upsAdvBatteryNumOfBattPacks
13331324
num_oid: '.1.3.6.1.4.1.318.1.1.1.2.2.5.{{ $index }}'
@@ -1340,3 +1331,14 @@ modules:
13401331
index: 'upsAdvBatteryNumOfBadBattPacks.{{ $index }}'
13411332
descr: 'Bad batteries'
13421333
high_limit: 1
1334+
runtime:
1335+
data:
1336+
-
1337+
oid: upsAdvBatteryRecommendedReplaceDate
1338+
num_oid: '.1.3.6.1.4.1.318.1.1.1.2.2.21.{{ $index }}'
1339+
index: 'upsAdvBatteryRecommendedReplaceDate.{{ $index }}'
1340+
descr: 'Battery Recommended Days Remaining'
1341+
user_func: dateToRuntime
1342+
low_warn_limit: 43200
1343+
# 30 Days
1344+
low_limit: 0

tests/data/apc_smart1500.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,6 @@
4848
"rrd_type": "GAUGE",
4949
"state_name": null
5050
},
51-
{
52-
"sensor_deleted": 0,
53-
"sensor_class": "count",
54-
"poller_type": "snmp",
55-
"sensor_oid": ".1.3.6.1.4.1.318.1.1.1.2.2.21.0",
56-
"sensor_index": "upsAdvBatteryRecommendedReplaceDate.0",
57-
"sensor_type": "apc",
58-
"sensor_descr": "Battery Recommended Days Remaining",
59-
"group": null,
60-
"sensor_divisor": 1,
61-
"sensor_multiplier": 1,
62-
"sensor_current": 2139,
63-
"sensor_limit": null,
64-
"sensor_limit_warn": null,
65-
"sensor_limit_low": 0,
66-
"sensor_limit_low_warn": 30,
67-
"sensor_alert": 1,
68-
"sensor_custom": "No",
69-
"entPhysicalIndex": null,
70-
"entPhysicalIndex_measured": null,
71-
"sensor_prev": null,
72-
"user_func": "dateToDays",
73-
"rrd_type": "GAUGE",
74-
"state_name": null
75-
},
7651
{
7752
"sensor_deleted": 0,
7853
"sensor_class": "current",
@@ -198,6 +173,31 @@
198173
"rrd_type": "GAUGE",
199174
"state_name": null
200175
},
176+
{
177+
"sensor_deleted": 0,
178+
"sensor_class": "runtime",
179+
"poller_type": "snmp",
180+
"sensor_oid": ".1.3.6.1.4.1.318.1.1.1.2.2.21.0",
181+
"sensor_index": "upsAdvBatteryRecommendedReplaceDate.0",
182+
"sensor_type": "apc",
183+
"sensor_descr": "Battery Recommended Days Remaining",
184+
"group": null,
185+
"sensor_divisor": 1,
186+
"sensor_multiplier": 1,
187+
"sensor_current": 3080160,
188+
"sensor_limit": null,
189+
"sensor_limit_warn": null,
190+
"sensor_limit_low": 0,
191+
"sensor_limit_low_warn": 43200,
192+
"sensor_alert": 1,
193+
"sensor_custom": "No",
194+
"entPhysicalIndex": null,
195+
"entPhysicalIndex_measured": null,
196+
"sensor_prev": null,
197+
"user_func": "dateToRuntime",
198+
"rrd_type": "GAUGE",
199+
"state_name": null
200+
},
201201
{
202202
"sensor_deleted": 0,
203203
"sensor_class": "runtime",

tests/data/apc_smx750.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -483,31 +483,6 @@
483483
"rrd_type": "GAUGE",
484484
"state_name": null
485485
},
486-
{
487-
"sensor_deleted": 0,
488-
"sensor_class": "count",
489-
"poller_type": "snmp",
490-
"sensor_oid": ".1.3.6.1.4.1.318.1.1.1.2.2.21.0",
491-
"sensor_index": "upsAdvBatteryRecommendedReplaceDate.0",
492-
"sensor_type": "apc",
493-
"sensor_descr": "Battery Recommended Days Remaining",
494-
"group": null,
495-
"sensor_divisor": 1,
496-
"sensor_multiplier": 1,
497-
"sensor_current": 1523,
498-
"sensor_limit": null,
499-
"sensor_limit_warn": null,
500-
"sensor_limit_low": 0,
501-
"sensor_limit_low_warn": 30,
502-
"sensor_alert": 1,
503-
"sensor_custom": "No",
504-
"entPhysicalIndex": null,
505-
"entPhysicalIndex_measured": null,
506-
"sensor_prev": null,
507-
"user_func": "dateToDays",
508-
"rrd_type": "GAUGE",
509-
"state_name": null
510-
},
511486
{
512487
"sensor_deleted": 0,
513488
"sensor_class": "current",
@@ -633,6 +608,31 @@
633608
"rrd_type": "GAUGE",
634609
"state_name": null
635610
},
611+
{
612+
"sensor_deleted": 0,
613+
"sensor_class": "runtime",
614+
"poller_type": "snmp",
615+
"sensor_oid": ".1.3.6.1.4.1.318.1.1.1.2.2.21.0",
616+
"sensor_index": "upsAdvBatteryRecommendedReplaceDate.0",
617+
"sensor_type": "apc",
618+
"sensor_descr": "Battery Recommended Days Remaining",
619+
"group": null,
620+
"sensor_divisor": 1,
621+
"sensor_multiplier": 1,
622+
"sensor_current": 2193120,
623+
"sensor_limit": null,
624+
"sensor_limit_warn": null,
625+
"sensor_limit_low": 0,
626+
"sensor_limit_low_warn": 43200,
627+
"sensor_alert": 1,
628+
"sensor_custom": "No",
629+
"entPhysicalIndex": null,
630+
"entPhysicalIndex_measured": null,
631+
"sensor_prev": null,
632+
"user_func": "dateToRuntime",
633+
"rrd_type": "GAUGE",
634+
"state_name": null
635+
},
636636
{
637637
"sensor_deleted": 0,
638638
"sensor_class": "runtime",

tests/data/apc_sua750i.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -458,31 +458,6 @@
458458
"rrd_type": "GAUGE",
459459
"state_name": null
460460
},
461-
{
462-
"sensor_deleted": 0,
463-
"sensor_class": "count",
464-
"poller_type": "snmp",
465-
"sensor_oid": ".1.3.6.1.4.1.318.1.1.1.2.2.21.0",
466-
"sensor_index": "upsAdvBatteryRecommendedReplaceDate.0",
467-
"sensor_type": "apc",
468-
"sensor_descr": "Battery Recommended Days Remaining",
469-
"group": null,
470-
"sensor_divisor": 1,
471-
"sensor_multiplier": 1,
472-
"sensor_current": 9,
473-
"sensor_limit": null,
474-
"sensor_limit_warn": null,
475-
"sensor_limit_low": 0,
476-
"sensor_limit_low_warn": 30,
477-
"sensor_alert": 1,
478-
"sensor_custom": "No",
479-
"entPhysicalIndex": null,
480-
"entPhysicalIndex_measured": null,
481-
"sensor_prev": null,
482-
"user_func": "dateToDays",
483-
"rrd_type": "GAUGE",
484-
"state_name": null
485-
},
486461
{
487462
"sensor_deleted": 0,
488463
"sensor_class": "current",
@@ -583,6 +558,31 @@
583558
"rrd_type": "GAUGE",
584559
"state_name": null
585560
},
561+
{
562+
"sensor_deleted": 0,
563+
"sensor_class": "runtime",
564+
"poller_type": "snmp",
565+
"sensor_oid": ".1.3.6.1.4.1.318.1.1.1.2.2.21.0",
566+
"sensor_index": "upsAdvBatteryRecommendedReplaceDate.0",
567+
"sensor_type": "apc",
568+
"sensor_descr": "Battery Recommended Days Remaining",
569+
"group": null,
570+
"sensor_divisor": 1,
571+
"sensor_multiplier": 1,
572+
"sensor_current": 12960,
573+
"sensor_limit": null,
574+
"sensor_limit_warn": null,
575+
"sensor_limit_low": 0,
576+
"sensor_limit_low_warn": 43200,
577+
"sensor_alert": 1,
578+
"sensor_custom": "No",
579+
"entPhysicalIndex": null,
580+
"entPhysicalIndex_measured": null,
581+
"sensor_prev": null,
582+
"user_func": "dateToRuntime",
583+
"rrd_type": "GAUGE",
584+
"state_name": null
585+
},
586586
{
587587
"sensor_deleted": 0,
588588
"sensor_class": "runtime",

0 commit comments

Comments
 (0)