indent + manage no vm running
This commit is contained in:
parent
82041f9120
commit
12e545e235
|
@ -106,6 +106,11 @@ sub run {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scalar(@ds_array) == 0) {
|
||||||
|
centreon::vmware::common::set_response(code => 200, short_message => "no virtual machines running or no datastore found");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
@properties = ('info');
|
@properties = ('info');
|
||||||
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@ds_array, \@properties);
|
my $result2 = centreon::vmware::common::get_views($self->{connector}, \@ds_array, \@properties);
|
||||||
return if (!defined($result2));
|
return if (!defined($result2));
|
||||||
|
|
|
@ -207,7 +207,8 @@ sub search_in_datastore {
|
||||||
my (%options) = @_;
|
my (%options) = @_;
|
||||||
my $result;
|
my $result;
|
||||||
|
|
||||||
my $files = FileQueryFlags->new(fileSize => 1,
|
my $files = FileQueryFlags->new(
|
||||||
|
fileSize => 1,
|
||||||
fileType => 1,
|
fileType => 1,
|
||||||
modification => 1,
|
modification => 1,
|
||||||
fileOwner => 1
|
fileOwner => 1
|
||||||
|
@ -219,8 +220,10 @@ sub search_in_datastore {
|
||||||
query => $options{query}
|
query => $options{query}
|
||||||
);
|
);
|
||||||
eval {
|
eval {
|
||||||
$result = $options{browse_ds}->SearchDatastoreSubFolders(datastorePath => $options{ds_name},
|
$result = $options{browse_ds}->SearchDatastoreSubFolders(
|
||||||
searchSpec => $hostdb_search_spec);
|
datastorePath => $options{ds_name},
|
||||||
|
searchSpec => $hostdb_search_spec
|
||||||
|
);
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
return (undef, $@) if (defined($options{return}) && $options{return} == 1);
|
return (undef, $@) if (defined($options{return}) && $options{return} == 1);
|
||||||
|
@ -237,16 +240,22 @@ sub get_perf_metric_ids {
|
||||||
foreach (@{$options{metrics}}) {
|
foreach (@{$options{metrics}}) {
|
||||||
if (defined($options{connector}->{perfcounter_cache}->{$_->{label}})) {
|
if (defined($options{connector}->{perfcounter_cache}->{$_->{label}})) {
|
||||||
if ($options{interval} != 20 && $options{connector}->{perfcounter_cache}->{$_->{label}}{level} > $options{connector}->{sampling_periods}->{$options{interval}}->{level}) {
|
if ($options{interval} != 20 && $options{connector}->{perfcounter_cache}->{$_->{label}}{level} > $options{connector}->{sampling_periods}->{$options{interval}}->{level}) {
|
||||||
set_response(code => -1,
|
set_response(
|
||||||
short_message => sprintf("Cannot get counter '%s' for the sampling period '%s' (counter level: %s, sampling level: %s)",
|
code => -1,
|
||||||
|
short_message => sprintf(
|
||||||
|
"Cannot get counter '%s' for the sampling period '%s' (counter level: %s, sampling level: %s)",
|
||||||
$_->{label}, $options{interval},
|
$_->{label}, $options{interval},
|
||||||
$options{connector}->{perfcounter_cache}->{$_->{label}}{level},
|
$options{connector}->{perfcounter_cache}->{$_->{label}}{level},
|
||||||
$options{connector}->{sampling_periods}->{$options{interval}}->{level}));
|
$options{connector}->{sampling_periods}->{$options{interval}}->{level}
|
||||||
|
)
|
||||||
|
);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
foreach my $instance (@{$_->{instances}}) {
|
foreach my $instance (@{$_->{instances}}) {
|
||||||
my $metric = PerfMetricId->new(counterId => $options{connector}->{perfcounter_cache}->{$_->{label}}{key},
|
my $metric = PerfMetricId->new(
|
||||||
instance => $instance);
|
counterId => $options{connector}->{perfcounter_cache}->{$_->{label}}{key},
|
||||||
|
instance => $instance
|
||||||
|
);
|
||||||
push @$filtered_list, $metric;
|
push @$filtered_list, $metric;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -264,20 +273,27 @@ sub performance_builder_specific {
|
||||||
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
||||||
my @perf_query_spec;
|
my @perf_query_spec;
|
||||||
foreach my $entry (@{$options{metrics}}) {
|
foreach my $entry (@{$options{metrics}}) {
|
||||||
my $perf_metric_ids = get_perf_metric_ids(connector => $options{connector},
|
my $perf_metric_ids = get_perf_metric_ids(
|
||||||
|
connector => $options{connector},
|
||||||
metrics => $entry->{metrics},
|
metrics => $entry->{metrics},
|
||||||
interval => $options{interval});
|
interval => $options{interval}
|
||||||
|
);
|
||||||
return undef if (!defined($perf_metric_ids));
|
return undef if (!defined($perf_metric_ids));
|
||||||
|
|
||||||
my $tstamp = time();
|
my $tstamp = time();
|
||||||
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
||||||
my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
|
my $startTime = sprintf(
|
||||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
|
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||||
|
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||||
|
);
|
||||||
(@t) = gmtime($tstamp);
|
(@t) = gmtime($tstamp);
|
||||||
my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
|
my $endTime = sprintf(
|
||||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
|
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||||
|
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||||
|
);
|
||||||
if ($options{interval} == 20) {
|
if ($options{interval} == 20) {
|
||||||
push @perf_query_spec, PerfQuerySpec->new(entity => $entry->{entity},
|
push @perf_query_spec, PerfQuerySpec->new(
|
||||||
|
entity => $entry->{entity},
|
||||||
metricId => $perf_metric_ids,
|
metricId => $perf_metric_ids,
|
||||||
format => 'normal',
|
format => 'normal',
|
||||||
intervalId => 20,
|
intervalId => 20,
|
||||||
|
@ -286,7 +302,8 @@ sub performance_builder_specific {
|
||||||
);
|
);
|
||||||
#maxSample => 1);
|
#maxSample => 1);
|
||||||
} else {
|
} else {
|
||||||
push @perf_query_spec, PerfQuerySpec->new(entity => $entry->{entity},
|
push @perf_query_spec, PerfQuerySpec->new(
|
||||||
|
entity => $entry->{entity},
|
||||||
metricId => $perf_metric_ids,
|
metricId => $perf_metric_ids,
|
||||||
format => 'normal',
|
format => 'normal',
|
||||||
intervalId => $options{interval},
|
intervalId => $options{interval},
|
||||||
|
@ -305,30 +322,39 @@ sub performance_builder_global {
|
||||||
|
|
||||||
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
||||||
my @perf_query_spec;
|
my @perf_query_spec;
|
||||||
my $perf_metric_ids = get_perf_metric_ids(connector => $options{connector},
|
my $perf_metric_ids = get_perf_metric_ids(
|
||||||
|
connector => $options{connector},
|
||||||
metrics => $options{metrics},
|
metrics => $options{metrics},
|
||||||
interval => $options{interval});
|
interval => $options{interval}
|
||||||
|
);
|
||||||
return undef if (!defined($perf_metric_ids));
|
return undef if (!defined($perf_metric_ids));
|
||||||
|
|
||||||
my $tstamp = time();
|
my $tstamp = time();
|
||||||
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
||||||
my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
|
my $startTime = sprintf(
|
||||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
|
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||||
|
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||||
|
);
|
||||||
(@t) = gmtime($tstamp);
|
(@t) = gmtime($tstamp);
|
||||||
my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
|
my $endTime = sprintf(
|
||||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
|
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||||
|
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||||
|
);
|
||||||
|
|
||||||
foreach (@{$options{views}}) {
|
foreach (@{$options{views}}) {
|
||||||
if ($options{interval} == 20) {
|
if ($options{interval} == 20) {
|
||||||
push @perf_query_spec, PerfQuerySpec->new(entity => $_,
|
push @perf_query_spec, PerfQuerySpec->new(
|
||||||
|
entity => $_,
|
||||||
metricId => $perf_metric_ids,
|
metricId => $perf_metric_ids,
|
||||||
format => 'normal',
|
format => 'normal',
|
||||||
intervalId => 20,
|
intervalId => 20,
|
||||||
startTime => $startTime,
|
startTime => $startTime,
|
||||||
endTime => $endTime);
|
endTime => $endTime
|
||||||
|
);
|
||||||
#maxSample => 1);
|
#maxSample => 1);
|
||||||
} else {
|
} else {
|
||||||
push @perf_query_spec, PerfQuerySpec->new(entity => $_,
|
push @perf_query_spec, PerfQuerySpec->new(
|
||||||
|
entity => $_,
|
||||||
metricId => $perf_metric_ids,
|
metricId => $perf_metric_ids,
|
||||||
format => 'normal',
|
format => 'normal',
|
||||||
intervalId => $options{interval},
|
intervalId => $options{interval},
|
||||||
|
@ -364,14 +390,20 @@ sub generic_performance_values_historic {
|
||||||
my $perfdata;
|
my $perfdata;
|
||||||
|
|
||||||
if (defined($views)) {
|
if (defined($views)) {
|
||||||
$perfdata = performance_builder_global(connector => $obj_vmware,
|
$perfdata = performance_builder_global(
|
||||||
|
connector => $obj_vmware,
|
||||||
views => $views,
|
views => $views,
|
||||||
metrics => $perfs,
|
metrics => $perfs,
|
||||||
interval => $interval, time_shift => $options{time_shift});
|
interval => $interval,
|
||||||
|
time_shift => $options{time_shift}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$perfdata = performance_builder_specific(connector => $obj_vmware,
|
$perfdata = performance_builder_specific(
|
||||||
|
connector => $obj_vmware,
|
||||||
metrics => $perfs,
|
metrics => $perfs,
|
||||||
interval => $interval, time_shift => $options{time_shift});
|
interval => $interval,
|
||||||
|
time_shift => $options{time_shift}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return undef if (!defined($perfdata));
|
return undef if (!defined($perfdata));
|
||||||
|
|
||||||
|
@ -412,8 +444,14 @@ sub generic_performance_values_historic {
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
if ($@ =~ /querySpec.interval.*InvalidArgumentFault/msi) {
|
if ($@ =~ /querySpec.interval.*InvalidArgumentFault/msi) {
|
||||||
set_response(code => -1, short_message => sprintf("Interval '%s' is surely not supported for the managed entity (caller: %s)",
|
set_response(
|
||||||
$interval, join('--', caller)));
|
code => -1,
|
||||||
|
short_message => sprintf(
|
||||||
|
"Interval '%s' is surely not supported for the managed entity (caller: %s)",
|
||||||
|
$interval,
|
||||||
|
join('--', caller)
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$obj_vmware->{logger}->writeLogError("'" . $obj_vmware->{whoaim} . "' $@");
|
$obj_vmware->{logger}->writeLogError("'" . $obj_vmware->{whoaim} . "' $@");
|
||||||
}
|
}
|
||||||
|
@ -466,8 +504,14 @@ sub search_entities {
|
||||||
if (scalar(@$begin_views) > 0) {
|
if (scalar(@$begin_views) > 0) {
|
||||||
my $temp_views = [];
|
my $temp_views = [];
|
||||||
while ((my $view = shift @$begin_views)) {
|
while ((my $view = shift @$begin_views)) {
|
||||||
my ($status, $views) = find_entity_views(connector => $options{command}->{connector}, view_type => $$scope[1], properties => $properties, filter => $filters,
|
my ($status, $views) = find_entity_views(
|
||||||
begin_entity => $view, output_message => 0);
|
connector => $options{command}->{connector},
|
||||||
|
view_type => $$scope[1],
|
||||||
|
properties => $properties,
|
||||||
|
filter => $filters,
|
||||||
|
begin_entity => $view,
|
||||||
|
output_message => 0
|
||||||
|
);
|
||||||
next if ($status == 0);
|
next if ($status == 0);
|
||||||
return undef if ($status == -1);
|
return undef if ($status == -1);
|
||||||
push @$temp_views, @$views;
|
push @$temp_views, @$views;
|
||||||
|
@ -490,8 +534,14 @@ sub search_entities {
|
||||||
if (scalar(@$begin_views) > 0) {
|
if (scalar(@$begin_views) > 0) {
|
||||||
my $results = [];
|
my $results = [];
|
||||||
foreach my $view (@$begin_views) {
|
foreach my $view (@$begin_views) {
|
||||||
my ($status, $views) = find_entity_views(connector => $options{command}->{connector}, view_type => $options{view_type}, properties => $options{properties}, filter => $options{filter},
|
my ($status, $views) = find_entity_views(
|
||||||
begin_entity => $view, output_message => 0);
|
connector => $options{command}->{connector},
|
||||||
|
view_type => $options{view_type},
|
||||||
|
properties => $options{properties},
|
||||||
|
filter => $options{filter},
|
||||||
|
begin_entity => $view,
|
||||||
|
output_message => 0
|
||||||
|
);
|
||||||
next if ($status == 0);
|
next if ($status == 0);
|
||||||
return undef if ($status == -1);
|
return undef if ($status == -1);
|
||||||
push @$results, @$views;
|
push @$results, @$views;
|
||||||
|
@ -699,11 +749,15 @@ sub vsan_get_performances {
|
||||||
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
||||||
my $tstamp = time();
|
my $tstamp = time();
|
||||||
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
||||||
my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
|
my $startTime = sprintf(
|
||||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
|
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||||
|
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||||
|
);
|
||||||
(@t) = gmtime($tstamp);
|
(@t) = gmtime($tstamp);
|
||||||
my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
|
my $endTime = sprintf(
|
||||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
|
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||||
|
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]
|
||||||
|
);
|
||||||
my $querySpec = VsanPerfQuerySpec->new(
|
my $querySpec = VsanPerfQuerySpec->new(
|
||||||
entityRefId => $options{entityRefId}, # for example: 'virtual-machine:*'
|
entityRefId => $options{entityRefId}, # for example: 'virtual-machine:*'
|
||||||
labels => $options{labels}, # for example: ['iopsRead, iopsWrite']
|
labels => $options{labels}, # for example: ['iopsRead, iopsWrite']
|
||||||
|
|
Loading…
Reference in New Issue