mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #706 from laf/bootgrid-alert-log
Updated alertlog to use bootgrid
This commit is contained in:
@@ -14,9 +14,9 @@ $pdf->AddPage('L');
|
||||
}
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
$query = " 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 ORDER BY `time_logged` DESC";
|
||||
$query = " 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 ORDER BY `humandate` DESC";
|
||||
} else {
|
||||
$query = " 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 = ? ORDER BY `time_logged` DESC";
|
||||
$query = " 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 = ? ORDER BY `humandate` DESC";
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
|
76
html/includes/table/alertlog.inc.php
Normal file
76
html/includes/table/alertlog.inc.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
$where = 1;
|
||||
|
||||
if (is_numeric($_POST['device_id'])) {
|
||||
$where .= ' AND E.device_id = ?';
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
|
||||
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 = ?";
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `E`.`time_logged` LIKE '%$searchPhrase%' OR `name` LIKE '%$searchPhrase%')";
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`E`.`id`) $sql";
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = 'time_logged DESC';
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
|
||||
$sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '%D %b %Y %T') as humandate $sql";
|
||||
|
||||
foreach (dbFetchRows($sql,$param) as $alertlog) {
|
||||
$dev = device_by_id_cache($alertlog['device_id']);
|
||||
$alert_state = $alertlog['state'];
|
||||
if ($alert_state=='0') {
|
||||
$glyph_icon = 'ok';
|
||||
$glyph_color = 'green';
|
||||
$text = 'Ok';
|
||||
}
|
||||
elseif ($alert_state=='1') {
|
||||
$glyph_icon = 'remove';
|
||||
$glyph_color = 'red';
|
||||
$text = 'Alert';
|
||||
}
|
||||
elseif ($alert_state=='2') {
|
||||
$glyph_icon = 'info-sign';
|
||||
$glyph_color = 'lightgrey';
|
||||
$text = 'Ack';
|
||||
}
|
||||
elseif ($alert_state=='3') {
|
||||
$glyph_icon = 'arrow-down';
|
||||
$glyph_color = 'orange';
|
||||
$text = 'Worse';
|
||||
}
|
||||
elseif ($alert_state=='4') {
|
||||
$glyph_icon = 'arrow-up';
|
||||
$glyph_color = 'khaki';
|
||||
$text = 'Better';
|
||||
}
|
||||
$response[] = array('humandate'=>$alertlog['humandate'],
|
||||
'hostname'=>generate_device_link($dev, shorthost($dev['hostname'])),
|
||||
'alert'=>htmlspecialchars($alertlog['alert']),
|
||||
'status'=>"<b><span class='glyphicon glyphicon-".$glyph_icon."' style='color:".$glyph_color."'></span> $text</b>");
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
echo _json_encode($output);
|
@@ -1,116 +1,78 @@
|
||||
<?php
|
||||
$param = array();
|
||||
if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
|
||||
$numresults = $_POST['results_amount'];
|
||||
} else {
|
||||
$numresults = 250;
|
||||
}
|
||||
if (isset($_POST['page_number']) && $_POST['page_number'] > 0) {
|
||||
$page_number = $_POST['page_number'];
|
||||
} else {
|
||||
$page_number = 1;
|
||||
}
|
||||
$start = ($page_number - 1) * $numresults;
|
||||
|
||||
$pagetitle[] = "Alert Log";
|
||||
print_optionbar_start();
|
||||
$where = "1";
|
||||
if (is_numeric($_POST['device']))
|
||||
{
|
||||
$where .= ' AND E.device_id = ?';
|
||||
$param[] = $_POST['device'];
|
||||
}
|
||||
if ($_POST['string'])
|
||||
{
|
||||
$where .= " AND R.rule LIKE ?";
|
||||
$param[] = "%".$_POST['string']."%";
|
||||
}
|
||||
?>
|
||||
|
||||
<form method="post" action="" class="form-inline" role="form" id="result_form">
|
||||
<div class="form-group">
|
||||
<input type="text" name="string" id="string" value="<?php echo($_POST['string']); ?>" placeholder="Search" class="form-control input-sm" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<strong>Device</strong>
|
||||
</label>
|
||||
<select name="device" id="device" class="form-control input-sm">
|
||||
<select name="device_id" id="device_id" class="form-control input-sm">
|
||||
<option value="">All Devices</option>
|
||||
<?php
|
||||
foreach (get_all_devices() as $hostname)
|
||||
{
|
||||
echo("<option value='".getidbyname($hostname)."'");
|
||||
if (getidbyname($hostname) == $_POST['device']) { echo("selected"); }
|
||||
if (getidbyname($hostname) == $_POST['device_id']) { echo("selected"); }
|
||||
echo(">".$hostname."</option>");
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default input-sm">Search</button>
|
||||
<button type="submit" class="btn btn-default input-sm">Filter</button>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
print_optionbar_end();
|
||||
if ($_SESSION['userlevel'] >= '5')
|
||||
{
|
||||
$query = " 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 ORDER BY `time_logged` DESC";
|
||||
} else {
|
||||
$query = " 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 = ? ORDER BY `time_logged` DESC";
|
||||
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
$count_query = "SELECT COUNT(time_logged) $query";
|
||||
$count = dbFetchCell($count_query,$param);
|
||||
$full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '%D %b %Y %T') as humandate $query LIMIT $start,$numresults";
|
||||
echo('<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<strong>Alert Log entries</strong><br /><br />
|
||||
<a href="pdf.php?report=alert-log&device_id='.$_POST['device'].'&string='.$_POST['string'].'&results='.$numresults.'&start='.$page_number.'"><img src="images/16/pdf.png" width="16" height="16" alt="Export to pdf"> Export to pdf</a>
|
||||
<strong>Alert Log entries</strong>
|
||||
</div>
|
||||
<div class="col-md-8" align="center">'. generate_pagination($count,$numresults,$page_number) .'</div>
|
||||
<div class="col-md-2">
|
||||
<select name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">');
|
||||
$result_options = array('10','50','100','250','500','1000','5000');
|
||||
foreach($result_options as $option) {
|
||||
echo "<option value='$option'";
|
||||
if ($numresults == $option) {
|
||||
echo " selected";
|
||||
}
|
||||
echo ">$option</option>";
|
||||
}
|
||||
echo('
|
||||
</select>
|
||||
<div class="col-md-2 col-md-offset-8">
|
||||
<div class="pull-right pdf-export"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-hover table-condensed table-striped">');
|
||||
foreach (dbFetchRows($full_query, $param) as $alert_entry)
|
||||
{
|
||||
include("includes/print-alerts.inc.php");
|
||||
}
|
||||
if ($count % $numresults > 0) {
|
||||
echo(' <tr>
|
||||
<td colspan="6" align="center">'. generate_pagination($count,$numresults,$page_number) .'</td>
|
||||
</tr>');
|
||||
}
|
||||
echo('</table>
|
||||
<input type="hidden" name="page_number" id="page_number" value="'.$page_number.'">
|
||||
<input type="hidden" name="results_amount" id="results_amount" value="'.$numresults.'">
|
||||
</form>');
|
||||
');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
function updateResults(results) {
|
||||
$('#results_amount').val(results.value);
|
||||
$('#page_number').val(1);
|
||||
$('#result_form').submit();
|
||||
}
|
||||
|
||||
function changePage(page,e) {
|
||||
e.preventDefault();
|
||||
$('#page_number').val(page);
|
||||
$('#result_form').submit();
|
||||
}
|
||||
<table id="alertlog" class="table table-hover table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="humandate" data-order="desc">Time logged</th>
|
||||
<th data-column-id="hostname">Device</th>
|
||||
<th data-column-id="alert">alert</th>
|
||||
<th data-column-id="status" data-sortable="false">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
var grid = $("#alertlog").bootgrid({
|
||||
ajax: true,
|
||||
post: function ()
|
||||
{
|
||||
return {
|
||||
id: "alertlog",
|
||||
device_id: '<?php echo htmlspecialchars($_POST['device_id']); ?>'
|
||||
};
|
||||
},
|
||||
url: "/ajax_table.php"
|
||||
}).on("loaded.rs.jquery.bootgrid", function() {
|
||||
|
||||
var results = $("div.infos").text().split(" ");
|
||||
low = results[1] -1 ;
|
||||
high = results[3];
|
||||
max = high - low;
|
||||
search = $('.search-field').val();
|
||||
|
||||
$(".pdf-export").html("<a href='pdf.php?report=alert-log&device_id=<?php echo $_POST['device_id'];?>&string="+search+"&results="+max+"&start="+low+"'><img src='images/16/pdf.png' width='16' height='16' alt='Export to pdf'> Export to pdf</a>");
|
||||
});
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user