Alerting with billing quota

Hi,

I was trying to set an alert rule when billing quota is more than 75%.

Default built-in rule that ships with librenms does not work.

The reason behind that is when we use macro that output is Boolean either 1 or 0.

To get such macros work we need to create a custom macro in config.php and add our comparison operator there. Then we can create alert rule.

So we need to add “config.php” below -

$config[‘alert’][‘macros’][‘rule’][‘bill_over_quota_75’] = ‘(((%bills.total_data/%bills.bill_quota) * 100) >= 75) && %bills.bill_type = “quota”’;

Look we are using >= 75 in the macro defination.

Then we create a rule like below picture -

I hope this will help someone, who tries to achieve the same result.

2 Likes

Help please.
$config[‘alert’][‘macros’][‘rule’][‘bill_over_quota_75’] = ‘(((%bills.total_data/%bills.bill_quota) * 100) >= 75) && %bills.bill_type = “quota”’;

[2021-04-13 17:03:01] production.ERROR: syntax error, unexpected ‘%’ {“exception”:"[object] (ParseError(code: 0): syntax error, unexpected ‘%’ at /opt/librenms/config.php:48)
[stacktrace]
#0 /opt/librenms/LibreNMS/Config.php(54): LibreNMS\Config::loadUserConfigFile()
#1 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(955): LibreNMS\Config::load()
#2 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(900): Illuminate\Foundation\Application->fireAppCallbacks()
#3 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application->boot()
#4 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(237): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap()
#5 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith()
#6 /opt/librenms/LibreNMS/Util/Laravel.php(46): Illuminate\Foundation\Console\Kernel->bootstrap()
#7 /opt/librenms/includes/init.php(90): LibreNMS\Util\Laravel::bootCli()
#8 /opt/librenms/alerts.php(33): require(’/opt/librenms/i…’)
#9 {main}
“}
[2021-04-13 17:03:17] production.ERROR: syntax error, unexpected ‘%’ {“exception”:”[object] (ParseError(code: 0): syntax error, unexpected ‘%’ at /opt/librenms/config.php:48)

Heeelp.
Idea?

Turns out the quotes aren’t working. Im very new to this but could tell the file didn’t like the format of the string.
Did mine like this and not getting errors but still testing if it actually works:
$config[‘alert’][‘macros’][‘rule’][‘bill_over_quota_75’] = ‘(((%bills.total_data/%bills.bill_quota) * 100) >= 75) && %bills.bill_type = “quota”’;

Nope. Sorry.
Its the forum that’s changing the apostrophe marks automatically.
If you paste the line in a text editor, just replace all the apostrophes manually and you should be able to paste the line into the conf.php file.
Or paste the line in the file and replace the apostrophes before saving.

You will also need to retype the quote marks around “quota” as this format also breaks it. After changing all these, my quota alerts are working correctly. I will also try to use this format to create alerts for cdr quotas. So in conclusion, retype all ’ and " in the file and it should work as intended.

@jult I digress. Discourse does the job just fine with the right fomatting. It is all plain markdown formatting

$config['alert']['macros']['rule']['bill_over_quota_75'] = '(((%bills.total_data/%bills.bill_quota) * 100) >= 75) && %bills.bill_type = "quota"';

It depends on which quotes you use… using the wrong quotes doesn’t work because PHP doesn’t accept them. You need to use '.

The forum is just showing what the user input. If something (like a stupid text editor) modified the quotes along the way, it won’t magically fix the user’s input.