From 8b4feb1828405e53fc3dea02b4d0a67865f8e232 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Thu, 12 Sep 2013 12:29:25 +0000 Subject: [PATCH] Fix #3864 git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@80 a5eaa968-4c79-4d68-970d-af6011b5b055 --- connectors/vmware/centreon_esx_client.pl | 36 +++++++++++++++++++++-- connectors/vmware/lib/cmdlistdatastore.pm | 16 +++++++++- connectors/vmware/lib/cmdlistnichost.pm | 17 ++++++++++- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/connectors/vmware/centreon_esx_client.pl b/connectors/vmware/centreon_esx_client.pl index 62ad49281..9eadbe8fa 100644 --- a/connectors/vmware/centreon_esx_client.pl +++ b/connectors/vmware/centreon_esx_client.pl @@ -31,6 +31,10 @@ my %OPTION = ( free => undef, skip_errors => undef, filter => undef, + + # For Autodisco + xml => undef, + show_attributes => undef, ); Getopt::Long::Configure('bundling'); @@ -66,6 +70,9 @@ GetOptions( "warning2=f" => \$OPTION{warning2}, "critical2=f" => \$OPTION{critical2}, + + "xml" => \$OPTION{xml}, + "show-attributes" => \$OPTION{show_attributes}, ); if (defined($OPTION{version})) { @@ -202,10 +209,13 @@ sub print_usage () { print " None\n"; print "\n"; print "'listdatastore':\n"; - print " None\n"; + print " --xml centreon-autodiscovery xml format\n"; + print " --show-attributes centreon-autodiscovery attributes xml display\n"; print "\n"; print "'listnichost':\n"; print " -e (--esx-host) Esx Host to check (required)\n"; + print " --xml centreon-autodiscovery xml format\n"; + print " --show-attributes centreon-autodiscovery attributes xml display\n"; print "\n"; print "'getmap':\n"; print " -e (--esx-host) Esx Host to check\n"; @@ -704,12 +714,22 @@ sub listhost_get_str { } sub listdatastore_check_arg { + if (!defined($OPTION{xml})) { + $OPTION{xml} = 0; + } else { + $OPTION{xml} = 1; + } + if (!defined($OPTION{show_attributes})) { + $OPTION{show_attributes} = 0; + } else { + $OPTION{show_attributes} = 1; + } return 0; } sub listdatastore_get_str { return join($separatorin, - ('listdatastore', $OPTION{vsphere})); + ('listdatastore', $OPTION{vsphere}, $OPTION{xml}, $OPTION{show_attributes})); } sub listnichost_check_arg { @@ -718,12 +738,22 @@ sub listnichost_check_arg { print_usage(); exit $ERRORS{UNKNOWN}; } + if (!defined($OPTION{xml})) { + $OPTION{xml} = 0; + } else { + $OPTION{xml} = 1; + } + if (!defined($OPTION{show_attributes})) { + $OPTION{show_attributes} = 0; + } else { + $OPTION{show_attributes} = 1; + } return 0; } sub listnichost_get_str { return join($separatorin, - ('listnichost', $OPTION{vsphere}, $OPTION{'esx-host'})); + ('listnichost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{xml}, $OPTION{show_attributes})); } sub getmap_check_arg { diff --git a/connectors/vmware/lib/cmdlistdatastore.pm b/connectors/vmware/lib/cmdlistdatastore.pm index b8b0e901b..6a470d5b6 100644 --- a/connectors/vmware/lib/cmdlistdatastore.pm +++ b/connectors/vmware/lib/cmdlistdatastore.pm @@ -28,11 +28,18 @@ sub checkArgs { sub initArgs { my $self = shift; + $self->{xml} = (defined($_[0]) && $_[0] == 1) ? 1 : 0; + $self->{show_attributes} = (defined($_[1]) && $_[1] == 1) ? 1 : 0; } sub run { my $self = shift; + if ($self->{show_attributes} == 1) { + $self->{obj_esxd}->print_response(centreon::esxd::common::get_status(0) . "|name\n"); + return ; + } + my %filters = (); my @properties = ('summary'); @@ -44,14 +51,21 @@ sub run { my $status = 0; # OK my $output = 'Datastore List: '; my $output_append = ""; + my $xml_output = ''; foreach my $datastore (@$result) { if ($datastore->summary->accessible) { $output .= $output_append . "'" . $datastore->summary->name . "'"; $output_append = ', '; } + $xml_output .= ''; } + $xml_output .= ''; - $self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n"); + if ($self->{xml} == 1) { + $self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$xml_output\n"); + } else { + $self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n"); + } } 1; diff --git a/connectors/vmware/lib/cmdlistnichost.pm b/connectors/vmware/lib/cmdlistnichost.pm index faccda8d9..7c0e94192 100644 --- a/connectors/vmware/lib/cmdlistnichost.pm +++ b/connectors/vmware/lib/cmdlistnichost.pm @@ -35,12 +35,19 @@ sub checkArgs { sub initArgs { my $self = shift; $self->{lhost} = $_[0]; + $self->{xml} = (defined($_[1]) && $_[1] == 1) ? 1 : 0; + $self->{show_attributes} = (defined($_[2]) && $_[2] == 1) ? 1 : 0; } sub run { my $self = shift; my %nic_in_vswitch = (); + if ($self->{show_attributes} == 1) { + $self->{obj_esxd}->print_response(centreon::esxd::common::get_status(0) . "|name\n"); + return ; + } + my %filters = ('name' => $self->{lhost}); my @properties = ('config.network.pnic', 'config.network.vswitch'); my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties); @@ -62,22 +69,30 @@ sub run { my $output_up_append = ""; my $output_down_append = ""; my $output_down_no_vswitch_append = ""; + my $xml_output = ''; foreach (@{$$result[0]->{'config.network.pnic'}}) { if (defined($_->linkSpeed)) { $output_up .= $output_up_append . "'" . $_->device . "'"; $output_up_append = ', '; + $xml_output .= ''; } else { if (defined($nic_in_vswitch{$_->key})) { $output_down .= $output_down_append . "'" . $_->device . "'"; $output_down_append = ', '; + $xml_output .= ''; } else { $output_down_no_vswitch .= $output_down_no_vswitch_append . "'" . $_->device . "'"; $output_down_no_vswitch_append = ', '; } } } + $xml_output .= ''; - $self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output_up. $output_down. $output_down_no_vswitch.\n"); + if ($self->{xml} == 1) { + $self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$xml_output\n"); + } else { + $self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output_up. $output_down. $output_down_no_vswitch.\n"); + } } 1;