diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index c3ae17adfe..3dca0c8ecf 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -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: diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index f16e584879..5dd4c72262 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -640,6 +640,8 @@ $config['libvirt_protocols'] = array( 'qemu+ssh', 'xen+ssh', ); +// Use different username for libvirt over SSH +$config['libvirt_username'] = null; // Mechanisms used, add or remove if not using this on any of your machines. // Hardcoded ASN descriptions $config['astext'][65332] = 'Cymru FullBogon Feed'; diff --git a/includes/discovery/libvirt-vminfo.inc.php b/includes/discovery/libvirt-vminfo.inc.php index 8825bf7b46..9c3ae45cbe 100644 --- a/includes/discovery/libvirt-vminfo.inc.php +++ b/includes/discovery/libvirt-vminfo.inc.php @@ -9,18 +9,23 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') { $ssh_ok = 0; + $userHostname = $device['hostname']; + if (!is_null($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; }