Custom ssh,telnet port with oxidized (#15255)

* Custom ssh,telnet,http port with oxidized

* Lint fixes

* copy paste minors
This commit is contained in:
Wheel
2023-09-04 03:15:51 +02:00
committed by GitHub
parent 2b10956f0b
commit a6ccb596df
5 changed files with 53 additions and 5 deletions

View File

@@ -192,9 +192,10 @@ class DeviceController extends Controller
}
// Web
$http_port = $device->attribs->firstWhere('attrib_type', 'override_device_http_port') ? ':' . $device->attribs->firstWhere('attrib_type', 'override_device_http_port')->attrib_value : '';
$device_links['web'] = [
'icon' => 'fa-globe',
'url' => 'https://' . $device->hostname,
'url' => 'https://' . $device->hostname . $http_port,
'title' => __('Web'),
'external' => true,
'onclick' => 'http_fallback(this); return false;',
@@ -212,9 +213,10 @@ class DeviceController extends Controller
}
// SSH
$ssh_port = $device->attribs->firstWhere('attrib_type', 'override_device_ssh_port') ? ':' . $device->attribs->firstWhere('attrib_type', 'override_device_ssh_port')->attrib_value : '';
$ssh_url = Config::has('gateone.server')
? Config::get('gateone.server') . '?ssh=ssh://' . (Config::get('gateone.use_librenms_user') ? Auth::user()->username . '@' : '') . $device['hostname'] . '&location=' . $device['hostname']
: 'ssh://' . $device->hostname;
: 'ssh://' . $device->hostname . $ssh_port;
$device_links['ssh'] = [
'icon' => 'fa-lock',
'url' => $ssh_url,
@@ -223,9 +225,10 @@ class DeviceController extends Controller
];
// Telnet
$telnet_port = $device->attribs->firstWhere('attrib_type', 'override_device_telnet_port') ? ':' . $device->attribs->firstWhere('attrib_type', 'override_device_telnet_port')->attrib_value : '';
$device_links['telnet'] = [
'icon' => 'fa-terminal',
'url' => 'telnet://' . $device->hostname,
'url' => 'telnet://' . $device->hostname . $telnet_port,
'title' => __('Telnet'),
'external' => true,
];

View File

@@ -103,3 +103,8 @@ The primary button is edit device by default.
| custom7 | Custom Link 7 |
| custom8 | Custom Link 8 |
!!! Custom http, ssh, telnet ports
Custom ports can be set through the device setting misc tab and will be appended to the Uri. Empty value will not append anything and automatically default to the standard.
- custom ssh port set to 2222 will result in ssh://10.0.0.0:2222
- custom telnet port set to 2323 will result in telnet://10.0.0.0:2323

View File

@@ -244,6 +244,20 @@ If you have devices which you do not wish to appear in Oxidized then
you can edit those devices in Device -> Edit -> Misc and enable
"Exclude from Oxidized?"
The use of custom ssh and telnet ports can be set through device settings misc tab, and can be passed on to oxidized with the following `vars_map`
```bash
source:
http:
map:
name: hostname
model: os
group: group
vars_map:
ssh_port: ssh_port
telnet_port: telnet_port
```
It's also possible to exclude certain device types and OS' from being
output via the API.

View File

@@ -1492,12 +1492,20 @@ function list_oxidized(Illuminate\Http\Request $request)
/** @var Device $device */
foreach ($devices as $device) {
$device['device_id'] = DeviceCache::getByHostname($device->hostname)->device_id;
$output = [
'hostname' => $device->hostname,
'os' => $device->os,
'ip' => $device->ip,
];
$custom_ssh_port = get_dev_attrib($device, 'override_device_ssh_port');
if (! empty($custom_ssh_port)) {
$output['ssh_port'] = $custom_ssh_port;
}
$custom_telnet_port = get_dev_attrib($device, 'override_device_telnet_port');
if (! empty($custom_telnet_port)) {
$output['telnet_port'] = $custom_telnet_port;
}
// Pre-populate the group with the default
if (Config::get('oxidized.group_support') === true && ! empty(Config::get('oxidized.default_group'))) {
$output['group'] = Config::get('oxidized.default_group');

View File

@@ -15,6 +15,24 @@ echo '
' . dynamic_override_config('checkbox', 'override_Oxidized_disable', $device) . '
</div>
</div>
<div class="form-group">
<label for="override_ssh" class="col-sm-4 control-label">Override default ssh port</label>
<div class="col-sm-8">
' . dynamic_override_config('text', 'override_device_ssh_port', $device) . '
</div>
</div>
<div class="form-group">
<label for="override_telnet" class="col-sm-4 control-label">Override default telnet port</label>
<div class="col-sm-8">
' . dynamic_override_config('text', 'override_device_telnet_port', $device) . '
</div>
</div>
<div class="form-group">
<label for="override_http" class="col-sm-4 control-label">Override default http port</label>
<div class="col-sm-8">
' . dynamic_override_config('text', 'override_device_http_port', $device) . '
</div>
</div>
<div class="form-group">
<label for="unixagent" class="col-sm-4 control-label">Unix agent port</label>
<div class="col-sm-8">
@@ -22,7 +40,7 @@ echo '
</div>
</div>
<div class="form-group">
<label for="unixagent" class="col-sm-4 control-label">Enable RRD Tune for all ports?</label>
<label for="rrdtool_tune" class="col-sm-4 control-label">Enable RRD Tune for all ports?</label>
<div class="col-sm-8">
' . dynamic_override_config('checkbox', 'override_rrdtool_tune', $device) . '
</div>