mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add device MIB association browser
This commit is contained in:
91
html/includes/table/device_mibs.inc.php
Normal file
91
html/includes/table/device_mibs.inc.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS device MIB association browser
|
||||
*
|
||||
* Copyright (c) 2015 Gear Consulting Pty Ltd <github@libertysys.com.au>
|
||||
*
|
||||
* by Paul Gear
|
||||
* based on code by Søren Friis Rosiak <sorenrosiak@gmail.com>
|
||||
* in commit 054bf3ae209f34a2c3bc8968300722004903df1b
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
$columns = array(
|
||||
'module',
|
||||
'mib',
|
||||
'included_by',
|
||||
'last_modified',
|
||||
);
|
||||
|
||||
function search_phrase_column($c)
|
||||
{
|
||||
global $searchPhrase;
|
||||
return "$c LIKE '%$searchPhrase%'";
|
||||
}
|
||||
|
||||
function quote_sql_word($c)
|
||||
{
|
||||
return "`$c`";
|
||||
}
|
||||
|
||||
|
||||
$params = array(
|
||||
$_POST['device_id'],
|
||||
);
|
||||
|
||||
// start of sql definition
|
||||
$sql = 'SELECT * FROM `device_mibs`';
|
||||
|
||||
$wheresql = ' WHERE `device_id` = ?';
|
||||
|
||||
// all columns are searchable - search across them
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$searchsql = implode(' OR ', array_map("search_phrase_column", array_map("quote_sql_word", $columns)));
|
||||
$wheresql .= " AND ( $searchsql )";
|
||||
}
|
||||
$sql .= $wheresql;
|
||||
|
||||
// get total
|
||||
$count_sql = "SELECT COUNT(*) FROM `device_mibs`".$wheresql;
|
||||
$total = dbFetchCell($count_sql, $params);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
|
||||
// sort by first three columns by default
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = implode(', ', array_map("quote_sql_word", array_slice($columns, 0, 3)));
|
||||
}
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
// select only the required rows
|
||||
if (isset($current)) {
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
|
||||
// load data from database into response array
|
||||
$response = array();
|
||||
foreach (dbFetchRows($sql, $params) as $mib) {
|
||||
$mibrow = array();
|
||||
foreach ($columns as $col) {
|
||||
$mibrow[$col] = $mib[$col];
|
||||
}
|
||||
$response[] = $mibrow;
|
||||
}
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
@@ -371,6 +371,14 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) {
|
||||
</a>
|
||||
</li>';
|
||||
|
||||
if (device_permitted($device['device_id'])) {
|
||||
echo '<li class="'.$select['mib'].'">
|
||||
<a href="'.generate_device_url($device, array('tab' => 'mib')).'">
|
||||
<i class="fa fa-file-text-o"></i> MIB
|
||||
</a>
|
||||
</li>';
|
||||
}
|
||||
|
||||
|
||||
echo '<li style="float: right;"><a href="https://'.$device['hostname'].'"><img src="images/16/http.png" alt="https" title="Launch browser to https://'.$device['hostname'].'" border="0" width="16" height="16" target="_blank"></a></li>
|
||||
<li style="float: right;"><a href="ssh://'.$device['hostname'].'"><img src="images/16/ssh.png" alt="ssh" title="SSH to '.$device['hostname'].'" border="0" width="16" height="16"></a></li>
|
||||
|
52
html/pages/device/mib.inc.php
Normal file
52
html/pages/device/mib.inc.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS device MIB association browser
|
||||
*
|
||||
* Copyright (c) 2015 Gear Consulting Pty Ltd <github@libertysys.com.au>
|
||||
*
|
||||
* Author: Paul Gear
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
if (!isset($vars['section'])) {
|
||||
$vars['section'] = "mib";
|
||||
}
|
||||
?>
|
||||
|
||||
<h4><i class="fa fa-file-text-o"></i> Device MIB associations</h4>
|
||||
<div class="table-responsive">
|
||||
<table id="mibs" class="table table-hover table-condensed mibs">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="module">Module</th>
|
||||
<th data-column-id="mib">MIB</th>
|
||||
<th data-column-id="included_by">Included by</th>
|
||||
<th data-column-id="last_modified">Last Modified</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var grid = $("#mibs").bootgrid({
|
||||
ajax: true,
|
||||
rowCount: [50,100,250,-1],
|
||||
post: function ()
|
||||
{
|
||||
return {
|
||||
id: "device_mibs",
|
||||
device_id: '<?php echo htmlspecialchars($device['device_id']); ?>',
|
||||
};
|
||||
},
|
||||
url: "/ajax_table.php",
|
||||
formatters: {
|
||||
},
|
||||
templates: {
|
||||
}
|
||||
});
|
||||
</script>
|
Reference in New Issue
Block a user