diff --git a/Changes b/Changes index 48cdfc7..e350b8c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ N.N.N - DD-MMM-2015 ==================== +- Added the option 'cmd' in 'libvirt.pm' in order to be able to execute a + custom command like 'virsh -r -c qemu:///session'. - Fixed in 'libvirt.pm' limiting to 100 all CPU values greater than 100. diff --git a/lib/libvirt.pm b/lib/libvirt.pm index 7ceb682..f50f447 100644 --- a/lib/libvirt.pm +++ b/lib/libvirt.pm @@ -125,6 +125,12 @@ sub libvirt_init { } } + # check for missing options + if(!$libvirt->{cmd}) { + logger("$myself: WARNING: the 'cmd' option doesn't exist. Please consider upgrading your configuration file."); + $libvirt->{cmd} = "virsh"; + } + $config->{libvirt_hist} = (); push(@{$config->{func_update}}, $package); logger("$myself: Ok") if $debug; @@ -161,13 +167,13 @@ sub libvirt_update { } # check first if that 'vm' is running - if($vm && open(IN, "virsh domstate $vm |")) { + if($vm && open(IN, "$libvirt->{cmd} domstate $vm |")) { $state = trim(); close(IN); } if($state eq "running") { - if(open(IN, "virsh cpu-stats $vm --total |")) { + if(open(IN, "$libvirt->{cmd} cpu-stats $vm --total |")) { my $c = 0; while() { if(/^\s+cpu_time\s+(\d+\.\d+) seconds$/) { @@ -182,7 +188,7 @@ sub libvirt_update { $cpu = $cpu > 100 ? 100 : $cpu; $config->{libvirt_hist}->{$str} = $c; } - if(open(IN, "virsh dommemstat $vm |")) { + if(open(IN, "$libvirt->{cmd} dommemstat $vm |")) { while() { if(/^rss\s+(\d+)$/) { $mem = $1 * 1024; @@ -190,7 +196,7 @@ sub libvirt_update { } close(IN); } - if(open(IN, "virsh domblkstat $vm $vda |")) { + if(open(IN, "$libvirt->{cmd} domblkstat $vm $vda |")) { my $r = 0; my $w = 0; while() { @@ -210,7 +216,7 @@ sub libvirt_update { $dsk /= 60; $config->{libvirt_hist}->{$str} = $t; } - if(open(IN, "virsh domiflist $vm |")) { + if(open(IN, "$libvirt->{cmd} domiflist $vm |")) { while() { if(/^(\S+)\s+.*?\s+$vmac$/) { $vnet = $1; @@ -218,7 +224,7 @@ sub libvirt_update { } close(IN); } - if(open(IN, "virsh domifstat $vm $vnet |")) { + if(open(IN, "$libvirt->{cmd} domifstat $vm $vnet |")) { my $r = 0; my $w = 0; while() { diff --git a/monitorix.conf b/monitorix.conf index a9f5dd2..f0b3374 100644 --- a/monitorix.conf +++ b/monitorix.conf @@ -287,6 +287,7 @@ secure_log_date_format = %b %e # LIBVIRT graph # ----------------------------------------------------------------------------- + cmd = virsh 0 = centos6, winxp