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

Good Morning ALL, I have same issue with LibreNMS, After configuring SNMP community and test SNMPWAlk, The auto discover doesn’t populate the devices automatically, I need to do manual can you please help me on this please. Its really give me sleepless night.

Please let me know if anyone can help here

You have to give more details of your current situation.
Manual or Auto discovery are running the same code on a regular LibreNMS install. They behave the same.

My devices are network devices and entPhysicalIndex is not implemented in our devices hence I have added a logic in OS file to overcome the entPhysicalIndex and it works properly when we do discover of devices as below: Click on IP → click on three vertical dots near setting symbol → Capture → Discover → Run then all the device details are populated correctly under device
but every 6 hours it re-discover the devices and at that time all the populated details are missing. Based on the logs/librenms.log file, it has reported this log

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)"}

Now my query is , can we stop re-discovery such that it doesn’t land in this issue ?

People are going to struggle without the changes you’ve made, you’ll need to post the code (why not submit it back to the repo?)

I have added my code above in the initial post. Posting it again . Changes has been done in file under OS directory

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;
    }
}

A post was split to a new topic: Migration issue

Create your own post, please don’t hijack someone else’s with an unrelated issue