WIP: begin vsan
This commit is contained in:
parent
5158666650
commit
ef884d2a8d
|
@ -54,7 +54,7 @@ BEGIN {
|
|||
use base qw(centreon::vmware::script);
|
||||
use vars qw(%centreon_vmware_config);
|
||||
|
||||
my $VERSION = "3.0.3";
|
||||
my $VERSION = "3.1.0";
|
||||
my %handlers = (TERM => {}, HUP => {}, CHLD => {});
|
||||
|
||||
my @load_modules = (
|
||||
|
@ -124,7 +124,8 @@ sub new {
|
|||
#'testvc' => {'url' => 'https://XXXXXX/sdk',
|
||||
# 'username' => 'XXXXX',
|
||||
# 'password' => 'XXXXXX'}
|
||||
}
|
||||
},
|
||||
vsan_sdk_path => '/usr/share/perl5/VMware',
|
||||
);
|
||||
|
||||
$self->{return_child} = {};
|
||||
|
@ -158,6 +159,15 @@ sub init {
|
|||
##### Load modules
|
||||
$self->load_module(@load_modules);
|
||||
|
||||
$self->{vsan_enabled} = 0;
|
||||
eval {
|
||||
centreon::vmware::common::load_vsanmgmt_binding_files(
|
||||
path => $self->{centreon_vmware_config}->{vsan_sdk_path},
|
||||
files => ['VIM25VsanmgmtStub.pm', 'VIM25VsanmgmtRuntime.pm'],
|
||||
);
|
||||
$self->{vsan_enabled} = 1;
|
||||
};
|
||||
|
||||
##### credstore check #####
|
||||
if (defined($self->{centreon_vmware_config}->{credstore_use}) && defined($self->{centreon_vmware_config}->{credstore_file}) &&
|
||||
$self->{centreon_vmware_config}->{credstore_use} == 1 && -e "$self->{centreon_vmware_config}->{credstore_file}") {
|
||||
|
@ -497,10 +507,13 @@ sub create_vsphere_child {
|
|||
return -1;
|
||||
}
|
||||
if ($child_vpshere_pid == 0) {
|
||||
my $connector = centreon::vmware::connector->new(name => $self->{whoaim},
|
||||
my $connector = centreon::vmware::connector->new(
|
||||
name => $self->{whoaim},
|
||||
modules_registry => $self->{modules_registry},
|
||||
config => $self->{centreon_vmware_config},
|
||||
logger => $self->{logger});
|
||||
logger => $self->{logger},
|
||||
vsan_enabled => $self->{vsan_enabled},
|
||||
);
|
||||
$connector->run();
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
@ -60,6 +60,16 @@ sub handle_ALRM {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
sub is_vsan_enabled {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if ($self->{connector}->{vsan_enabled} == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_connector {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
|
|
@ -54,19 +54,25 @@ sub run {
|
|||
}
|
||||
|
||||
my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter');
|
||||
my @properties = ('summary.accessible', 'summary.name', 'vm', 'info');
|
||||
my @properties = ('summary.accessible', 'summary.name', 'summary.type', 'vm', 'info');
|
||||
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters);
|
||||
return if (!defined($result));
|
||||
|
||||
my $ds_vsan = {};
|
||||
|
||||
my $data = {};
|
||||
#my %uuid_list = ();
|
||||
my %disk_name = ();
|
||||
my %datastore_lun = ();
|
||||
my $ds_checked = 0;
|
||||
foreach (@$result) {
|
||||
$data->{$_->{'summary.name'}} = { name => $_->{'summary.name'}, accessible => $_->{'summary.accessible'} };
|
||||
$data->{$_->{'summary.name'}} = { name => $_->{'summary.name'}, accessible => $_->{'summary.accessible'}, type => $_->{'summary.type'} };
|
||||
next if (centreon::vmware::common::is_accessible(accessible => $_->{'summary.accessible'}) == 0);
|
||||
|
||||
if ($_->{'summary.type'} eq 'vsan') {
|
||||
$ds_vsan->{$_->{mo_ref}->{value}} = $_->{'summary.name'};
|
||||
$ds_checked = 1;
|
||||
}
|
||||
if ($_->info->isa('VmfsDatastoreInfo')) {
|
||||
#$uuid_list{$_->volume->uuid} = $_->volume->name;
|
||||
# Not need. We are on Datastore level (not LUN level)
|
||||
|
@ -125,21 +131,52 @@ sub run {
|
|||
return ;
|
||||
}
|
||||
|
||||
my $interval_sec = $self->{connector}->{perfcounter_speriod};
|
||||
if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') {
|
||||
$interval_sec = $self->{sampling_period};
|
||||
}
|
||||
|
||||
# VSAN part
|
||||
if ($self->is_vsan_enabled() && scalar(keys(%$ds_vsan)) > 0) {
|
||||
my $vsan_performance_mgr = centreon::vmware::common::vsan_create_mo_view(
|
||||
vsan_vim => $self->{connector}->{vsan_vim},
|
||||
type => 'VsanPerformanceManager',
|
||||
value => 'vsan-performance-manager',
|
||||
);
|
||||
my $cluster_views = centreon::vmware::common::search_entities(command => $self, view_type => 'ComputeResource', properties => ['name', 'datastore'], filter => undef);
|
||||
my $clusters = {};
|
||||
foreach my $cluster_view (@$cluster_views) {
|
||||
$clusters->{view} = $cluster_view;
|
||||
foreach (@{$cluster_view->{datastore}}) {
|
||||
if (defined($ds_vsan->{$_->{value}})) {
|
||||
$clusters->{ds_vsan} = $_->{value};
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
centreon::vmware::common::vsan_get_performances(
|
||||
cluster => $cluster_view,
|
||||
entityRefId => 'virtual-machine:*',
|
||||
labels => ['iopsRead', 'iopsWrite'],
|
||||
interval => $interval_sec,
|
||||
time_shift => $self->{time_shift}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# Vsphere >= 4.1
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector},
|
||||
my $values = centreon::vmware::common::generic_performance_values_historic(
|
||||
$self->{connector},
|
||||
$result2,
|
||||
[{'label' => 'disk.numberRead.summation', 'instances' => ['*']},
|
||||
{'label' => 'disk.numberWrite.summation', 'instances' => ['*']}],
|
||||
$self->{connector}->{perfcounter_speriod},
|
||||
sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift},
|
||||
skip_undef_counter => 1, multiples => 1);
|
||||
skip_undef_counter => 1, multiples => 1
|
||||
);
|
||||
|
||||
return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1);
|
||||
|
||||
my $interval_sec = $self->{connector}->{perfcounter_speriod};
|
||||
if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') {
|
||||
$interval_sec = $self->{sampling_period};
|
||||
}
|
||||
foreach (keys %$values) {
|
||||
my ($vm_id, $id, $disk_name) = split(/:/);
|
||||
|
||||
|
@ -163,16 +200,20 @@ sub run {
|
|||
$data->{$_}->{'disk.numberWrite.summation'} = $total_write_counter;
|
||||
$data->{$_}->{vm} = {};
|
||||
|
||||
$self->vm_iops_details(label => 'disk.numberRead.summation',
|
||||
$self->vm_iops_details(
|
||||
label => 'disk.numberRead.summation',
|
||||
type => 'read',
|
||||
detail => $datastore_lun{$_},
|
||||
ref_vm => \%ref_ids_vm,
|
||||
data => $data);
|
||||
$self->vm_iops_details(label => 'disk.numberWrite.summation',
|
||||
data => $data
|
||||
);
|
||||
$self->vm_iops_details(
|
||||
label => 'disk.numberWrite.summation',
|
||||
type => 'write',
|
||||
detail => $datastore_lun{$_},
|
||||
ref_vm => \%ref_ids_vm,
|
||||
data_vm => $data->{$_}->{vm});
|
||||
data_vm => $data->{$_}->{vm}
|
||||
);
|
||||
}
|
||||
|
||||
centreon::vmware::common::set_response(data => $data);
|
||||
|
|
|
@ -103,21 +103,26 @@ sub vmware_error {
|
|||
}
|
||||
|
||||
sub connect_vsphere {
|
||||
my ($logger, $whoaim, $timeout_vsphere, $session1, $service_url, $username, $password) = @_;
|
||||
$logger->writeLogInfo("'$whoaim' Vsphere connection in progress");
|
||||
my (%options) = @_;
|
||||
|
||||
$options{logger}->writeLogInfo("'$options{whoaim}' Vsphere connection in progress");
|
||||
eval {
|
||||
$SIG{ALRM} = sub { die('TIMEOUT'); };
|
||||
alarm($timeout_vsphere);
|
||||
$$session1 = Vim->new(service_url => $service_url);
|
||||
$$session1->login(
|
||||
user_name => $username,
|
||||
password => $password);
|
||||
alarm($options{connect_timeout});
|
||||
$options{connector}->{session1} = Vim->new(service_url => $options{url});
|
||||
$options{connector}->{session1}->login(
|
||||
user_name => $options{username},
|
||||
password => $options{password}
|
||||
);
|
||||
|
||||
get_vsan_vim(%options) if ($options{vsan_enabled} == 1);
|
||||
|
||||
alarm(0);
|
||||
};
|
||||
if ($@) {
|
||||
$logger->writeLogError("'$whoaim' No response from VirtualCenter server") if($@ =~ /TIMEOUT/);
|
||||
$logger->writeLogError("'$whoaim' You need to upgrade HTTP::Message!") if($@ =~ /HTTP::Message/);
|
||||
$logger->writeLogError("'$whoaim' Login to VirtualCenter server failed: $@");
|
||||
$options{logger}->writeLogError("'$options{whoaim}' No response from VirtualCenter server") if($@ =~ /TIMEOUT/);
|
||||
$options{logger}->writeLogError("'$options{whoaim}' You need to upgrade HTTP::Message!") if($@ =~ /HTTP::Message/);
|
||||
$options{logger}->writeLogError("'$options{whoaim}' Login to VirtualCenter server failed: $@");
|
||||
return 1;
|
||||
}
|
||||
# eval {
|
||||
|
@ -626,4 +631,92 @@ sub stats_info {
|
|||
set_response(data => $data);
|
||||
}
|
||||
|
||||
#
|
||||
# Vsan
|
||||
#
|
||||
|
||||
sub load_vsanmgmt_binding_files {
|
||||
my (%options) = @_;
|
||||
|
||||
my @stub = ();
|
||||
local $/;
|
||||
for (@{$options{files}}) {
|
||||
open(STUB, $options{path} . '/' . $_) or die $!;
|
||||
push @stub, split /\n####+?\n/, <STUB>;
|
||||
close STUB or die $!;
|
||||
}
|
||||
for (@stub) {
|
||||
my ($package) = /\bpackage\s+(\w+)/;
|
||||
$VIMRuntime::stub_class{$package} = $_ if (defined($package));
|
||||
}
|
||||
eval $VIMRuntime::stub_class{'VimService'};
|
||||
}
|
||||
|
||||
sub get_vsan_vim {
|
||||
my (%options) = @_;
|
||||
|
||||
require URI::URL;
|
||||
my $session_id = $options{connector}->{session1}->get_session_id();
|
||||
my $url = URI::URL->new($options{connector}->{session1}->get_service_url());
|
||||
my $api_type = $options{connector}->{session1}->get_service_content()->about->apiType;
|
||||
|
||||
my $service_url_path = "sdk/vimService";
|
||||
my $path = "vsanHealth";
|
||||
if ($api_type eq "HostAgent") {
|
||||
$service_url_path = "sdk";
|
||||
$path = "vsan";
|
||||
}
|
||||
|
||||
$options{connector}->{vsan_vim} = Vim->new(
|
||||
service_url =>
|
||||
'https://' . $url->host . '/' . $service_url_path,
|
||||
server => $url->host,
|
||||
protocol => "https",
|
||||
path => $path,
|
||||
port => '443'
|
||||
);
|
||||
|
||||
$options{connector}->{vsan_vim}->{vim_service} = VimService->new($options{connector}->{vsan_vim}->{service_url});
|
||||
$options{connector}->{vsan_vim}->{vim_service}->load_session_id($session_id);
|
||||
$options{connector}->{vsan_vim}->unset_logout_on_disconnect;
|
||||
}
|
||||
|
||||
sub vsan_create_mo_view {
|
||||
my (%options) = @_;
|
||||
|
||||
my $moref = ManagedObjectReference->new(
|
||||
type => $options{type},
|
||||
value => $options{value},
|
||||
);
|
||||
my $view_type = $moref->type;
|
||||
my $mo_view = $view_type->new($moref, $options{vsan_vim});
|
||||
return $mo_view;
|
||||
}
|
||||
|
||||
sub vsan_get_performances {
|
||||
my (%options) = @_;
|
||||
|
||||
my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0;
|
||||
my $tstamp = time();
|
||||
my (@t) = gmtime($tstamp - $options{interval} - $time_shift);
|
||||
my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
|
||||
(@t) = gmtime($tstamp);
|
||||
my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
|
||||
(1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]);
|
||||
my $querySpec = VsanPerfQuerySpec->new(
|
||||
entityRefId => $options{entityRefId}, # for example: 'virtual-machine:*'
|
||||
labels => $options{labels}, # for example: ['iopsRead, iopsWrite']
|
||||
startTime = $startTime,
|
||||
endTime = $endTime,
|
||||
);
|
||||
my $values = $options{vsan_performance_mgr}->VsanPerfQueryPerf(
|
||||
querySpecs => [$querySpec],
|
||||
cluster => $options{cluster},
|
||||
);
|
||||
|
||||
use Data::Dumper;
|
||||
print Data::Dumper::Dumper($values);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -54,6 +54,7 @@ sub new {
|
|||
$connector->{modules_registry} = $options{modules_registry};
|
||||
$connector->{logger} = $options{logger};
|
||||
$connector->{whoaim} = $options{name};
|
||||
$connector->{vsan_enabled} = $options{vsan_enabled};
|
||||
$connector->{config_ipc_file} = $options{config}->{ipc_file};
|
||||
$connector->{config_child_timeout} = $options{config}->{timeout};
|
||||
$connector->{config_stop_child_timeout} = $options{config}->{timeout_kill};
|
||||
|
@ -272,13 +273,17 @@ sub run {
|
|||
}
|
||||
|
||||
if ($connector->{vsphere_connected} == 0) {
|
||||
if (!centreon::vmware::common::connect_vsphere($connector->{logger},
|
||||
$connector->{whoaim},
|
||||
$connector->{config_vsphere_connect_timeout},
|
||||
\$connector->{session1},
|
||||
$connector->{config_vsphere_url},
|
||||
$connector->{config_vsphere_user},
|
||||
$connector->{config_vsphere_pass})) {
|
||||
if (!centreon::vmware::common::connect_vsphere(
|
||||
logger => $connector->{logger},
|
||||
whoaim => $connector->{whoaim},
|
||||
connect_timeout => $connector->{config_vsphere_connect_timeout},
|
||||
connector => $connector,
|
||||
url => $connector->{config_vsphere_url},
|
||||
username => $connector->{config_vsphere_user},
|
||||
password => $connector->{config_vsphere_pass},
|
||||
vsan_enabled => $connector->{vsan_enabled},
|
||||
)
|
||||
) {
|
||||
$connector->{logger}->writeLogInfo("'" . $connector->{whoaim} . "' Vsphere connection ok");
|
||||
$connector->{logger}->writeLogInfo("'" . $connector->{whoaim} . "' Create perf counters cache in progress");
|
||||
if (!centreon::vmware::common::cache_perf_counters($connector)) {
|
||||
|
|
Loading…
Reference in New Issue