mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #3148 from ekoyle/alert_template_transport
Alert template transport
This commit is contained in:
@@ -121,8 +121,6 @@ function IssueAlert($alert) {
|
||||
$obj = DescribeAlert($alert);
|
||||
if (is_array($obj)) {
|
||||
echo 'Issuing Alert-UID #'.$alert['id'].'/'.$alert['state'].': ';
|
||||
$msg = FormatAlertTpl($obj);
|
||||
$obj['msg'] = $msg;
|
||||
if (!empty($config['alert']['transports'])) {
|
||||
ExtTransports($obj);
|
||||
}
|
||||
@@ -338,6 +336,9 @@ function ExtTransports($obj) {
|
||||
$opts = array_filter($opts);
|
||||
}
|
||||
if (($opts === true || !empty($opts)) && $opts != false && file_exists($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php')) {
|
||||
$obj['transport'] = $transport;
|
||||
$msg = FormatAlertTpl($obj);
|
||||
$obj['msg'] = $msg;
|
||||
echo $transport.' => ';
|
||||
eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php').' return false; };');
|
||||
$tmp = $tmp($obj,$opts);
|
||||
|
@@ -99,7 +99,7 @@ The template-parser understands `if` and `foreach` controls and replaces certain
|
||||
Controls:
|
||||
|
||||
- if-else (Else can be omitted):
|
||||
`{if %placeholder == 'value'}Some Text{else}Other Text{/if}`
|
||||
`{if %placeholder == value}Some Text{else}Other Text{/if}`
|
||||
- foreach-loop:
|
||||
`{foreach %placeholder}Key: %key<br/>Value: %value{/foreach}`
|
||||
|
||||
@@ -116,6 +116,7 @@ Placeholders:
|
||||
- Rule: `%rule`
|
||||
- Rule-Name: `%name`
|
||||
- Timestamp: `%timestamp`
|
||||
- Transport name: `%transport`
|
||||
- Contacts, must be iterated in a foreach, `%key` holds email and `%value` holds name: `%contacts`
|
||||
|
||||
The Default Template is a 'one-size-fit-all'. We highly recommend defining own templates for your rules to include more specific information.
|
||||
@@ -136,6 +137,14 @@ Rule: {if %name}%name{else}%rule{/if}\r\n
|
||||
Alert sent to: {foreach %contacts}%value <%key> {/foreach}
|
||||
```
|
||||
|
||||
Conditional formatting example, will display a link to the host in email or just the hostname in any other transport:
|
||||
```text
|
||||
{if %transport == mail}<a href="https://my.librenms.install/device/device=%hostname/">%hostname</a>{else}%hostname{/if}
|
||||
```
|
||||
|
||||
Note the use of double-quotes. Single quotes (`'`) in templates will be escaped (replaced with `\'`) in the output and should therefore be avoided.
|
||||
|
||||
|
||||
# <a name="transports">Transports</a>
|
||||
|
||||
Transports are located within `$config['install_dir']/includes/alerts/transports.*.php` and defined as well as configured via ~~`$config['alert']['transports']['Example'] = 'Some Options'`~~.
|
||||
|
Reference in New Issue
Block a user