Coriant Network Hardware Page. (#6187)

* Fix the definition. Should be mef instead of mef-evc

* Added Coriant TNMS Hardware page.

* Polling and discovery modules for TNMS Network Equipements.

* SQL in one line.

* Only show when OS is coriant

* Fix conflict file

* Conflict file

* Added missing COLLATE

* Refactor poller code for more data to be inserted into DB in the future.
Removed the discovery module and merged it into poller code.

* Removed tnms-nbi discovery also in the yaml

* Removing debug

* Code updates and fixes + schema rename

* bootstrapify the code.
Renamed the sql file

* Bloody tabs !

* Add db_schema.yaml update.
This commit is contained in:
Xavier Beaudouin
2017-04-12 11:39:02 +02:00
committed by Neil Lathwood
parent 069020cb80
commit 4b0972628f
7 changed files with 250 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
<?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(
'neName',
'neLocation',
'neType',
'neOpMode',
'neAlarm',
'neOpState',
);
if (isset($_POST['device_id'])) {
$params = array(
$_POST['device_id'],
);
$sql = 'SELECT `neName`,`neLocation`,`neType`,`neOpMode`,`neAlarm`,`neOpState` FROM `tnmsneinfo`';
$wheresql = ' WHERE `device_id` = ?';
$sortcolumns = 3;
$count_sql = "SELECT COUNT(id) FROM `tnmsneinfo`".$wheresql;
// all columns are searchable - search across them
if (isset($searchPhrase) && !empty($searchPhrase)) {
$searchsql = implode(' OR ', array_map("search_phrase_column", array_map("mres", $columns)));
$wheresql .= " AND ( $searchsql )";
}
$sql .= $wheresql;
// get total
$total = dbFetchCell($count_sql, $params);
if (empty($total)) {
$total = 0;
}
// set up default sort
if (!isset($sort) || empty($sort)) {
$sort = implode(', ', array_map("mres", array_slice($columns, 0, $sortcolumns)));
}
$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 $tnmsne) {
if ($tnmsne['neOpMode'] == 'operation') {
$neop = '<span style="min-width:40px; display:inlink-block;" class="label label-success">operation</span>';
} else {
$neop = '<span style="min-width:40px; display:inlink-block;" class="label label-danger">' . $tnmsne['neOpMode'] . '</span>';
}
switch ($tnmsne['neAlarm']) {
case "cleared":
$alarm = '<span style="min-width:40px; display:inline-block;" class="label label-success">cleared</span>';
break;
case "warning":
$alarm = '<span style="min-width:40px; display:inline-block;" class="label label-warning">warning</span>';
break;
case "minor":
case "major":
case "critical":
case "indeterminate":
$alarm = '<span style="min-width:40px; display:inline-block;" class="label label-danger">' . $tnmsne['neAlarm'] . '</span>';
break;
default:
$alarm = '<span style="min-width:40px; display:inline-block;" class="label label-default">' . $tnmsne['neAlarm'] . '</span>';
}
if ($tnmsne['neOpState'] == 'enabled') {
$opstate = '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-success">enabled</span></td>';
} else {
$opstate = '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-danger">'.$tnmsne['neOpState'].'</span></td>';
}
$response[] = array(
'neName' => $tnmsne['neName'],
'neLocation' => $tnmsne['neLocation'],
'neType' => $tnmsne['neType'],
'neOpMode' => $neop,
'neAlarm' => $alarm,
'neOpState' => $opstate,
);
}
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
);
echo _json_encode($output);
}

View File

