Auto discovery fails and device details are wiped out from librenms

Hi

I have added multiple devices in Librenms and those are networking devices. If I do discovery under capture from each devices then it populate some information about the devices like system name , serial number and other details perfectly but when it does rediscover the devices after 6 hours then it doesn’t populate the above details.

I have added these mibs in “/opt/librenms/LibreNMS/OS” . This file is always picked during manual discover but never while doing re-discover.

Could you please let me know if we need to add this file details in any other place or stop the re-discover of devices ?

Gets below error on rediscover

Next Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entPhysicalIndex' cannot be null (Connection: mysql, SQL: insert into `entPhysical` (`entPhysicalIndex`, `entPhysicalDescr`, `entPhysicalClass`, `entPhysicalModelName`, `entPhysicalSerialNum`, `entPhysicalContainedIn`, `entPhysicalMfgName`, `entPhysicalParentRelPos`, `entPhysicalHardwareRev`, `entPhysicalIsFRU`, `device_id`) values (?,  0 transceiver , sensor, ?, ?, 5640, ?, -1, ?, true, 38)) in /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:829
Stack trace:
#0 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(783): Illuminate\Database\Connection->runQueryCallback()
#1 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/MySqlConnection.php(34): Illuminate\Database\Connection->run()
#2 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/MySqlProcessor.php(35): Illuminate\Database\MySqlConnection->insert()
#3 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3549): Illuminate\Database\Query\Processors\MySqlProcessor->processInsertGetId()
#4 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1982): Illuminate\Database\Query\Builder->insertGetId()
#5 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1334): Illuminate\Database\Eloquent\Builder->__call()
#6 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1299): Illuminate\Database\Eloquent\Model->insertAndSetId()
#7 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1138): Illuminate\Database\Eloquent\Model->performInsert()
#8 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php(287): Illuminate\Database\Eloquent\Model->save()
#9 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php(312): Illuminate\Database\Eloquent\Relations\HasOneOrMany->save()
#10 /opt/librenms/LibreNMS/DB/SyncsModels.php(74): Illuminate\Database\Eloquent\Relations\HasOneOrMany->saveMany()
#11 /opt/librenms/LibreNMS/Modules/EntityPhysical.php(50): LibreNMS\Modules\EntityPhysical->syncModels()
#12 /opt/librenms/includes/discovery/entity-physical.inc.php(9): LibreNMS\Modules\EntityPhysical->discover()
#13 /opt/librenms/includes/discovery/functions.inc.php(170): include('...')
#14 /opt/librenms/discovery.php(108): discover_device()
#15 {main}
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entPhysicalIndex' cannot be null (Connection: mysql, SQL: insert into `entPhysical` (`entPhysicalIndex`, `entPhysicalDescr`, `entPhysicalClass`, `entPhysicalModelName`, `entPhysicalSerialNum`, `entPhysicalContainedIn`, `entPhysicalMfgName`, `entPhysicalParentRelPos`, `entPhysicalHardwareRev`, `entPhysicalIsFRU`, `device_id`) values (?,  0 transceiver , sensor, ?, ?, 5640, ?, -1, ?, true, 38)) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entPhysicalIndex' cannot be null (Connection: mysql, SQL: insert into `entPhysical` (`entPhysicalIndex`, `entPhysicalDescr`, `entPhysicalClass`, `entPhysicalModelName`, `entPhysicalSerialNum`, `entPhysicalContainedIn`, `entPhysicalMfgName`, `entPhysicalParentRelPos`, `entPhysicalHardwareRev`, `entPhysicalIsFRU`, `device_id`) values (?,  0 transceiver , sensor, ?, ?, 5640, ?, -1, ?, true, 38)) at /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:829)
[previous exception] [object] (PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entPhysicalIndex' cannot be null at /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/MySqlConnection.php:45)"}

Changes that has been done:

<?php
namespace LibreNMS\OS;

use App\Models\EntPhysical;
use Illuminate\Support\Collection;
use LibreNMS\OS;
use SnmpQuery;
use LibreNMS\OS\Traits\EntityMib;
class CienaSds extends OS
{
       use EntityMib {
         EntityMib::discoverEntityPhysical as discoverBaseEntityPhysical;
        }


    public function discoverEntityPhysical(): Collection
    {

        $inventory = $this->discoverBaseEntityPhysical();
        $trans = SnmpQuery::hideMib()->enumStrings()->cache()->walk('ENTIY-MIB::entPhysicalEntry')->table(1);
        $ifIndexToEntIndexMap = array_flip($this->getIfIndexEntPhysicalMap());
        foreach ($trans as $ifIndex => $data) {
            $inventory->push(new EntPhysical([
                'entPhysicalIndex' => 1000000 + $ifIndex,
                'entPhysicalDescr' => $data['entPhysicalDescr'],
                'entPhysicalName' => strtoupper($data['entPhysicalName']),
                'entPhysicalModelName' => $this->normData($data['entPhysicalModelName']),
                'entPhysicalSerialNum' => $data['entPhysicalSerialNum'],
                'entPhysicalParentRelPos' => 0,
                'entPhysicalIsFRU' => 'true',
                'ifIndex' => $ifIndex,
            ]));
        }

        return $inventory;
    }
}

Please format your logs / code you paste using markdown so it’s readable.

If you’ve made local file changes then you’ll need to share those changes so someone can help you.

Thanks for the suggestion. Made the suggested changes