mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Update sensors in database + changed the way the handler is created to allow snmpv1 traps allowing dots in OID.
This commit is contained in:
@@ -41,8 +41,22 @@ class UpsTrapsOnBattery implements SnmptrapHandler
|
||||
*/
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
$remaining = $trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining.0'));
|
||||
$time = $trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery.0'));
|
||||
Log::event("UPS running on battery for $time seconds. Estimated $remaining minutes remaining", $device->device_id, 'trap', 5);
|
||||
$min_remaining = $trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining.0'));
|
||||
$sec_time = $trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery.0'));
|
||||
Log::event("UPS running on battery for $sec_time seconds. Estimated $min_remaining minutes remaining", $trap->getDevice(), 'trap', 5);
|
||||
$sensor_remaining = $device->sensors()->where('sensor_index', '200')->where('sensor_type', 'rfc1628')->first();
|
||||
if(!$sensor_remaining){
|
||||
Log::warning("Snmptrap UpsTraps: Could not find matching sensor \'Estimated battery time remaining\' for device: " . $device->hostname);
|
||||
return;
|
||||
}
|
||||
$sensor_remaining->sensor_current = $min_remaining;
|
||||
$sensor_remaining->save();
|
||||
$sensor_time = $device->sensors()->where('sensor_index', '100')->where('sensor_type', 'rfc1628')->first();
|
||||
if(!$sensor_time){
|
||||
Log::warning("Snmptrap UpsTraps: Could not find matching sensor \'Time on battery\' for device: " . $device->hostname);
|
||||
return;
|
||||
}
|
||||
$sensor_time->sensor_current = $sec_time;
|
||||
$sensor_time->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,9 @@ class SnmptrapProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(SnmptrapHandler::class, function ($app, $oid) {
|
||||
if ($handler = config('snmptraps.trap_handlers.' . reset($oid))) {
|
||||
return $app->make($handler);
|
||||
}
|
||||
|
||||
return $app->make(Fallback::class);
|
||||
$this->app->bind(SnmptrapHandler::class, function ($app, $options) {
|
||||
$oid = reset($options);
|
||||
return $app->make(config('snmptraps.trap_handlers')[$oid] ?? Fallback::class);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user