diff --git a/alerts.php b/alerts.php index 827d5063e1..4ccf2e2fb3 100755 --- a/alerts.php +++ b/alerts.php @@ -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); diff --git a/doc/Extensions/Alerting.md b/doc/Extensions/Alerting.md index 09e269dd9b..15a38291f7 100644 --- a/doc/Extensions/Alerting.md +++ b/doc/Extensions/Alerting.md @@ -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
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}%hostname{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. + + # Transports Transports are located within `$config['install_dir']/includes/alerts/transports.*.php` and defined as well as configured via ~~`$config['alert']['transports']['Example'] = 'Some Options'`~~.