From a349a883d83e5716721fbff9e2e270aa847fce16 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Wed, 11 Sep 2013 15:55:36 +0000 Subject: [PATCH] Optimize nic info from 'listnichost' command git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@76 a5eaa968-4c79-4d68-970d-af6011b5b055 --- connectors/vmware/centreon_esx_client.pl | 8 +++++++- connectors/vmware/lib/cmdlistnichost.pm | 23 +++++++++++++++++++---- connectors/vmware/lib/cmdnethost.pm | 5 +++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/connectors/vmware/centreon_esx_client.pl b/connectors/vmware/centreon_esx_client.pl index 02278188c..7dfa91391 100644 --- a/connectors/vmware/centreon_esx_client.pl +++ b/connectors/vmware/centreon_esx_client.pl @@ -130,6 +130,7 @@ sub print_usage () { print " --nic Physical nic name to check (required)\n"; print " -w (--warning) Warning Threshold in percent (default 80)\n"; print " -c (--critical) Critical Threshold in percent (default 90)\n"; + print " --filter Use regexp for --nic option (can check multiple nics at once)\n"; print "\n"; print "'memhost':\n"; print " -e (--esx-host) Esx Host to check (required)\n"; @@ -473,12 +474,17 @@ sub nethost_check_arg { if (!defined($OPTION{critical})) { $OPTION{critical} = 90; } + if (defined($OPTION{filter})) { + $OPTION{filter} = 1; + } else { + $OPTION{filter} = 0; + } return 0; } sub nethost_get_str { return join($separatorin, - ('nethost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{nic}, $OPTION{warning}, $OPTION{critical})); + ('nethost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{nic}, $OPTION{filter}, $OPTION{warning}, $OPTION{critical})); } sub countvmhost_check_arg { diff --git a/connectors/vmware/lib/cmdlistnichost.pm b/connectors/vmware/lib/cmdlistnichost.pm index ffc452ae9..faccda8d9 100644 --- a/connectors/vmware/lib/cmdlistnichost.pm +++ b/connectors/vmware/lib/cmdlistnichost.pm @@ -39,30 +39,45 @@ sub initArgs { sub run { my $self = shift; + my %nic_in_vswitch = (); my %filters = ('name' => $self->{lhost}); - my @properties = ('config.network.pnic'); + my @properties = ('config.network.pnic', 'config.network.vswitch'); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties); if (!defined($result)) { return ; } + + # Get Name from vswitch + foreach (@{$$result[0]->{'config.network.vswitch'}}) { + foreach my $keynic (@{$_->pnic}) { + $nic_in_vswitch{$keynic} = 1; + } + } my $status = 0; # OK my $output_up = 'Nic Up List: '; my $output_down = 'Nic Down List: '; + my $output_down_no_vswitch = 'Nic Down List (not in vswitch): '; my $output_up_append = ""; my $output_down_append = ""; + my $output_down_no_vswitch_append = ""; foreach (@{$$result[0]->{'config.network.pnic'}}) { if (defined($_->linkSpeed)) { $output_up .= $output_up_append . "'" . $_->device . "'"; $output_up_append = ', '; } else { - $output_down .= $output_down_append . "'" . $_->device . "'"; - $output_down_append = ', '; + if (defined($nic_in_vswitch{$_->key})) { + $output_down .= $output_down_append . "'" . $_->device . "'"; + $output_down_append = ', '; + } else { + $output_down_no_vswitch .= $output_down_no_vswitch_append . "'" . $_->device . "'"; + $output_down_no_vswitch_append = ', '; + } } } - $self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output_up. $output_down.\n"); + $self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output_up. $output_down. $output_down_no_vswitch.\n"); } 1; diff --git a/connectors/vmware/lib/cmdnethost.pm b/connectors/vmware/lib/cmdnethost.pm index 7c1a80af1..619113d18 100644 --- a/connectors/vmware/lib/cmdnethost.pm +++ b/connectors/vmware/lib/cmdnethost.pm @@ -52,8 +52,9 @@ sub initArgs { my $self = shift; $self->{lhost} = $_[0]; $self->{pnic} = $_[1]; - $self->{warn} = (defined($_[2]) ? $_[2] : 80); - $self->{crit} = (defined($_[3]) ? $_[3] : 90); + $self->{filter} = (defined($_[2]) && $_[2] == 1) ? 1 : 0; + $self->{warn} = (defined($_[3]) ? $_[3] : 80); + $self->{crit} = (defined($_[4]) ? $_[4] : 90); } sub run {