mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 00:24:21 +02:00
Added ability to expand alerts to see triggers
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
<?php
|
||||
if(!isset($vars['format'])) { $vars['format'] = "basic"; }
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<span id="message"></span>
|
||||
@@ -31,7 +34,8 @@ var grid = $("#alerts").bootgrid({
|
||||
{
|
||||
return {
|
||||
id: "alerts",
|
||||
device_id: '<?php echo $device['device_id']; ?>'
|
||||
device_id: '<?php echo $device['device_id']; ?>',
|
||||
format: '<?php echo $vars['format']; ?>'
|
||||
};
|
||||
},
|
||||
url: "/ajax_table.php",
|
||||
@@ -42,6 +46,35 @@ var grid = $("#alerts").bootgrid({
|
||||
"ack": function(column,row) {
|
||||
return "<button type='button' class='btn btn-"+row.ack_col+" btn-sm command-ack-alert' data-target='#ack-alert' data-state='"+row.state+"' data-alert_id='"+row.alert_id+"' name='ack-alert' id='ack-alert' data-extra='"+row.extra+"'><span class='glyphicon glyphicon-"+row.ack_ico+"'aria-hidden='true'></span></button>";
|
||||
}
|
||||
},
|
||||
templates: {
|
||||
header: "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+
|
||||
"<div class=\"col-sm-8 actionBar\"><span class=\"pull-left\">"+
|
||||
<?php
|
||||
|
||||
echo('"<span style=\"font-weight: bold;\">Alerts</span> » "+');
|
||||
|
||||
$menu_options = array('basic' => 'Basic',
|
||||
'detail' => 'Detail');
|
||||
|
||||
$sep = "";
|
||||
foreach ($menu_options as $option => $text)
|
||||
{
|
||||
echo("\"$sep\"+");
|
||||
if ($vars['format'] == $option)
|
||||
{
|
||||
echo("\"<span class='pagemenu-selected'>\"+");
|
||||
}
|
||||
echo('"<a href=\"' . generate_url($vars, array('format' => $option)) . '\">' . $text . '</a>"+');
|
||||
if ($vars['format'] == $option)
|
||||
{
|
||||
echo("\"</span>\"+");
|
||||
}
|
||||
$sep = " | ";
|
||||
}
|
||||
?>
|
||||
"</span></div>"+
|
||||
"<div class=\"col-sm-4 actionBar\"><p class=\"{{css.search}}\"></p><p class=\"{{css.actions}}\"></p></div></div></div>"
|
||||
}
|
||||
}).on("loaded.rs.jquery.bootgrid", function() {
|
||||
grid.find(".command-ack-alert").on("click", function(e) {
|
||||
|
||||
@@ -7,8 +7,7 @@ if (is_numeric($_POST['device_id']) && $_POST['device_id'] > 0) {
|
||||
}
|
||||
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql .= " AND (`timestamp` LIKE '%?%' OR `rule` LIKE '%?%' OR `name` LIKE '%?%' OR `hostname` LIKE '%?%')";
|
||||
$param[] = array($searchPhrase,$searchPhrase,$searchPhrase,$serchPhrase);
|
||||
$sql .= " AND (`timestamp` LIKE '%$searchPhrase%' OR `rule` LIKE '%$searchPhrase%' OR `name` LIKE '%$searchPhrase%' OR `hostname` LIKE '%$searchPhrase%')";
|
||||
}
|
||||
|
||||
$sql = " FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id` RIGHT JOIN alert_rules ON alerts.rule_id=alert_rules.id WHERE $where AND `state` IN (1,2,3,4) $sql";
|
||||
@@ -36,7 +35,9 @@ if ($rowCount != -1) {
|
||||
|
||||
$sql = "SELECT `alerts`.*, `devices`.`hostname` AS `hostname`,`alert_rules`.`rule` AS `rule`, `alert_rules`.`name` AS `name`, `alert_rules`.`severity` AS `severity` $sql";
|
||||
|
||||
system("echo '$sql' >> /tmp/testing");
|
||||
$rulei = 0;
|
||||
$format = $_POST['format'];
|
||||
foreach (dbFetchRows($sql,$param) as $alert) {
|
||||
$log = dbFetchCell("SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1", array($alert['rule_id'],$alert['device_id']));
|
||||
$log_detail = json_decode(gzuncompress($log),true);
|
||||
@@ -44,10 +45,16 @@ foreach (dbFetchRows($sql,$param) as $alert) {
|
||||
$fault_detail = '';
|
||||
foreach ($tmp_alerts as $k=>$v) {
|
||||
if (!empty($v) && $k != 'device_id' && (stristr($k,'id') || stristr($k,'desc')) && substr_count($k,'_') <= 1) {
|
||||
$fault_detail .= $k.' => '.$v.", ";
|
||||
if ($format == 'basic') {
|
||||
$fault_detail .= $k.' => '.$v."\n ";
|
||||
} else {
|
||||
$fault_detail .= $k.' => '.$v.", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
$fault_detail = rtrim($fault_detail,", ");
|
||||
if ($format == 'detail') {
|
||||
$fault_detail = rtrim($fault_detail,", ");
|
||||
}
|
||||
$fault_detail .= "\n";
|
||||
}
|
||||
|
||||
@@ -96,10 +103,15 @@ foreach (dbFetchRows($sql,$param) as $alert) {
|
||||
$ack_col = 'danger';
|
||||
}
|
||||
}
|
||||
if ($format == 'basic') {
|
||||
$hostname = "<a href=\"device/device=".$alert['device_id']."\"><i title='".htmlentities($fault_detail)."'>".$alert['hostname']."</i></a>";
|
||||
} else {
|
||||
$hostname = "<a href=\"device/device=".$alert['device_id']."\"><i>".$alert['hostname']."<br />$fault_detail</i></a>";
|
||||
}
|
||||
|
||||
$response[] = array('id'=>"<i>#".$rulei++."</i>",
|
||||
'rule'=>"<i title=\"".htmlentities($alert['rule'])."\">".htmlentities($alert['name'])."</i>",
|
||||
'hostname'=>"<a href=\"device/device=".$alert['device_id']."\"><i title='".htmlentities($fault_detail)."'>".$alert['hostname']."<br />$fault_detail</i></a>",
|
||||
'hostname'=>$hostname,
|
||||
'timestamp'=>($alert['timestamp'] ? $alert['timestamp'] : "N/A"),
|
||||
'severity'=>$severity,
|
||||
'ack_col'=>$ack_col,
|
||||
|
||||
Reference in New Issue
Block a user