Commande de cartographie

git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@13 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
Quentin Garnier 2012-09-13 15:22:15 +00:00
parent 8c277b8947
commit cae8e0ccbc
2 changed files with 432 additions and 363 deletions

View File

@ -108,6 +108,9 @@ sub print_usage () {
print "\n";
print "'listnichost':\n";
print " -e (--esx-host) Esx Host to check (required)\n";
print "\n";
print "'getmap':\n";
print " -e (--esx-host) Esx Host to check\n";
}
sub print_help () {
@ -309,6 +312,17 @@ sub listnichost_get_str {
return "listnichost|" . $OPTION{'esx-host'};
}
sub getmap_check_arg {
if (!defined($OPTION{'esx-host'})) {
$OPTION{'esx-host'} = "";
}
return 0;
}
sub getmap_get_str {
return "getmap|" . $OPTION{'esx-host'};
}
#################
#################
@ -323,7 +337,7 @@ if (!defined($OPTION{'usage'})) {
print_usage();
exit $ERRORS{'UNKNOWN'};
}
if ($OPTION{'usage'} !~ /^(healthhost|datastores|maintenancehost|statushost|cpuhost|nethost|memhost|swaphost|listhost|listdatastore|listnichost)$/) {
if ($OPTION{'usage'} !~ /^(healthhost|datastores|maintenancehost|statushost|cpuhost|nethost|memhost|swaphost|listhost|listdatastore|listnichost|getmap)$/) {
print "Usage value is unknown\n";
print_usage();
exit $ERRORS{'UNKNOWN'};

View File

@ -67,7 +67,8 @@ our %checks_descr = (
"swaphost" => {'arg' => \&swaphost_check_args, 'compute' => \&swaphost_compute_args, 'exec' => \&swaphost_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}
"listnichost" => {'arg' => \&listnichost_check_args, 'compute' => \&listnichost_compute_args, 'exec' => \&listnichost_do},
"getmap" => {'arg' => \&getmap_check_args, 'compute' => \&getmap_compute_args, 'exec' => \&getmap_do}
);
sub writeLogFile($$) {
@ -887,7 +888,6 @@ sub listhost_compute_args {
}
sub listhost_do {
my ($lhost) = @_;
my %filters = ();
my @properties = ('name');
my $result = get_entities_host('HostSystem', \%filters, \@properties);
@ -1000,6 +1000,61 @@ sub listnichost_do {
print_response($ERRORS{$MYERRORS{$status}} . "|$output_up. $output_down.\n");
}
############
# Get Map Func
############
sub getmap_check_args {
return 0;
}
sub getmap_compute_args {
my $lhost = $_[0];
return ($lhost);
}
sub getmap_do {
my ($lhost) = @_;
my %filters = ();
if (defined($lhost) and $lhost ne "") {
%filters = ('name' => $lhost);
}
my @properties = ('name', 'vm');
my $result = get_entities_host('HostSystem', \%filters, \@properties);
if (!defined($result)) {
return ;
}
my $status = 0; # OK
my $output = '';
my $output_append = "";
foreach my $entity_view (@$result) {
$output .= $output_append . "ESX Host '" . $entity_view->name . "': ";
my @vm_array = ();
if (defined $entity_view->vm) {
@vm_array = (@vm_array, @{$entity_view->vm});
}
@properties = ('name', 'summary.runtime.powerState');
my $result2 = get_views(\@vm_array, \@properties);
if (!defined($result)) {
return ;
}
my $output_append2 = '';
foreach my $vm (@$result2) {
if ($vm->{'summary.runtime.powerState'}->val eq "poweredOn") {
$output .= $output_append2 . "[" . $vm->name . "]";
$output_append2 = ', ';
}
}
$output_append = ". ";
}
print_response($ERRORS{$MYERRORS{$status}} . "|$output\n");
}
############
sub catch_zap_term {
@ -1273,16 +1328,16 @@ while (1) {
my ($name, @args) = split /\|/, $line;
if (!defined($checks_descr{$name})) {
$rh->send("3|Unknown method name '$name'\n");
delete $sockets{fileno($rh)};
$read_select->remove($rh);
close $rh;
delete $sockets{fileno($rh)};
next;
}
if ($checks_descr{$name}->{'arg'}(@args)) {
$rh->send("3|Params error '$name'\n");
delete $sockets{fileno($rh)};
$read_select->remove($rh);
close $rh;
delete $sockets{fileno($rh)};
next;
}