@@ -167,6 +167,16 @@ if (device_permitted($vars['device']) || $permitted_by_port) {
</li>';
}
if ($device['os'] == 'coriant') {
if (@dbFetchCell("SELECT COUNT(id) FROM tnmsneinfo WHERE device_id = '".$device['device_id']."'") > '0') {
echo '<li class="'.$select['tnmsne'].'">
<a href="'.generate_device_url($device, array('tab' => 'tnmsne')).'">
<i class="fa fa-link fa-lg icon-theme" aria-hidden="true"></i> Hardware
</a>
</li>';
}
}
// $loadbalancer_tabs is used in device/loadbalancer/ to build the submenu. we do it here to save queries
if ($device['os'] == 'netscaler') {
// Netscaler

View File

@@ -0,0 +1,40 @@
<?php
if (!isset($var['section'])) {
$vars['section'] = "tnmsne";
}
$pagetitle[] = 'Hardware';
?>
<h4><i class="fa fa-file-info-text-o"></i> Coriant NE Hardware</h4>
<div class="table-responsive">
<table id="tnmsne" class="table table-hover table-condensed tnmsne">
<thead>
<tr>
<th data-column-id="neName">Name</th>
<th data-column-id="neLocation">Location</th>
<th data-column-id="neType">Type</th>
<th data-column-id="neOpMode">Operation Mode</th>
<th data-column-id="neAlarm">Alarm</th>
<th data-column-id="neOpState">State</th>
</tr>
</thead>
</table>
</div>
<script>
var grid = $("#tnmsne").bootgrid({
ajax: true,
rowCount: [50,100,250,-1],
post: function()
{
return {
id: "tnmsneinfo",
device_id: '<?php echo htmlspecialchars($device['device_id']); ?>',
};
},
url: "ajax_table.php",
formatters: {
},
templates: {
}
});
</script>

View File

@@ -0,0 +1,26 @@
<?php
/**
* coriant.inc.php
*
* LibreNMS os poller module for Coriant
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2017 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
require 'includes/polling/os/misc/tnms-nbi.inc.php';

View File

@@ -0,0 +1,48 @@
<?php
echo 'TNMS-NBI-MIB: ';
/*
* Coriant have done some SQL over SNMP, since we have to populate and update all the tables
* before using it, we have to do ugly stuff
*/
function SqlSNMP($table, $cmib, $device)
{
echo " $cmib ";
$c_oids = snmpwalk_cache_multi_oid($device, $cmib, array(), 'TNMS-NBI-MIB');
$c_list = array();
foreach ($c_oids as $index => $entry) {
$neType = $entry['enmsNeType'];
$neName = $entry['enmsNeName'];
$neLocation = $entry['enmsNeLocation'];
$neAlarm = $entry['enmsNeAlarmSeverity'];
$neOpMode = $entry['enmsNeOperatingMode'];
$neOpState = $entry['enmsNeOpState'];
if (dbFetchCell("SELECT COUNT(id) FROM $table WHERE `device_id` = ? AND `neID` = ?", array($device['device_id'], $index)) == 0) {
dbInsert(array('device_id' => $device['device_id'], 'neID' => $index, 'neType' => mres($neType), 'neName' => mres($neName), 'neLocation' => mres($neLocation), 'neAlarm' => mres($neAlarm), 'neOpMode' => mres($neOpMode), 'neOpState' => mres($neOpState)), $table);
log_event("Coriant $cmib Hardware ". mres($neType) . " : " . mres($neName) . " ($index) at " . mres($neLocation) . " Discovered", $device, 'system', 2);
echo '+';
} else {
echo '.';
}
$c_list[] = $index;
}
$sql = "SELECT id, neID, neName FROM $table WHERE device_id = ?";
$params = array($device['device_id']);
foreach (dbFetchRows($sql, $params) as $db_ne) {
d_echo($db_ne);
if (!in_array($db_ne['neID'], $c_list)) {
dbDelete($table, '`id` = ?', array($db_ne['id']));
log_event("Coriant $cmib Hardware ".mres($db_ne['neName']).' at ' . mres($db_ne['neLocation']) . ' Removed', $device, 'system', $db_ne['neID']);
echo '-';
}
}
}
SqlSNMP('tnmsneinfo', 'enmsNETable', $device);
echo PHP_EOL;

View File

@@ -1454,6 +1454,21 @@ syslog:
datetime: { Name: datetime, Columns: [timestamp], Unique: false, Type: BTREE }
device_id: { Name: device_id, Columns: [device_id], Unique: false, Type: BTREE }
program: { Name: program, Columns: [program], Unique: false, Type: BTREE }
tnmsneinfo:
Columns:
device_id: { Field: device_id, Type: int(11), 'Null': false, Default: null, Extra: '' }
id: { Field: id, Type: int(11), 'Null': false, Default: null, Extra: auto_increment }
neAlarm: { Field: neAlarm, Type: varchar(128), 'Null': false, Default: null, Extra: '' }
neID: { Field: neID, Type: int(32), 'Null': false, Default: null, Extra: '' }
neLocation: { Field: neLocation, Type: varchar(128), 'Null': false, Default: null, Extra: '' }
neName: { Field: neName, Type: varchar(128), 'Null': false, Default: null, Extra: '' }
neOpMode: { Field: neOpMode, Type: varchar(128), 'Null': false, Default: null, Extra: '' }
neOpState: { Field: neOpState, Type: varchar(128), 'Null': false, Default: null, Extra: '' }
neType: { Field: neType, Type: varchar(128), 'Null': false, Default: null, Extra: '' }
Indexes:
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
device_id: { Name: device_id, Columns: [device_id], Unique: false, Type: BTREE }
neID: { Name: neID, Columns: [neID], Unique: false, Type: BTREE }
toner:
Columns:
device_id: { Field: device_id, Type: int(11), 'Null': false, Default: '0', Extra: '' }

1
sql-schema/185.sql Normal file
View File

@@ -0,0 +1 @@
CREATE TABLE IF NOT EXISTS `tnmsneinfo` ( `id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `neID` int(32) NOT NULL, `neType` varchar(128) NOT NULL, `neName` varchar(128) NOT NULL, `neLocation` varchar(128) NOT NULL, `neAlarm` varchar(128) NOT NULL, `neOpMode` varchar(128) NOT NULL, `neOpState` varchar(128) NOT NULL, PRIMARY KEY (`id`), KEY `device_id` (`device_id`), KEY `neID` (`neID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;