[Solved] PHP Error (Null Parameter)

Hi,

This may be Ubuntu related (i.e. recent updates), not sure … but when trying to poll a device (or devices), I’m getting a bunch of errors like this,

PHP Error(8192): PDO::prepare(): Passing null to parameter #1 ($query) of type string is deprecated in /opt/librenms/LibreNMS/Alert/AlertRules.php:83

Any suggestions? I haven’t changed my rules in a long time - and many are default (i.e. not modified by me).

Thanks!

1 Like

Can you please check which PHP-version you’re currently running?

php -v

Of course!


PHP 8.3.6 (cli) (built: Jan  7 2026 08:40:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
    with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans

Thanks!

Looking at the source of AlertRules.php, it seems that the variable $sql is empty, which is defined a few line before.
Maybe some PHP modules are missing on your host. Could you please check if the packages stated here are present?
In particular, the php-packages like:
php-cli php-curl php-fpm php-gd php-gmp php-json php-mbstring php-mysql php-snmp php-xml php-zip

You could also check Libre’s logs in /logs subfolder for entries beginning with “Error in alert rule”. They should contain some information about what failed.

Hi,

I tried those packages - installed them … they were all there, just a couple updated. No change though. But perhaps this helps?

  1. manually polling a device, lnms device:poll winServer2, I get
Starting polling run:

Hostname:  winserver2  (microsoft)
ID:        114
OS:        windows
IP:        192.168.0.31

#### Load poller module availability ####

1 day   : 0%
1 week  : 0%
4 weeks : 0%
1 year  : 50.779%

>> SNMP: [0/0.00s] MySQL: [18/0.27s] RRD: [5/0.00s]
>> Runtime for poller module 'availability': 0.0159 seconds with 151048 bytes
#### Unload poller module availability ####

Enabled graphs (15): poller_perf availability ping_perf poller_modules_perf uptime netstat_icmp netstat_icmp_info netstat_ip netstat_ip_frag netstat_snmp netstat_snmp_pkt netstat_udp netstat_tcp hr_processes hr_users



>>> Polled winserver2 (114) in 1.565 seconds <<<
INFO: device:poll winserver2 (114) polled in 1.565s
### Start Device Groups ###
### End Device Groups (0.0026s) ###

#### Start Alerts ####
Rule #1 (Devices up/down):
Status: NOCHG
Rule #2 (Device rebooted):
PHP Error(8192): PDO::prepare(): Passing null to parameter #1 ($query) of type string is deprecated in /opt/librenms/LibreNMS/Alert/AlertRules.php:83
Exception: ValueError PDO::prepare(): Argument #1 ($query) cannot be empty @ /opt/librenms/LibreNMS/Alert/AlertRules.php:83
#0 /opt/librenms/LibreNMS/Alert/AlertRules.php(83): PDO->prepare()
#1 /opt/librenms/app/Actions/Alerts/RunAlertRulesAction.php(43): LibreNMS\Alert\AlertRules->runRules()
#2 /opt/librenms/app/Action.php(40): App\Actions\Alerts\RunAlertRulesAction->execute()
#3 /opt/librenms/app/Listeners/CheckAlerts.php(39): App\Action::execute()
#4 /opt/librenms/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(508): App\Listeners\CheckAlerts->handle()
#5 /opt/librenms/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(315): Illuminate\Events\Dispatcher->Illuminate\Events\{closure}()
#6 /opt/librenms/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(295): Illuminate\Events\Dispatcher->invokeListeners()
#7 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(505): Illuminate\Events\Dispatcher->dispatch()
#8 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Events/Dispatchable.php(14): event()
#9 /opt/librenms/app/Jobs/PollDevice.php(108): App\Events\DevicePolled::dispatch()
#10 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Jobs\PollDevice->handle()
#11 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#12 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(96): Illuminate\Container\Util::unwrapIfClosure()
#13 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod()
#14 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/Container.php(799): Illuminate\Container\BoundMethod::call()
#15 /opt/librenms/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(129): Illuminate\Container\Container->call()
#16 /opt/librenms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}()
#17 /opt/librenms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#18 /opt/librenms/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(133): Illuminate\Pipeline\Pipeline->then()
#19 /opt/librenms/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(134): Illuminate\Bus\Dispatcher->dispatchNow()
#20 /opt/librenms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}()
#21 /opt/librenms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#22 /opt/librenms/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(127): Illuminate\Pipeline\Pipeline->then()
#23 /opt/librenms/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(68): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
#24 /opt/librenms/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(102): Illuminate\Queue\CallQueuedHandler->call()
#25 /opt/librenms/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php(131): Illuminate\Queue\Jobs\Job->fire()
#26 /opt/librenms/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php(111): Illuminate\Queue\SyncQueue->executeJob()
#27 /opt/librenms/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(246): Illuminate\Queue\SyncQueue->push()
#28 /opt/librenms/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(230): Illuminate\Bus\Dispatcher->pushCommandToQueue()
#29 /opt/librenms/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Bus\Dispatcher->dispatchToQueue()
#30 /opt/librenms/app/PerDeviceProcess.php(78): Illuminate\Bus\Dispatcher->dispatchSync()
#31 /opt/librenms/app/Console/Commands/DevicePoll.php(73): App\PerDeviceProcess->run()
#32 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Console\Commands\DevicePoll->handle()
#33 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#34 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(96): Illuminate\Container\Util::unwrapIfClosure()
#35 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod()
#36 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/Container.php(799): Illuminate\Container\BoundMethod::call()
#37 /opt/librenms/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\Container\Container->call()
#38 /opt/librenms/vendor/symfony/console/Command/Command.php(341): Illuminate\Console\Command->execute()
#39 /opt/librenms/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Symfony\Component\Console\Command\Command->run()
#40 /opt/librenms/vendor/symfony/console/Application.php(1102): Illuminate\Console\Command->run()
#41 /opt/librenms/vendor/symfony/console/Application.php(356): Symfony\Component\Console\Application->doRunCommand()
#42 /opt/librenms/vendor/symfony/console/Application.php(195): Symfony\Component\Console\Application->doRun()
#43 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(198): Symfony\Component\Console\Application->run()
#44 /opt/librenms/lnms(35): Illuminate\Foundation\Console\Kernel->handle()
#45 {main}

In AlertRules.php line 83:

  PDO::prepare(): Argument #1 ($query) cannot be empty

OK, so specifically, breaking on Rule #2 (Device rebooted). So then I checked,

  1. vi resources/definitions/alert_rules.json and I get,
  {
    "builder": {"condition":"AND","rules":[{"id":"devices.uptime","field":"devices.uptime","type":"string","input":"text","operator":"less","value":"300"},{"id":"macros.device","field":"macros.device","type":"integer","input":"radio","operator":"equal","value":"1"}],"valid":true},
    "name": "Device rebooted",
    "extra": "{\"count\": 1}",
    "default": true
  },

Seems valid, agreed? So it’s not the rules JSON file? Thoughts?

Thanks again!

Something regarding alerting and null-parameters just got fixed in the new release:

So maybe this problem is already gone. Please update and try again.

Updated, tried again … nope, still fails. Dang it!

Thanks!

Somehow you have a bad alert rule. Did you set one to advanced and not set proper SQL for it?

Also, alert_rules.json is where the default rule is after you add it, it is stored in the database and you can edit it further. Checking the default rule does nothing, you need to look at the alert rule as you have it configured.

Yes, I was thinking a bad rule also, but …

  1. The rule that has been failing - I have never modified it. It’s been the same for at least a couple years, and it’s a “stock” rule. Did something else change?
  2. The (first?) rule that fails is above - is anything wrong with it? It looks correct to me, but I’m by no means an expert.

Thanks!

That rule is what’s in the definition file and doesn’t mean it’s what you’re running.

Screenshot the rule builder and show the query it’s generated as well.

I think you mean this? :wink: I admit, I have never used this interface … but some do look blank. Did some update wipe out needed content perhaps? Thanks!

If you go into one of the rules and see what it shows but yes, that doesn’t look right.

Agreed! But how did they get blown away? I haven’t touched them in a very long time … and in fact, this one - I have never touched. I just left it as the default.

Is there a way to recreate them from the JSON file?

Thanks!

Click import from on the left and select collection. You can search for the rule in there.

No idea how they have disappeared, not seen that before.

No worries, stuff happens :wink: . Will replace the blank ones (assuming anything that is blank (rule) needs to be replaced?).

So the JSON is no longer used?

Thanks!

It is used, that’s where the collection pulls its information from.

Got it, thanks! I rebuilt all the rules, they work now - thanks! Odd, but one of those things.

1 Like

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