mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #2728 from jviersel/master
Added username support for libvirt over SSH
This commit is contained in:
@ -78,6 +78,7 @@ LibreNMS contributors:
|
||||
- D. Britz <github@wrind.de> (flatterlight)
|
||||
- Tobias Herrmann <tobias@fiveninedigital.ch> (Mightea)
|
||||
- Nicolas Guillaumin <nicolas+github@guillaumin.me> (nguillaumin)
|
||||
- Jurrian van Iersel <jurrian@vaniersel.net> (jviersel)
|
||||
|
||||
[1]: http://observium.org/ "Observium web site"
|
||||
Observium was written by:
|
||||
|
@ -488,6 +488,7 @@ This array can be used to filter out syslog messages that you don't want to be s
|
||||
```php
|
||||
$config['enable_libvirt'] = 1;
|
||||
$config['libvirt_protocols'] = array("qemu+ssh","xen+ssh");
|
||||
$config['libvirt_username'] = 'root';
|
||||
```
|
||||
Enable this to switch on support for libvirt along with `libvirt_protocols`
|
||||
to indicate how you connect to libvirt. You also need to:
|
||||
|
@ -9,18 +9,23 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') {
|
||||
|
||||
$ssh_ok = 0;
|
||||
|
||||
$userHostname = $device['hostname'];
|
||||
if (isset($config['libvirt_username'])) {
|
||||
$userHostname = $config['libvirt_username'].'@'.$userHostname;
|
||||
}
|
||||
|
||||
foreach ($config['libvirt_protocols'] as $method) {
|
||||
if (strstr($method, 'qemu')) {
|
||||
$uri = $method.'://'.$device['hostname'].'/system';
|
||||
$uri = $method.'://'.$userHostname.'/system';
|
||||
}
|
||||
else {
|
||||
$uri = $method.'://'.$device['hostname'];
|
||||
$uri = $method.'://'.$userHostname;
|
||||
}
|
||||
|
||||
if (strstr($method, 'ssh') && !$ssh_ok) {
|
||||
// Check if we are using SSH if we can log in without password - without blocking the discovery
|
||||
// Also automatically add the host key so discovery doesn't block on the yes/no question, and run echo so we don't get stuck in a remote shell ;-)
|
||||
exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" '.$device['hostname'].' echo -e', $out, $ret);
|
||||
exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" '.$userHostname.' echo -e', $out, $ret);
|
||||
if ($ret != 255) {
|
||||
$ssh_ok = 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user