mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
WebUI: Oxidized Device List: Link to config and refreshDevice Btn (#9129)
* WebUI: Direct link to oxidized config from list, oxidized refresh device capability * WebUI: Direct link to oxidized config from list, oxidized refresh device capability * Move oxidized_node_update in functions.php to avoid code duplication * Update refresh-oxidized-node.inc.php * Update functions.php
This commit is contained in:
38
html/includes/forms/refresh-oxidized-node.inc.php
Normal file
38
html/includes/forms/refresh-oxidized-node.inc.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2018 PipoCanaja <pipocanaja@gmail.com>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
header('Content-type: application/json');
|
||||
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Authentication\Auth;
|
||||
|
||||
$device_hostname = clean($_POST['device_hostname']);
|
||||
if (Auth::user()->hasGlobalAdmin() && isset($device_hostname)) {
|
||||
if (oxidized_node_update($device_hostname, "LibreNMS GUI refresh", $_SESSION['username'])) {
|
||||
$status = 'ok';
|
||||
$message = 'Queued refresh in oxidized for device ' . $device_hostname;
|
||||
} else {
|
||||
$status = 'error';
|
||||
$message = 'ERROR: Could not queue refresh of oxidized device' . $device_hostname;
|
||||
};
|
||||
} else {
|
||||
$status = 'error';
|
||||
$message = 'ERROR: Could not queue refresh oxidized device';
|
||||
}
|
||||
|
||||
$output = array(
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
);
|
||||
|
||||
header('Content-type: application/json');
|
||||
echo _json_encode($output);
|
||||
@@ -1530,6 +1530,15 @@ function get_oxidized_nodes_list()
|
||||
<td>
|
||||
" . $object['group'] . "
|
||||
</td>
|
||||
<td>
|
||||
<button class='btn btn-default btn-sm' name='btn-refresh-node-devId" . $device['device_id'] . "' id='btn-refresh-nod
|
||||
e-devId" . $device['device_id'] . "' onclick='refresh_oxidized_node(\"" . $device['hostname'] . "\")'>
|
||||
<i class='fa fa-refresh'></i>
|
||||
</button>
|
||||
<a href='/device/device=".$device['device_id']."/tab=showconfig/'>
|
||||
<i class='fa fa-align-justify fa-lg icon-theme'></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ $pagetitle[] = 'Oxidized';
|
||||
<th data-column-id="last_update">Last Update</th>
|
||||
<th data-column-id="model">Model</th>
|
||||
<th data-column-id="group">Group</th>
|
||||
<th data-column-id="actions"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -62,6 +63,28 @@ $pagetitle[] = 'Oxidized';
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
function refresh_oxidized_node(device_hostname){
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax_form.php',
|
||||
data: {
|
||||
type: "refresh-oxidized-node",
|
||||
device_hostname: device_hostname
|
||||
},
|
||||
success: function (data) {
|
||||
if(data['status'] == 'ok') {
|
||||
toastr.success(data['message']);
|
||||
} else {
|
||||
toastr.error(data['message']);
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
toastr.error('An error occured while refreshing an oxidized node (hostname: ' + device_hostname + ')');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$("[name='btn-search']").on('click', function (event) {
|
||||
event.preventDefault();
|
||||
var $this = $(this);
|
||||
|
||||
@@ -2628,3 +2628,26 @@ function is_disk_valid($disk, $device)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Queues a hostname to be refreshed by Oxidized
|
||||
* Settings: oxidized.url
|
||||
*
|
||||
* @param string $hostname
|
||||
* @param string $msg
|
||||
* @param string $username
|
||||
* @return bool
|
||||
*/
|
||||
function oxidized_node_update($hostname, $msg, $username = 'not_provided')
|
||||
{
|
||||
// Work around https://github.com/rack/rack/issues/337
|
||||
$msg = str_replace("%", "", $msg);
|
||||
$postdata = ["user" => $username, "msg" => $msg];
|
||||
$oxidized_url = Config::get('oxidized.url');
|
||||
if (!empty($oxidized_url)) {
|
||||
Requests::put("$oxidized_url/node/next/$hostname", [], json_encode($postdata), ['proxy' => get_proxy()]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}//end oxidized_node_update()
|
||||
|
||||
@@ -6,17 +6,6 @@ require __DIR__ . '/../includes/init.php';
|
||||
|
||||
use LibreNMS\Config;
|
||||
|
||||
function oxidized_node_update($hostname, $msg, $username = 'not_provided')
|
||||
{
|
||||
// Work around https://github.com/rack/rack/issues/337
|
||||
$msg = str_replace("%", "", $msg);
|
||||
$postdata = ["user" => $username, "msg" => $msg];
|
||||
$oxidized_url = Config::get('oxidized.url');
|
||||
if (!empty($oxidized_url)) {
|
||||
Requests::put("$oxidized_url/node/next/$hostname", [], json_encode($postdata), ['proxy' => get_proxy()]);
|
||||
}
|
||||
}//end oxidized_node_update()
|
||||
|
||||
$hostname = $argv[1];
|
||||
$os = $argv[2];
|
||||
$msg = $argv[3];
|
||||
|
||||
Reference in New Issue
Block a user