[solved - kindof] - Notifications in specific time periods

I’ve been getting to the stage of testing nagios plugins, where a number of our nagios checks are 24x7 for one set of users and 9x5 for others - I can’t see anyplace to either schedule the checks or the alerts for particular hours. Is it even possible?

The easiest way right now would probably be to add a couple new alert macros. For example, if you added

$config[‘alert’][‘macros’][‘rule’][‘8_to_5’] = ‘HOUR(NOW()) BETWEEN 8 AND 16’;
$config[‘alert’][‘macros’][‘rule’][‘Mon_to_Fri’] = ‘DAYOFWEEK(NOW()) BETWEEN 2 AND 6’;

…to your config.php file you should get macros.8_to_5 and macros.Mon_to_Fri as options in alert builder. If you include them as AND conditions and set them to equals Yes the alert should only fire when the normal conditions are true plus the current time is between 08:00:00 and 16:59:59 and the day of week is between Mon and Fri.

When I add those I get a PHP error:

PHP Fatal error: Uncaught UnexpectedValueException: The stream or file “/opt/librenms” could not be opened: failed to open stream: Is a directory in /opt/librenms/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107\nStack trace:\n#0 /opt/librenms/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)\n#1 /opt/librenms/vendor/monolog/monolog/src/Monolog/Logger.php(337): Monolog\Handler\AbstractProcessingHandler->handle(Array)\n#2 /opt/librenms/vendor/monolog/monolog/src/Monolog/Logger.php(616): Monolog\Logger->addRecord(400, Object(Symfony\Component\Debug\Exception\FatalThrowableError), Array)\n#3 /opt/librenms/vendor/laravel/framework/src/Illuminate/Log/Writer.php(203): Monolog\Logger->error(Object(Symfony\Component\Debug\Exception\FatalThrowableError), Array)\n#4 /opt/librenms/vendor/laravel/framework/src/Illuminate/Log/Writer.php(114): Illuminate\Log\Writer->writeLog(‘error’, Object(Symfony\Component\Debug\Exception\FatalThrowableError), Array)\n#5 /op in /opt/librenms/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107

Hm, I’ve got it in my config.php and haven’t been able to duplicate that error…

Maybe make sure the syntax is all good and nothing weird happened during copy/paste?

You can also check the syntax against the define your own macros section of the docs…

https://docs.librenms.org/#Alerting/Macros/

I’m guessing you have added some sort of error to your config.php.

Actually, if I had a different guess it would be that you set APP_LOG= in your .env file, but that doesn’t make any sense.

Must gave been a typo copy/paste error on my part. I got it working now thanks.

1 Like