From 93e76a2b5a878bf1d883a30dfaeeb4c689c9d702 Mon Sep 17 00:00:00 2001 From: Jurrian van Iersel Date: Sat, 9 Jan 2016 14:20:57 +0100 Subject: [PATCH 1/4] Added username support for libvirt over SSH --- doc/Support/Configuration.md | 1 + includes/defaults.inc.php | 2 ++ includes/discovery/libvirt-vminfo.inc.php | 11 ++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) 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; } From 31243b2acf8fca79cbf2594e5d947e36aee0f46e Mon Sep 17 00:00:00 2001 From: Jurrian van Iersel Date: Sat, 9 Jan 2016 14:38:37 +0100 Subject: [PATCH 2/4] I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md. --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 0945ba8ec5..83929477a9 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -78,6 +78,7 @@ LibreNMS contributors: - D. Britz (flatterlight) - Tobias Herrmann (Mightea) - Nicolas Guillaumin (nguillaumin) +- Jurrian van Iersel (jviersel) [1]: http://observium.org/ "Observium web site" Observium was written by: From d0f0e055fb19c0661522367d36a94098ac9e56eb Mon Sep 17 00:00:00 2001 From: Jurrian van Iersel Date: Sun, 17 Jan 2016 15:42:03 +0100 Subject: [PATCH 3/4] Update defaults.inc.php --- includes/defaults.inc.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 5dd4c72262..f16e584879 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -640,8 +640,6 @@ $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'; From a1c5a9dbeb50762c8b3283c167f146279e5cba27 Mon Sep 17 00:00:00 2001 From: Jurrian van Iersel Date: Sun, 17 Jan 2016 15:42:31 +0100 Subject: [PATCH 4/4] Update libvirt-vminfo.inc.php --- includes/discovery/libvirt-vminfo.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/libvirt-vminfo.inc.php b/includes/discovery/libvirt-vminfo.inc.php index 9c3ae45cbe..aced6467c3 100644 --- a/includes/discovery/libvirt-vminfo.inc.php +++ b/includes/discovery/libvirt-vminfo.inc.php @@ -10,7 +10,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') { $ssh_ok = 0; $userHostname = $device['hostname']; - if (!is_null($config['libvirt_username'])) { + if (isset($config['libvirt_username'])) { $userHostname = $config['libvirt_username'].'@'.$userHostname; }