webui: Alerts table refresh (#7765)

* initial release

* changed layout, matching pr 7628

* style changes
usage of short hostname

* alerts page cleanup

* reduced css class, added js function

* initial release

* added min-height, also apply min-height via js if parrent is smaller

* remove status column
This commit is contained in:
crcro
2017-12-24 21:55:24 +02:00
committed by Neil Lathwood
parent d11808aad4
commit 34e07a1d66
8 changed files with 280 additions and 268 deletions

View File

@@ -1,9 +1,22 @@
<?php
/*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*
* @package LibreNMS
* @subpackage graphs
* @link http://librenms.org
* @copyright 2017 LibreNMS
* @author LibreNMS Contributors
*/
$where = 1;
if (is_numeric($_POST['device_id'])) {
$where .= ' AND E.device_id = ?';
$where .= ' AND E.device_id = ?';
$param[] = $_POST['device_id'];
}
@@ -15,7 +28,7 @@ if ($_POST['state'] >= 0) {
if ($_SESSION['userlevel'] >= '5') {
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where";
} else {
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?";
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?";
$param[] = array($_SESSION['user_id']);
}
@@ -24,7 +37,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
}
$count_sql = "SELECT COUNT(`E`.`id`) $sql";
$total = dbFetchCell($count_sql, $param);
$total = dbFetchCell($count_sql, $param);
if (empty($total)) {
$total = 0;
}
@@ -36,7 +49,7 @@ if (!isset($sort) || empty($sort)) {
$sql .= " ORDER BY $sort";
if (isset($current)) {
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_high = $rowCount;
}
@@ -44,53 +57,45 @@ if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT D.device_id,name AS alert,rule_id, state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate,details $sql";
$sql = "SELECT D.device_id,name AS alert,rule_id, state,time_logged,DATE_FORMAT(time_logged, '" . $config['dateformat']['mysql']['compact'] . "') as humandate,details $sql";
$rulei = 0;
foreach (dbFetchRows($sql, $param) as $alertlog) {
$dev = device_by_id_cache($alertlog['device_id']);
$dev = device_by_id_cache($alertlog['device_id']);
logfile($alertlog['rule_id']);
$log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? AND `state` = 1 ORDER BY id DESC LIMIT 1', array($alertlog['rule_id'], $alertlog['device_id']));
$log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? AND `state` = 1 ORDER BY id DESC LIMIT 1', array($alertlog['rule_id'], $alertlog['device_id']));
$fault_detail = alert_details($log);
if (empty($fault_detail)) {
$fault_detail = 'Rule created, no faults found';
}
$alert_state = $alertlog['state'];
$alert_state = $alertlog['state'];
if ($alert_state == '0') {
$fa_icon = 'check';
$fa_color = 'success';
$text = 'Ok';
$status = 'label-success';
} elseif ($alert_state == '1') {
$fa_icon = 'times';
$fa_color = 'danger';
$text = 'Alert';
$status = 'label-danger';
} elseif ($alert_state == '2') {
$fa_icon = 'info-circle';
$fa_color = 'muted';
$text = 'Ack';
$status = 'label-info';
} elseif ($alert_state == '3') {
$fa_icon = 'arrow-down';
$fa_color = 'warning';
$text = 'Worse';
$status = 'label-warning';
} elseif ($alert_state == '4') {
$fa_icon = 'arrow-up';
$fa_color = 'info';
$text = 'Better';
$status = 'label-primary';
}//end if
$response[] = array(
'id' => $rulei++,
'id' => $rulei++,
'time_logged' => $alertlog['humandate'],
'details' => '<a class="fa fa-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident'.($rulei).'" data-parent="#alerts"></a>',
'hostname' => '<div class="incident">'.generate_device_link($dev, shorthost($dev['hostname'])).'<div id="incident'.($rulei).'" class="collapse">'.$fault_detail.'</div></div>',
'alert' => htmlspecialchars($alertlog['alert']),
'status' => "<b><i class='fa fa-".$fa_icon." text-".$fa_color."'></i> $text</b>",
'details' => '<a class="fa fa-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident' . ($rulei) . '" data-parent="#alerts"></a>',
'hostname' => '<div class="incident">' . generate_device_link($dev, shorthost($dev['hostname'])) . '<div id="incident' . ($rulei) . '" class="collapse">' . $fault_detail . '</div></div>',
'alert' => htmlspecialchars($alertlog['alert']),
'status' => "<i class='alert-status " . $status . "'></i>"
);
}//end foreach
$output = array(
'current' => $current,
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
'rows' => $response,
'total' => $total,
);
echo _json_encode($output);