mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-09-25 10:48:40 +02:00
Fix #3864
git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@80 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
2c6bb7bdd0
commit
8b4feb1828
@ -31,6 +31,10 @@ my %OPTION = (
|
|||||||
free => undef,
|
free => undef,
|
||||||
skip_errors => undef,
|
skip_errors => undef,
|
||||||
filter => undef,
|
filter => undef,
|
||||||
|
|
||||||
|
# For Autodisco
|
||||||
|
xml => undef,
|
||||||
|
show_attributes => undef,
|
||||||
);
|
);
|
||||||
|
|
||||||
Getopt::Long::Configure('bundling');
|
Getopt::Long::Configure('bundling');
|
||||||
@ -66,6 +70,9 @@ GetOptions(
|
|||||||
|
|
||||||
"warning2=f" => \$OPTION{warning2},
|
"warning2=f" => \$OPTION{warning2},
|
||||||
"critical2=f" => \$OPTION{critical2},
|
"critical2=f" => \$OPTION{critical2},
|
||||||
|
|
||||||
|
"xml" => \$OPTION{xml},
|
||||||
|
"show-attributes" => \$OPTION{show_attributes},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (defined($OPTION{version})) {
|
if (defined($OPTION{version})) {
|
||||||
@ -202,10 +209,13 @@ sub print_usage () {
|
|||||||
print " None\n";
|
print " None\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
print "'listdatastore':\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 "\n";
|
||||||
print "'listnichost':\n";
|
print "'listnichost':\n";
|
||||||
print " -e (--esx-host) Esx Host to check (required)\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 "\n";
|
||||||
print "'getmap':\n";
|
print "'getmap':\n";
|
||||||
print " -e (--esx-host) Esx Host to check\n";
|
print " -e (--esx-host) Esx Host to check\n";
|
||||||
@ -704,12 +714,22 @@ sub listhost_get_str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub listdatastore_check_arg {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub listdatastore_get_str {
|
sub listdatastore_get_str {
|
||||||
return join($separatorin,
|
return join($separatorin,
|
||||||
('listdatastore', $OPTION{vsphere}));
|
('listdatastore', $OPTION{vsphere}, $OPTION{xml}, $OPTION{show_attributes}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub listnichost_check_arg {
|
sub listnichost_check_arg {
|
||||||
@ -718,12 +738,22 @@ sub listnichost_check_arg {
|
|||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{UNKNOWN};
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub listnichost_get_str {
|
sub listnichost_get_str {
|
||||||
return join($separatorin,
|
return join($separatorin,
|
||||||
('listnichost', $OPTION{vsphere}, $OPTION{'esx-host'}));
|
('listnichost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{xml}, $OPTION{show_attributes}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getmap_check_arg {
|
sub getmap_check_arg {
|
||||||
|
@ -28,11 +28,18 @@ sub checkArgs {
|
|||||||
|
|
||||||
sub initArgs {
|
sub initArgs {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
$self->{xml} = (defined($_[0]) && $_[0] == 1) ? 1 : 0;
|
||||||
|
$self->{show_attributes} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
if ($self->{show_attributes} == 1) {
|
||||||
|
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status(0) . "|<data><element>name</element></data>\n");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
my %filters = ();
|
my %filters = ();
|
||||||
my @properties = ('summary');
|
my @properties = ('summary');
|
||||||
|
|
||||||
@ -44,14 +51,21 @@ sub run {
|
|||||||
my $status = 0; # OK
|
my $status = 0; # OK
|
||||||
my $output = 'Datastore List: ';
|
my $output = 'Datastore List: ';
|
||||||
my $output_append = "";
|
my $output_append = "";
|
||||||
|
my $xml_output = '<data>';
|
||||||
foreach my $datastore (@$result) {
|
foreach my $datastore (@$result) {
|
||||||
if ($datastore->summary->accessible) {
|
if ($datastore->summary->accessible) {
|
||||||
$output .= $output_append . "'" . $datastore->summary->name . "'";
|
$output .= $output_append . "'" . $datastore->summary->name . "'";
|
||||||
$output_append = ', ';
|
$output_append = ', ';
|
||||||
}
|
}
|
||||||
|
$xml_output .= '<element name="' . $datastore->summary->name . '" />';
|
||||||
}
|
}
|
||||||
|
$xml_output .= '</data>';
|
||||||
|
|
||||||
|
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");
|
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -35,12 +35,19 @@ sub checkArgs {
|
|||||||
sub initArgs {
|
sub initArgs {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->{lhost} = $_[0];
|
$self->{lhost} = $_[0];
|
||||||
|
$self->{xml} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||||
|
$self->{show_attributes} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my %nic_in_vswitch = ();
|
my %nic_in_vswitch = ();
|
||||||
|
|
||||||
|
if ($self->{show_attributes} == 1) {
|
||||||
|
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status(0) . "|<data><element>name</element></data>\n");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
my %filters = ('name' => $self->{lhost});
|
my %filters = ('name' => $self->{lhost});
|
||||||
my @properties = ('config.network.pnic', 'config.network.vswitch');
|
my @properties = ('config.network.pnic', 'config.network.vswitch');
|
||||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties);
|
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_up_append = "";
|
||||||
my $output_down_append = "";
|
my $output_down_append = "";
|
||||||
my $output_down_no_vswitch_append = "";
|
my $output_down_no_vswitch_append = "";
|
||||||
|
my $xml_output = '<data>';
|
||||||
foreach (@{$$result[0]->{'config.network.pnic'}}) {
|
foreach (@{$$result[0]->{'config.network.pnic'}}) {
|
||||||
if (defined($_->linkSpeed)) {
|
if (defined($_->linkSpeed)) {
|
||||||
$output_up .= $output_up_append . "'" . $_->device . "'";
|
$output_up .= $output_up_append . "'" . $_->device . "'";
|
||||||
$output_up_append = ', ';
|
$output_up_append = ', ';
|
||||||
|
$xml_output .= '<element name="' . $_->device . '" />';
|
||||||
} else {
|
} else {
|
||||||
if (defined($nic_in_vswitch{$_->key})) {
|
if (defined($nic_in_vswitch{$_->key})) {
|
||||||
$output_down .= $output_down_append . "'" . $_->device . "'";
|
$output_down .= $output_down_append . "'" . $_->device . "'";
|
||||||
$output_down_append = ', ';
|
$output_down_append = ', ';
|
||||||
|
$xml_output .= '<element name="' . $_->device . '" />';
|
||||||
} else {
|
} else {
|
||||||
$output_down_no_vswitch .= $output_down_no_vswitch_append . "'" . $_->device . "'";
|
$output_down_no_vswitch .= $output_down_no_vswitch_append . "'" . $_->device . "'";
|
||||||
$output_down_no_vswitch_append = ', ';
|
$output_down_no_vswitch_append = ', ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$xml_output .= '</data>';
|
||||||
|
|
||||||
|
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");
|
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output_up. $output_down. $output_down_no_vswitch.\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user