mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #1811 from laf/issue-1689
Ability to override the ports ifAlias
This commit is contained in:
48
html/includes/forms/update-ifalias.inc.php
Normal file
48
html/includes/forms/update-ifalias.inc.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
$status = 'error';
|
||||
|
||||
$descr = mres($_POST['descr']);
|
||||
$device_id = mres($_POST['device_id']);
|
||||
$ifName = mres($_POST['ifName']);
|
||||
$port_id = mres($_POST['port_id']);
|
||||
|
||||
logfile($descr . ','. $device_id . ','. $ifName. ','. $port_id);
|
||||
|
||||
if (!empty($ifName) && is_numeric($port_id)) {
|
||||
// We have ifName and port id so update ifAlias
|
||||
if (empty($descr)) {
|
||||
$descr = 'repoll';
|
||||
// Set to repoll so we avoid using ifDescr on port poll
|
||||
}
|
||||
if (dbUpdate(array('ifAlias'=>$descr), 'ports', '`port_id`=?', array($port_id)) > 0) {
|
||||
$device = device_by_id_cache($device_id);
|
||||
if ($descr === 'repoll') {
|
||||
del_dev_attrib($device, 'ifName');
|
||||
}
|
||||
else {
|
||||
set_dev_attrib($device, 'ifName', $ifName);
|
||||
}
|
||||
$status = 'ok';
|
||||
}
|
||||
else {
|
||||
$status = 'na';
|
||||
}
|
||||
}
|
||||
|
||||
$response = array(
|
||||
'status' => $status,
|
||||
);
|
||||
echo _json_encode($response);
|
@@ -64,7 +64,7 @@ foreach (dbFetchRows($sql, $param) as $port) {
|
||||
<input type="hidden" name="olddis_'.$port['port_id'].'" value="'.($port['disabled'] ? 1 : 0).'"">',
|
||||
'ignore' => '<input type="checkbox" class="ignore-check" name="ignore_'.$port['port_id'].'"'.($port['ignore'] ? 'checked' : '').'>
|
||||
<input type="hidden" name="oldign_'.$port['port_id'].'" value="'.($port['ignore'] ? 1 : 0).'"">',
|
||||
'ifAlias' => $port['ifAlias']
|
||||
'ifAlias' => '<div class="form-group"><input class="form-control input-sm" id="if-alias" name="if-alias" data-device_id="'.$port['device_id'].'" data-port_id="'.$port['port_id'].'" data-ifName="'.$port['ifName'].'" value="'.$port['ifAlias'].'"><span class="glyphicon form-control-feedback" aria-hidden="true"></span></div>'
|
||||
);
|
||||
|
||||
}//end foreach
|
||||
@@ -75,4 +75,4 @@ $output = array(
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
echo _json_encode($output);
|
||||
|
@@ -1,10 +1,12 @@
|
||||
</form>
|
||||
<span id="message"><small><div class="alert alert-danger">n.b For the first time, please click any button twice.</div></small></span>
|
||||
|
||||
<form id='ignoreport' name='ignoreport' method='post' action='' role='form' class='form-inline'>
|
||||
<input type='hidden' name='ignoreport' value='yes'>
|
||||
<input type='hidden' name='type' value='update-ports'>
|
||||
<input type='hidden' name='device' value='<?php echo $device['device_id'];?>'>
|
||||
<table id='edit-ports' class='table table-condensed table-responsive table-striped'>
|
||||
<div class='table-responsibe'>
|
||||
<table id='edit-ports' class='table table-striped'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id='ifIndex'>Index</th>
|
||||
@@ -17,9 +19,50 @@
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
|
||||
$(document).on('blur', "[name='if-alias']", function (){
|
||||
var $this = $(this);
|
||||
var descr = $this.val();
|
||||
var device_id = $this.data('device_id');
|
||||
var port_id = $this.data('port_id');
|
||||
var ifName = $this.data('ifname');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax_form.php',
|
||||
data: {type: "update-ifalias", descr: descr, ifName: ifName, port_id: port_id, device_id: device_id},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
$this.closest('.form-group').addClass('has-success');
|
||||
$this.next().addClass('glyphicon-ok');
|
||||
setTimeout(function(){
|
||||
$this.closest('.form-group').removeClass('has-success');
|
||||
$this.next().removeClass('glyphicon-ok');
|
||||
}, 2000);
|
||||
} else if (data.status == 'na') {
|
||||
|
||||
} else {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$this.next().addClass('glyphicon-remove');
|
||||
setTimeout(function(){
|
||||
$this.closest('.form-group').removeClass('has-error');
|
||||
$this.next().removeClass('glyphicon-remove');
|
||||
}, 2000);
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$this.next().addClass('glyphicon-remove');
|
||||
setTimeout(function(){
|
||||
$this.closest('.form-group').removeClass('has-error');
|
||||
$this.next().removeClass('glyphicon-remove');
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
});
|
||||
$(document).ready(function() {
|
||||
$('form#ignoreport').submit(function (event) {
|
||||
$('#disable-toggle').click(function (event) {
|
||||
@@ -96,6 +139,7 @@
|
||||
});
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
var grid = $("#edit-ports").bootgrid({
|
||||
|
@@ -435,8 +435,14 @@ function get_dev_entity_state($device) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
function get_dev_attrib($device, $attrib_type) {
|
||||
if ($row = dbFetchRow("SELECT attrib_value FROM devices_attribs WHERE `device_id` = ? AND `attrib_type` = ?", array($device['device_id'], $attrib_type))) {
|
||||
function get_dev_attrib($device, $attrib_type, $attrib_value='') {
|
||||
$sql = '';
|
||||
$params = array($device['device_id'], $attrib_type);
|
||||
if (!empty($attrib_value)) {
|
||||
$sql = " AND `attrib_value`=?";
|
||||
array_push($params, $attrib_value);
|
||||
}
|
||||
if ($row = dbFetchRow("SELECT attrib_value FROM devices_attribs WHERE `device_id` = ? AND `attrib_type` = ? $sql", $params)) {
|
||||
return $row['attrib_value'];
|
||||
}
|
||||
else {
|
||||
|
@@ -333,6 +333,13 @@ foreach ($ports as $port) {
|
||||
|
||||
// Update IF-MIB data
|
||||
foreach ($data_oids as $oid) {
|
||||
|
||||
if ($oid == 'ifAlias') {
|
||||
if (get_dev_attrib($device, 'ifName', $port['ifName'])) {
|
||||
$this_port['ifAlias'] = $port['ifAlias'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($port[$oid] != $this_port[$oid] && !isset($this_port[$oid])) {
|
||||
$port['update'][$oid] = array('NULL');
|
||||
log_event($oid.': '.$port[$oid].' -> NULL', $device, 'interface', $port['port_id']);
|
||||
|
Reference in New Issue
Block a user