git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@80 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
Quentin Garnier 2013-09-12 12:29:25 +00:00
parent 2c6bb7bdd0
commit 8b4feb1828
3 changed files with 64 additions and 5 deletions

View File

@ -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 {

View File

@ -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) . "|<data><element>name</element></data>\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 = '<data>';
foreach my $datastore (@$result) {
if ($datastore->summary->accessible) {
$output .= $output_append . "'" . $datastore->summary->name . "'";
$output_append = ', ';
}
$xml_output .= '<element name="' . $datastore->summary->name . '" />';
}
$xml_output .= '</data>';
$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;

View File

@ -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) . "|<data><element>name</element></data>\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 = '<data>';
foreach (@{$$result[0]->{'config.network.pnic'}}) {
if (defined($_->linkSpeed)) {
$output_up .= $output_up_append . "'" . $_->device . "'";
$output_up_append = ', ';
$xml_output .= '<element name="' . $_->device . '" />';
} else {
if (defined($nic_in_vswitch{$_->key})) {
$output_down .= $output_down_append . "'" . $_->device . "'";
$output_down_append = ', ';
$xml_output .= '<element name="' . $_->device . '" />';
} else {
$output_down_no_vswitch .= $output_down_no_vswitch_append . "'" . $_->device . "'";
$output_down_no_vswitch_append = ', ';
}
}
}
$xml_output .= '</data>';
$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;