UserFuncHelper->hhmmssToMinutes

I have a DC rectifier from, alpha that returns
rectSysEstimatedBatteryRuntime.0 = 16078

this is 16 hours 07 min and 8 seconds

I was using
user_func: '\LibreNMS\OS\BaicellsOd04::hhmmss_to_minutes'
but that changed in a previous update now I am using

        runtime:
            data:
                -
                    oid: rectifierSystem
                    num_oid: '.1.3.6.1.4.1.7309.5.3.1.31.{{ $index }}'
                    value: rectSysEstimatedBatteryRuntime
                    descr: 'Estimated Run Time in hours'
                    index: rectSysEstimatedBatteryRuntime.{{ $index }}
                    user_func: hhmmssToMinutes

and during discovery I get an error

Sensor fetched value: 16078
  
Error discovering sensors module for alpha ErrorException: Undefined array key 1 in /opt/librenms/LibreNMS/Util/UserFuncHelper.php:57
Stack trace:
#0 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(256): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /opt/librenms/LibreNMS/Util/UserFuncHelper.php(57): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()
#2 /opt/librenms/includes/discovery/functions.inc.php(644): LibreNMS\Util\UserFuncHelper->hhmmssToMinutes()
#3 /opt/librenms/includes/discovery/functions.inc.php(687): discovery_process()
#4 /opt/librenms/includes/discovery/sensors.inc.php(50): sensors()
#5 /opt/librenms/includes/discovery/functions.inc.php(173): include('...')
#6 /opt/librenms/discovery.php(108): discover_device()
#7 {main}  

this was working when I used to point my user function to
user_func: '\LibreNMS\OS\BaicellsOd04::hhmmss_to_minutes'
but that was removed and replaced with hhmmssToMinutes

I even tried to give it a multiplier of 10 to make it 6 digits and I am still getting the same error.

That function was moved in this PR: baicells-od04: fix user_func by Jellyfrog · Pull Request #17606 · librenms/librenms · GitHub

The issue is that the function expects hh:mm:ss which isn’t what’s being passed over. The function could be updated to just split based on a set length of characters as a fallback I guess. Would need a small update to the code.

I did find the change that was how I found the new user_func. Do I need to add a feature request to get that done? o could you point me to the location of the user functions?

It’s linked in that pull request:

If you can write a bit of code you can probably update that function

thank you for pointing me to that I wrote a new user function to convert the 5 digit hhmms to min

public function hhmmsToMinutes(): int
    {
    $raw = $this->value_raw;
	$h = (int) substr($raw, 0, 2);
	$m = (int) substr($raw, 2, 2); 
	$s = (int) substr($raw, 4, 1);
	return (int) ($h * 60 + $m + $s / 60);
    }

I think you’ll be better adding that to the existing function, just do something like if(str_contains($this->value_raw, ':')) {

old code

} else {

Your code

again thank you for that info

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.