From 4cbffb12354d880131144fcb5b4431bf7a992701 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Mon, 8 Oct 2012 12:51:06 +0000 Subject: [PATCH] =?UTF-8?q?Evolution=20#4012=20[vm]=20V=C3=A9rification=20?= =?UTF-8?q?du=20swap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@41 a5eaa968-4c79-4d68-970d-af6011b5b055 --- connectors/vmware/centreon_esx_client.pl | 26 ++++++++- connectors/vmware/centreon_esxd | 2 + connectors/vmware/lib/command-swaphost.pm | 3 +- connectors/vmware/lib/command-swapvm.pm | 67 +++++++++++++++++++++++ 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 connectors/vmware/lib/command-swapvm.pm diff --git a/connectors/vmware/centreon_esx_client.pl b/connectors/vmware/centreon_esx_client.pl index 406548d3b..91b24083a 100644 --- a/connectors/vmware/centreon_esx_client.pl +++ b/connectors/vmware/centreon_esx_client.pl @@ -148,6 +148,11 @@ sub print_usage () { print " -w (--warning) Warning Threshold in percent (default 80)\n"; print " -c (--critical) Critical Threshold in percent (default 90)\n"; print "\n"; + print "'swapvm':\n"; + print " --vm VM to check (required)\n"; + print " -w (--warning) Warning Threshold in MB/s (default 0.8)\n"; + print " -c (--critical) Critical Threshold in MB/s (default 1)\n"; + print "\n"; print "'listhost':\n"; print " None\n"; print "\n"; @@ -487,6 +492,25 @@ sub memvm_get_str { return "memvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'}; } +sub swapvm_check_arg { + if (!defined($OPTION{'vm'})) { + print "Option --vm is required\n"; + print_usage(); + exit $ERRORS{'UNKNOWN'}; + } + if (!defined($OPTION{'warning'})) { + $OPTION{'warning'} = 0.8; + } + if (!defined($OPTION{'critical'})) { + $OPTION{'critical'} = 1; + } + return 0; +} + +sub swapvm_get_str { + return "swapvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'}; +} + sub listhost_check_arg { return 0; @@ -556,7 +580,7 @@ if (!defined($OPTION{'usage'})) { print_usage(); exit $ERRORS{'UNKNOWN'}; } -if ($OPTION{'usage'} !~ /^(healthhost|datastore-usage|datastore-io|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|listhost|listdatastore|listnichost|getmap|stats)$/) { +if ($OPTION{'usage'} !~ /^(healthhost|datastore-usage|datastore-io|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|swapvm|listhost|listdatastore|listnichost|getmap|stats)$/) { print "Usage value is unknown\n"; print_usage(); exit $ERRORS{'UNKNOWN'}; diff --git a/connectors/vmware/centreon_esxd b/connectors/vmware/centreon_esxd index a35a78432..5c6bdd2aa 100644 --- a/connectors/vmware/centreon_esxd +++ b/connectors/vmware/centreon_esxd @@ -58,6 +58,7 @@ require $libpath . '/command-nethost.pm'; require $libpath . '/command-snapshotvm.pm'; require $libpath . '/command-statushost.pm'; require $libpath . '/command-swaphost.pm'; +require $libpath . '/command-swapvm.pm'; require $libpath . '/command-toolsvm.pm'; @@ -113,6 +114,7 @@ our %checks_descr = ( "snapshotvm" => {'arg' => \&snapshotvm_check_args, 'compute' => \&snapshotvm_compute_args, 'exec' => \&snapshotvm_do}, "datastoresvm" => {'arg' => \&datastoresvm_check_args, 'compute' => \&datastoresvm_compute_args, 'exec' => \&datastoresvm_do}, "memvm" => {'arg' => \&memvm_check_args, 'compute' => \&memvm_compute_args, 'exec' => \&memvm_do}, + "swapvm" => {'arg' => \&swapvm_check_args, 'compute' => \&swapvm_compute_args, 'exec' => \&swapvm_do}, "listhost" => {'arg' => \&listhost_check_args, 'compute' => \&listhost_compute_args, 'exec' => \&listhost_do}, "listdatastore" => {'arg' => \&listdatastore_check_args, 'compute' => \&listdatastore_compute_args, 'exec' => \&listdatastore_do}, "listnichost" => {'arg' => \&listnichost_check_args, 'compute' => \&listnichost_compute_args, 'exec' => \&listnichost_do}, diff --git a/connectors/vmware/lib/command-swaphost.pm b/connectors/vmware/lib/command-swaphost.pm index 31bfc5bb0..089e193d6 100644 --- a/connectors/vmware/lib/command-swaphost.pm +++ b/connectors/vmware/lib/command-swaphost.pm @@ -35,8 +35,7 @@ sub swaphost_do { } my %filters = ('name' => $lhost); - #my @properties = ('summary'); - my @properties = (); + my @properties = ('name'); my $result = get_entities_host('HostSystem', \%filters, \@properties); if (!defined($result)) { return ; diff --git a/connectors/vmware/lib/command-swapvm.pm b/connectors/vmware/lib/command-swapvm.pm new file mode 100644 index 000000000..7a4d24a43 --- /dev/null +++ b/connectors/vmware/lib/command-swapvm.pm @@ -0,0 +1,67 @@ +sub swapvm_check_args { + my ($vm, $warn, $crit) = @_; + if (!defined($vm) || $vm eq "") { + writeLogFile(LOG_ESXD_ERROR, "ARGS error: need vm name\n"); + return 1; + } + if (defined($warn) && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) { + writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be a positive number\n"); + return 1; + } + if (defined($crit) && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) { + writeLogFile(LOG_ESXD_ERROR, "ARGS error: crit threshold must be a positive number\n"); + return 1; + } + if (defined($warn) && defined($crit) && $warn > $crit) { + writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be lower than crit threshold\n"); + return 1; + } + return 0; +} + +sub swapvm_compute_args { + my $lvm = $_[0]; + my $warn = (defined($_[1]) ? $_[1] : 0.8); + my $crit = (defined($_[2]) ? $_[2] : 1); + return ($lvm, $warn, $crit); +} + +sub swapvm_do { + my ($lvm, $warn, $crit) = @_; + if (!($perfcounter_speriod > 0)) { + my $status |= $MYERRORS_MASK{'UNKNOWN'}; + print_response($ERRORS{$MYERRORS{$status}} . "|Can't retrieve perf counters.\n"); + return ; + } + + my %filters = ('name' => $lvm); + my @properties = ('name'); + my $result = get_entities_host('VirtualMachine', \%filters, \@properties); + if (!defined($result)) { + return ; + } + + my $values = generic_performance_values_historic($$result[0], + [{'label' => 'mem.swapinRate.average', 'instances' => ['']}, + {'label' => 'mem.swapoutRate.average', 'instances' => ['']}], + $perfcounter_speriod); + + my $swap_in = simplify_number(convert_number($values->{$perfcounter_cache{'mem.swapinRate.average'}->{'key'} . ":"}[0])); + my $swap_out = simplify_number(convert_number($values->{$perfcounter_cache{'mem.swapoutRate.average'}->{'key'} . ":"}[0])); + my $status = 0; # OK + my $output = ''; + + if (($swap_in / 1024) >= $warn || ($swap_out / 1024) >= $warn) { + $status |= $MYERRORS_MASK{'WARNING'}; + } + if (($swap_in / 1024) >= $crit || ($swap_out / 1024) >= $crit) { + $status |= $MYERRORS_MASK{'CRITICAL'}; + } + + $output = "Swap In : " . simplify_number($swap_in / 1024 * 8) . " Mb/s , Swap Out : " . simplify_number($swap_out / 1024 * 8) . " Mb/s "; + $output .= "|swap_in=" . ($swap_in * 1024 * 8) . "b/s swap_out=" . (($swap_out * 1024 * 8)) . "b/s"; + + print_response($ERRORS{$MYERRORS{$status}} . "|$output\n"); +} + +1;