Problem with backend - ` Trying to get property 'device_id' of non-object `

On the dashboard it is not possible to see service status out of the sudden. When looking at the service availability-map they show just fine.

  • No service is unknown, warning or critical, all good

  • The issue came out of nowhere. It worked and then it just stopped.

  • Already tried to work backwards to figure out what causes this error since it worked before adding more nodes and service checks

  • Poller is running with new service setup, works fine and faster than cron

  • LibreNMS hostname and Specific URL are correct and also the same in config.php and .env.

  • There is no custom css, logo or favicon active

  • PHP7.4

  • all required plugins installed

  • validate gives no errors on cli nor in WebUI

  • librenms was at stable, error appeared, update to master, still the same issue

XHRPOST https://MYDOMAIN/ajax/dash/availability-map
[HTTP/2 500 Internal Server Error 52ms]

"message": "Trying to get property 'device_id' of non-object (View: /opt/librenms/resources/views/widgets/availability-map.blade.php)",
 "exception": "ErrorException",
 "file": "/opt/librenms/LibreNMS/Util/Url.php",
"line": 228,

Can someone please look into this. I am happy to provide more info if required.
Thanks!

I’m guessing you have a service that links to a device that no longer exists.

You could run php artisan tinker in the librenms directory and paste:

foreach(Service::with('device')->get() as $s) {echo "$s->service_id - {$s->device->device_id}" . PHP_EOL;}

if it gives you an error you will see what service id is the problem

That was a good hint, apparently there are services created that are not linked to any devices. Additionally those services appear to be empty. How can that be?

We are creating service checks via Ansible using the API. If there is no service check defined Ansible just does nothing and skips that step. So I don’t understand what causes this?!

Shouldn’t there be a mechanism be in place that denys creating empty services?

curl -k -H 'X-Auth-Token: xxx' https://domain/api/v0/services/48
{
    "status": "ok",
    "services": [
        []
    ],
    "count": 1
}%          

curl -k -H 'X-Auth-Token: xxx' https://domain/api/v0/services/50         ─╯
{
    "status": "ok",
    "services": [
        []
    ],
    "count": 1
}%

 curl -k -H 'X-Auth-Token: xxx' https://domain/api/v0/services/54         ─╯
{
    "status": "ok",
    "services": [
        []
    ],
    "count": 1

Removing the empty services via API solved this issue in the dashboard, but there is no way of doing this via the UI (to my knowledge).
Maybe it would be usefull to improve the service overview and allow to do such cleanup jobs via the UI.

Update:
Apparently it is possible to add service checks to non existing devices. Shouldn’t this be denied via API? (Adding services to non existing devices)

Update2:
I added a check loop into our Ansible roles that checks if the device actually exists before trying to add services. It automatically adds missing devices, checks again for the device and then adds the desired service checks.
Still it would be good if the API throws an error if the device actually does not exist. :slight_smile:

Yes, Yes, and Yes. Pull requests welcome.

Thanks for your reply. I am not a developer and hence cannot help out with a php code contribution. Sorry. Hope someone who can will take care of this.

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