Notifications with Bash

Reading of notifications is not supported, but setting notifications is.

LoxBerry 1.0.3

This function is available starting with LoxBerry V1.0.3. If you use that function, set this minimum version in your plugin.cfg.

Easy notification (notify)

An easy notification can be set with the following code. The parameters are equivalent to LoxBerry::Log::notify

Syntax

notify <package> <name> "<Message>" [err]

For the package, use your plugin's folder name (in Perl/PHP this is $lbpplugindir).

The name parameter defines a name of the group the notification belongs to.

The message needs to be quoted, otherwise it is not seen as one parameter from the notify function.

Set the fourth parameter to "err" or "error" to indicate an error. If you omit this parameter, it will be set as an informational notification.

Example

notify

# Source the functions. Don't forget the dot in front, followed by a white-space
. $LBHOMEDIR/libs/bashlib/notify.sh
 
# Do anything in your script
# ...
 
# An error notification
notify sonos daemon "The Sonos daemon has a communication problem." err
 
# An info notification
notify backup cronjob "The backup was successful."

Extended notification (notify_ext)

The extended notification can add additional attributes to a notification. The parameters listed below are equivalent to them of LoxBerry::Log::notify_ext.

The parameters PACKAGE, NAME, MESSAGE and SEVERITY are mandatory. At all, only 9 parameters are possible, therefore you can add up to 5 custom attributes along to the mandatory fields.

Example

notify

# Source the functions. Don't forget the dot in front, followed by a white-space
. $LBHOMEDIR/libs/bashlib/notify.sh
 
# Do anything in your script
# ...
 
# An error notification
notify_ext PACKAGE=sonos NAME=daemon MESSAGE="The Sonos daemon has a communication problem." SEVERITY=3 customattribute="hello how are you?" additionalattribute="Welcome"
 
# An info notification
notify_ext PACKAGE=sonos NAME=daemon MESSAGE="The Sonos daemon has a communication problem." SEVERITY=6 customattribute="hello how are you?" additionalattribute="Welcome"

Parameters

Not all parameters are required. 

ParameterRequiredBeschreibung
PACKAGE x This is, where the message belongs to. In a plugin, always use the variable $lbpplugindir.
NAME x The notification group, this notification belongs to.
MESSAGE x The message to be sent.
SEVERITY If you omit this parameter, an informational notification (severity 6) is created.

If you specify the severity, use a level from 0 to 7 (see the log levels here: plugindatabase.dat)

Use 6 for info or 3 for error. Other levels currently are undefined.
LINK This optional parameter can be used to add a link with a "Details" button.

Setting the LINK parameter and filling it with an internal or external hyperlink, will show a "Details" button in the get_notifications_html page.
LOGFILE This optional parameter can be used to add a local path to a logfile.

get_notification_html will show a logfile button to directly open the logviewer, if the LOGFILE parameter is found.

See also