Merge pull request #3148 from ekoyle/alert_template_transport

Alert template transport
This commit is contained in:
Neil Lathwood
2016-03-17 20:58:43 +00:00
2 changed files with 13 additions and 3 deletions

View File

@@ -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);

View File

@@ -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'`~~.