mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Show visually in webui + cli when using deprecated templates or transports (#9413)
* Show visually in webui + cli when using deprecated templates or transports * Fixed query
This commit is contained in:
@@ -56,12 +56,14 @@ class Template
|
||||
public function getTitle($data)
|
||||
{
|
||||
$data['parsed_title'] = $this->bladeTitle($data);
|
||||
//FIXME remove Deprecated template
|
||||
return $this->legacyTitle($data);
|
||||
}
|
||||
|
||||
public function getBody($data)
|
||||
{
|
||||
$data['template']['parsed_template'] = $this->bladeBody($data);
|
||||
//FIXME remove Deprecated template
|
||||
return $this->legacyBody($data);
|
||||
}
|
||||
|
||||
@@ -108,6 +110,7 @@ class Template
|
||||
*/
|
||||
public function legacyBody($data)
|
||||
{
|
||||
//FIXME remove Deprecated template
|
||||
$tpl = $data['template']->parsed_template;
|
||||
$msg = '$ret .= "'.str_replace(array('{else}', '{/if}', '{/foreach}'), array('"; } else { $ret .= "', '"; } $ret .= "', '"; } $ret .= "'), addslashes($tpl)).'";';
|
||||
$parsed = $msg;
|
||||
@@ -183,6 +186,7 @@ class Template
|
||||
*/
|
||||
public function legacyTitle($data)
|
||||
{
|
||||
//FIXME remove Deprecated template
|
||||
if (strstr($data['parsed_title'], '%')) {
|
||||
return RunJail('$ret = "'.populate(addslashes($data['parsed_title'])).'";', $data);
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
//FIXME remove Deprecated template
|
||||
/**
|
||||
* convert-template.inc.php
|
||||
*
|
||||
|
||||
@@ -50,6 +50,7 @@ if (!LegacyAuth::user()->hasGlobalAdmin()) {
|
||||
<input type="text" class="form-control input-sm" id="title_rec" name="title_rec" placeholder="Recovery Title">
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary btn-sm" name="create-template" id="create-template">Create template</button>
|
||||
<!--//FIXME remove Deprecated template-->
|
||||
<button type="button" class="btn btn-default btn-sm" name="convert-template" id="convert-template" title="Convert template to new syntax" style="display: none">Convert template</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -113,6 +114,7 @@ $('#alert-template').on('show.bs.modal', function (event) {
|
||||
return data.text;
|
||||
}
|
||||
}).val(selected_rules).trigger("change");
|
||||
//FIXME remove Deprecated template
|
||||
if(output['template'].indexOf("{/if}")>=0){
|
||||
toastr.info('The old template syntax is no longer supported. Please see https://docs.librenms.org/Alerting/Old_Templates/');
|
||||
$('#convert-template').show();
|
||||
@@ -133,6 +135,7 @@ $('#alert-template').on('hide.bs.modal', function(event) {
|
||||
$('#reset-default').remove();
|
||||
$('#name').prop("disabled",false);
|
||||
$('#error').val('');
|
||||
//FIXME remove Deprecated template
|
||||
$('#convert-template').hide();
|
||||
});
|
||||
|
||||
@@ -153,6 +156,7 @@ $('#create-template').click('', function(e) {
|
||||
alertTemplateAjaxOps(template, name, template_id, title, title_rec, rules_items.join(','));
|
||||
});
|
||||
|
||||
//FIXME remove Deprecated template
|
||||
$('#convert-template').click('', function(e) {
|
||||
e.preventDefault();
|
||||
var template = $("#template").val();
|
||||
|
||||
@@ -14,25 +14,27 @@ require_once 'includes/modal/delete_alert_template.inc.php';
|
||||
<th data-column-id="id" data-searchable="false" data-identifier="true" data-type="numeric">#</th>
|
||||
<th data-column-id="templatename">Name</th>
|
||||
<th data-column-id="actions" data-searchable="false" data-formatter="commands">Action</th>
|
||||
<th data-column-id="template" data-searchable="false" data-visible="false">Template</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr data-row-id="0">
|
||||
<td>0</td>
|
||||
<td>Default Alert Template</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<?php
|
||||
$full_query = "SELECT id, name from alert_templates";
|
||||
foreach (dbFetchRows($full_query, $param) as $template) {
|
||||
$full_query = dbFetchRows("SELECT id, name, template from alert_templates", $param);
|
||||
foreach ($full_query as $template) {
|
||||
if ($template['name'] == 'Default Alert Template') {
|
||||
$default_tplid = $template['id'];
|
||||
continue;
|
||||
$template['id'] = 0;
|
||||
}
|
||||
$templates[] = $template;
|
||||
}
|
||||
$template_ids = array_column($templates, 'id');
|
||||
array_multisort($templates, SORT_ASC, $template_ids);
|
||||
foreach ($templates as $template) {
|
||||
echo '<tr data-row-id="'.$template['id'].'">
|
||||
<td>'.$template['id'].'</td>
|
||||
<td>'.$template['name'].'</td>
|
||||
<td></td>
|
||||
<td>'.$template['template'].'</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
@@ -62,10 +64,15 @@ $(document).ready(function() {
|
||||
formatters: {
|
||||
"commands": function(column, row) {
|
||||
var response = '';
|
||||
template = row.template;
|
||||
//FIXME remove Deprecated template
|
||||
if (template.indexOf("{/if}") >= 0) {
|
||||
response = "<button type='button' class='btn btn-xs btn-warning' data-content=' class='btn btn-xs btn-warning' data-content='><i class='fa fa-exclamation-triangle' title='This is a legacy template and needs converting, please edit this template and click convert then save'><i class='fa fa-exclamation-triangle'></i></button> ";
|
||||
}
|
||||
if(row.id == 0) {
|
||||
response = "<button type=\"button\" class=\"btn btn-xs btn-primary command-edit\" data-toggle='modal' data-target='#alert-template' data-template_id=\"" + row.id + "\" data-template_action='edit' name='edit-alert-template'><i class=\"fa fa-pencil\" aria-hidden=\"true\"></i></button> " + "<button type=\"button\" class=\"btn btn-xs btn-danger command-delete\" disabled=\"disabled\"><i class=\"fa fa-trash-o\" aria-hidden=\"true\"></i></button>";
|
||||
response = response + "<button type=\"button\" class=\"btn btn-xs btn-primary command-edit\" data-toggle='modal' data-target='#alert-template' data-template_id=\"" + row.id + "\" data-template_action='edit' name='edit-alert-template'><i class=\"fa fa-pencil\" aria-hidden=\"true\"></i></button> " + "<button type=\"button\" class=\"btn btn-xs btn-danger command-delete\" disabled=\"disabled\"><i class=\"fa fa-trash-o\" aria-hidden=\"true\"></i></button>";
|
||||
} else {
|
||||
response = "<button type=\"button\" class=\"btn btn-xs btn-primary command-edit\" data-toggle='modal' data-target='#alert-template' data-template_id=\"" + row.id + "\" data-template_action='edit' name='edit-alert-template'><i class=\"fa fa-pencil\" aria-hidden=\"true\"></i></button> " + "<button type=\"button\" class=\"btn btn-xs btn-danger command-delete\" data-toggle=\"modal\" data-target='#confirm-delete-alert-template' data-template_id=\"" + row.id + "\" name='delete-alert-template'><i class=\"fa fa-trash-o\" aria-hidden=\"true\"></i></button>";
|
||||
response = response + "<button type=\"button\" class=\"btn btn-xs btn-primary command-edit\" data-toggle='modal' data-target='#alert-template' data-template_id=\"" + row.id + "\" data-template_action='edit' name='edit-alert-template'><i class=\"fa fa-pencil\" aria-hidden=\"true\"></i></button> " + "<button type=\"button\" class=\"btn btn-xs btn-danger command-delete\" data-toggle=\"modal\" data-target='#confirm-delete-alert-template' data-template_id=\"" + row.id + "\" name='delete-alert-template'><i class=\"fa fa-trash-o\" aria-hidden=\"true\"></i></button>";
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -605,7 +605,7 @@ function IssueAlert($alert)
|
||||
|
||||
$obj = DescribeAlert($alert);
|
||||
if (is_array($obj)) {
|
||||
echo 'Issuing Alert-UID #'.$alert['id'].'/'.$alert['state'].': ';
|
||||
echo 'Issuing Alert-UID #'.$alert['id'].'/'.$alert['state'].':' . PHP_EOL;
|
||||
ExtTransports($obj);
|
||||
|
||||
echo "\r\n";
|
||||
@@ -861,20 +861,27 @@ function ExtTransports($obj)
|
||||
|
||||
foreach ($transport_maps as $item) {
|
||||
$class = 'LibreNMS\\Alert\\Transport\\'.ucfirst($item['transport_type']);
|
||||
//FIXME remove Deprecated noteice
|
||||
$dep_notice = 'DEPRECATION NOTICE: https://t.libren.ms/deprecation-alerting';
|
||||
if (class_exists($class)) {
|
||||
$transport_title = ($item['legacy'] === true) ? "{$item['transport_type']} (legacy)" : $item['transport_type'];
|
||||
//FIXME remove Deprecated transport
|
||||
$transport_title = ($item['legacy'] === true) ? "Transport {$item['transport_type']} (%YTransport $dep_notice%n)" : "Transport {$item['transport_type']}";
|
||||
$obj['transport'] = $item['transport_type'];
|
||||
$obj['transport_name'] = $item['transport_name'];
|
||||
$obj['alert'] = new AlertData($obj);
|
||||
$obj['title'] = $type->getTitle($obj);
|
||||
$obj['alert']['title'] = $obj['title'];
|
||||
$obj['msg'] = $type->getBody($obj);
|
||||
echo "$transport_title => ";
|
||||
//FIXME remove Deprecated template check
|
||||
if (preg_match('/{\/if}/', $type->getTemplate()->template)) {
|
||||
c_echo(" :: %YTemplate $dep_notice :: Please update your template " . $type->getTemplate()->name . "%n" . PHP_EOL);
|
||||
}
|
||||
c_echo(" :: $transport_title => ");
|
||||
$instance = new $class($item['transport_id']);
|
||||
$tmp = $instance->deliverAlert($obj, $item['opts']);
|
||||
AlertLog($tmp, $obj, $obj['transport']);
|
||||
unset($instance);
|
||||
echo '; ';
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
INSERT INTO `alert_templates` (`rule_id`, `name`, `template`, `title`, `title_rec`) VALUES (',','BGP Sessions.','%title\\r\\n\nSeverity: %severity\\r\\n\n{if %state == 0}Time elapsed: %elapsed\\r\\n{/if}\nTimestamp: %timestamp\\r\\n\nUnique-ID: %uid\\r\\n\nRule: {if %name}%name{else}%rule{/if}\\r\\n\n{if %faults}Faults:\\r\\n\n{foreach %faults}\n#%key: %value.string\\r\\n\nPeer: %value.astext\\r\\n\nPeer IP: %value.bgpPeerIdentifier\\r\\n\nPeer AS: %value.bgpPeerRemoteAs\\r\\n\nPeer EstTime: %value.bgpPeerFsmEstablishedTime\\r\\n\nPeer State: %value.bgpPeerState\\r\\n\n{/foreach}\n{/if}','','');
|
||||
INSERT INTO `alert_templates` (`rule_id`, `name`, `template`, `title`, `title_rec`) VALUES (',','Ports','%title\\r\\n\nSeverity: %severity\\r\\n\n{if %state == 0}Time elapsed: %elapsed{/if}\nTimestamp: %timestamp\nUnique-ID: %uid\nRule: {if %name}%name{else}%rule{/if}\\r\\n\n{if %faults}Faults:\\r\\n\n{foreach %faults}\\r\\n\n#%key: %value.string\\r\\n\nPort: %value.ifName\\r\\n\nPort Name: %value.ifAlias\\r\\n\nPort Status: %value.message\\r\\n\n{/foreach}\\r\\n\n{/if}\n','','');
|
||||
INSERT INTO `alert_templates` (`rule_id`, `name`, `template`, `title`, `title_rec`) VALUES (',','Temperature','%title\\r\\n\nSeverity: %severity\\r\\n\n{if %state == 0}Time elapsed: %elapsed{/if}\\r\\n\nTimestamp: %timestamp\\r\\n\nUnique-ID: %uid\\r\\n\nRule: {if %name}%name{else}%rule{/if}\\r\\n\n{if %faults}Faults:\\r\\n\n{foreach %faults}\\r\\n\n#%key: %value.string\\r\\n\nTemperature: %value.sensor_current\\r\\n\nPrevious Measurement: %value.sensor_prev\\r\\n\n{/foreach}\\r\\n\n{/if}','','');
|
||||
INSERT INTO `alert_templates` (`name`, `template`) VALUES ('BGP Sessions.', '{{ $alert->title }}\r\n\\r\\n\nSeverity: {{ $alert->severity }}\r\n\\r\\n\n @if ($alert->state == 0) Time elapsed: {{ $alert->elapsed }}\r\n @endif\\r\\n\nTimestamp: {{ $alert->timestamp }}\r\n\\r\\n\nUnique-ID: {{ $alert->uid }}\r\n\\r\\n\nRule: @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif \r\n\\r\\n\n @if ($alert->faults) Faults:\r\n\\r\\n\n @foreach ($alert->faults as $key => $value)\\r\\n\n#{{ $key }}: {{ $value[\'string\'] }}\r\n\\r\\n\nPeer: {{ $value[\'astext\'] }}\r\n\\r\\n\nPeer IP: {{ $value[\'bgpPeerIdentifier\'] }}\r\n\\r\\n\nPeer AS: {{ $value[\'bgpPeerRemoteAs\'] }}\r\n\\r\\n\nPeer EstTime: {{ $value[\'bgpPeerFsmEstablishedTime\'] }}\r\n\\r\\n\nPeer State: {{ $value[\'bgpPeerState\'] }}\r\n\\r\\n\n @endforeach\\r\\n\n @endif');
|
||||
INSERT INTO `alert_templates` (`name`, `template`) VALUES ('Ports', '{{ $alert->title }}\r\n\\r\\n\nSeverity: {{ $alert->severity }}\r\n\\r\\n\n @if ($alert->state == 0) Time elapsed: {{ $alert->elapsed }} @endif\\r\\n\nTimestamp: {{ $alert->timestamp }}\\r\\n\nUnique-ID: {{ $alert->uid }}\\r\\n\nRule: @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif \r\n\\r\\n\n @if ($alert->faults) Faults:\r\n\\r\\n\n @foreach ($alert->faults as $key => $value)\r\n\\r\\n\n#{{ $key }}: {{ $value[\'string\'] }}\r\n\\r\\n\nPort: {{ $value[\'ifName\'] }}\r\n\\r\\n\nPort Name: {{ $value[\'ifAlias\'] }}\r\n\\r\\n\nPort Status: {{ $value[\'message\'] }}\r\n\\r\\n\n @endforeach \r\n\\r\\n\n @endif');
|
||||
INSERT INTO `alert_templates` (`name`, `template`) VALUES ('Temperature', '{{ $alert->title }}\r\n\\r\\n\nSeverity: {{ $alert->severity }}\r\n\\r\\n\n @if ($alert->state == 0) Time elapsed: {{ $alert->elapsed }} @endif \r\n\\r\\n\nTimestamp: {{ $alert->timestamp }}\r\n\\r\\n\nUnique-ID: {{ $alert->uid }}\r\n\\r\\n\nRule: @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif \r\n\\r\\n\n @if ($alert->faults) Faults:\r\n\\r\\n\n @foreach ($alert->faults as $key => $value)\r\n\\r\\n\n#{{ $key }}: {{ $value[\'string\'] }}\r\n\\r\\n\nTemperature: {{ $value[\'sensor_current\'] }}\r\n\\r\\n\nPrevious Measurement: {{ $value[\'sensor_prev\'] }}\r\n\\r\\n\n @endforeach \r\n\\r\\n\n @endif');
|
||||
|
||||
@@ -1 +1 @@
|
||||
INSERT INTO `alert_templates` (name, template) values('Default Alert Template', '%title\r\nSeverity: %severity\r\n{if %state == 0}Time elapsed: %elapsed\r\n{/if}Timestamp: %timestamp\r\nUnique-ID: %uid\r\nRule: {if %name}%name{else}%rule{/if}\r\n{if %faults}Faults:\r\n{foreach %faults} #%key: %value.string\r\n{/foreach}{/if}Alert sent to: {foreach %contacts}%value <%key> {/foreach}');
|
||||
INSERT INTO `alert_templates` (name, template) values('Default Alert Template', '{{ $alert->title }}\\r\\n\nSeverity: {{ $alert->severity }}\\r\\n\n @if ($alert->state == 0) Time elapsed: {{ $alert->elapsed }}\\r\\n\n @endif Timestamp: {{ $alert->timestamp }}\\r\\n\nUnique-ID: {{ $alert->uid }}\\r\\n\nRule: @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif\\r\\n\n @if ($alert->faults) Faults:\\r\\n\n @foreach ($alert->faults as $key => $value) #{{ $key }}: {{ $value[\'string\'] }}\\r\\n\n @endforeach @endif Alert sent to: @foreach ($alert->contacts as $key => $value){{ $value }} <{{ $key }}> @endforeach');
|
||||
|
||||
Reference in New Issue
Block a user