+ add memory system for alarms
This commit is contained in:
parent
c8e99a53f8
commit
d350bc4535
|
@ -4,6 +4,8 @@ package centreon::esxd::cmdalarmdatacenter;
|
|||
use strict;
|
||||
use warnings;
|
||||
use centreon::esxd::common;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
|
@ -52,6 +54,15 @@ sub set_connector {
|
|||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (defined($self->{memory})) {
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(output => $self->{manager}->{output});
|
||||
$self->{statefile_cache}->read(statefile_dir => $self->{obj_esxd}->{retention_dir},
|
||||
statefile => "cache_vmware_connector_" . $self->{obj_esxd}->{whoaim} . "_" . $self->{commandName} . "_" . (defined($self->{datacenter}) ? md5_hex($self->{datacenter}) : md5_hex('.*')),
|
||||
statefile_suffix => '',
|
||||
no_quit => 1);
|
||||
return if ($self->{statefile_cache}->error() == 1);
|
||||
}
|
||||
|
||||
my %filters = ();
|
||||
my $multiple = 0;
|
||||
|
||||
|
@ -76,12 +87,14 @@ sub run {
|
|||
if (scalar(@$result) > 1) {
|
||||
$multiple = 1;
|
||||
}
|
||||
|
||||
$self->{manager}->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("No current alarms on datacenter(s)"));
|
||||
|
||||
my $alarmMgr = centreon::esxd::common::get_view($self->{obj_esxd}, $self->{obj_esxd}->{session1}->get_service_content()->alarmManager, undef);
|
||||
my $total_alarms = { red => 0, yellow => 0 };
|
||||
my $dc_alarms = {};
|
||||
my $new_datas = {};
|
||||
foreach my $datacenter_view (@$result) {
|
||||
$dc_alarms->{$datacenter_view->name} = { red => 0, yellow => 0, alarms => {} };
|
||||
next if (!defined($datacenter_view->triggeredAlarmState));
|
||||
|
@ -91,6 +104,9 @@ sub run {
|
|||
my $time_sec = Date::Parse::str2time($_->time);
|
||||
next if (time() - $time_sec > $self->{filter_time});
|
||||
}
|
||||
$new_datas->{$_->key} = 1;
|
||||
next if (defined($self->{memory}) && defined($self->{statefile_cache}->get(name => $_->key)));
|
||||
|
||||
my $entity = centreon::esxd::common::get_view($self->{obj_esxd}, $_->entity, ['name']);
|
||||
my $alarm = centreon::esxd::common::get_view($self->{obj_esxd}, $_->alarm, ['info']);
|
||||
|
||||
|
@ -138,6 +154,10 @@ sub run {
|
|||
value => $dc_alarms->{$dc_name}->{red},
|
||||
min => 0);
|
||||
}
|
||||
|
||||
if (defined($self->{memory})) {
|
||||
$self->{statefile_cache}->write(data => $new_datas);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -4,6 +4,8 @@ package centreon::esxd::cmdalarmhost;
|
|||
use strict;
|
||||
use warnings;
|
||||
use centreon::esxd::common;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
|
@ -52,6 +54,15 @@ sub set_connector {
|
|||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
if (defined($self->{memory})) {
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(output => $self->{manager}->{output});
|
||||
$self->{statefile_cache}->read(statefile_dir => $self->{obj_esxd}->{retention_dir},
|
||||
statefile => "cache_vmware_connector_" . $self->{obj_esxd}->{whoaim} . "_" . (defined($self->{esx_hostname}) ? md5_hex($self->{esx_hostname}) : md5_hex('.*')),
|
||||
statefile_suffix => '',
|
||||
no_quit => 1);
|
||||
return if ($self->{statefile_cache}->error() == 1);
|
||||
}
|
||||
|
||||
my %filters = ();
|
||||
my $multiple = 0;
|
||||
|
||||
|
@ -82,6 +93,7 @@ sub run {
|
|||
my $alarmMgr = centreon::esxd::common::get_view($self->{obj_esxd}, $self->{obj_esxd}->{session1}->get_service_content()->alarmManager, undef);
|
||||
my $total_alarms = { red => 0, yellow => 0 };
|
||||
my $dc_alarms = {};
|
||||
my $new_datas = {};
|
||||
foreach my $datacenter_view (@$result) {
|
||||
$dc_alarms->{$datacenter_view->name} = { red => 0, yellow => 0, alarms => {} };
|
||||
next if (!defined($datacenter_view->triggeredAlarmState));
|
||||
|
@ -91,6 +103,9 @@ sub run {
|
|||
my $time_sec = Date::Parse::str2time($_->time);
|
||||
next if (time() - $time_sec > $self->{filter_time});
|
||||
}
|
||||
$new_datas->{$_->key} = 1;
|
||||
next if (defined($self->{memory}) && defined($self->{statefile_cache}->get(name => $_->key)));
|
||||
|
||||
my $entity = centreon::esxd::common::get_view($self->{obj_esxd}, $_->entity, ['name']);
|
||||
my $alarm = centreon::esxd::common::get_view($self->{obj_esxd}, $_->alarm, ['info']);
|
||||
|
||||
|
@ -138,6 +153,10 @@ sub run {
|
|||
value => $dc_alarms->{$dc_name}->{red},
|
||||
min => 0);
|
||||
}
|
||||
|
||||
if (defined($self->{memory})) {
|
||||
$self->{statefile_cache}->write(data => $new_datas);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -444,7 +444,7 @@ sub is_running {
|
|||
|
||||
sub datastore_state {
|
||||
my (%options) = @_;
|
||||
my $status = defined($options{status}) ? $options{status} : $options{connector}->{centreonesxd_config}->{datastore_state_error};
|
||||
my $status = defined($options{status}) ? $options{status} : $options{connector}->{datastore_state_error};
|
||||
|
||||
if ($options{state} !~ /^true|1$/) {
|
||||
my $output = "Datastore '" . $options{name} . "' not accessible. Current connection state: '$options{state}'.";
|
||||
|
@ -461,8 +461,8 @@ sub datastore_state {
|
|||
|
||||
sub vm_state {
|
||||
my (%options) = @_;
|
||||
my $status = defined($options{status}) ? $options{status} : $options{connector}->{centreonesxd_config}->{host_state_error};
|
||||
my $power_status = defined($options{powerstatus}) ? $options{powerstatus} : $options{connector}->{centreonesxd_config}->{vm_state_error};
|
||||
my $status = defined($options{status}) ? $options{status} : $options{connector}->{host_state_error};
|
||||
my $power_status = defined($options{powerstatus}) ? $options{powerstatus} : $options{connector}->{vm_state_error};
|
||||
|
||||
if ($options{state} !~ /^connected$/i) {
|
||||
my $output = "VM '" . $options{hostname} . "' not connected. Current Connection State: '$options{state}'.";
|
||||
|
@ -489,7 +489,7 @@ sub vm_state {
|
|||
|
||||
sub host_state {
|
||||
my (%options) = @_;
|
||||
my $status = defined($options{status}) ? $options{status} : $options{connector}->{centreonesxd_config}->{host_state_error};
|
||||
my $status = defined($options{status}) ? $options{status} : $options{connector}->{host_state_error};
|
||||
|
||||
if ($options{state} !~ /^connected$/i) {
|
||||
my $output = "Host '" . $options{hostname} . "' not connected. Current Connection State: '$options{state}'.";
|
||||
|
|
|
@ -46,6 +46,10 @@ sub new {
|
|||
$connector->{config_vsphere_url} = $options{config}->{vsphere_server}->{$options{name}}->{url};
|
||||
$connector->{config_vsphere_user} = $options{config}->{vsphere_server}->{$options{name}}->{username};
|
||||
$connector->{config_vsphere_pass} = $options{config}->{vsphere_server}->{$options{name}}->{password};
|
||||
$connector->{retention_dir} = $options{config}->{retention_dir};
|
||||
$connector->{datastore_state_error} = $options{config}->{datastore_state_error};
|
||||
$connector->{vm_state_error} = $options{config}->{vm_state_error};
|
||||
$connector->{host_state_error} = $options{config}->{host_state_error};
|
||||
|
||||
return $connector;
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ sub new {
|
|||
datastore_state_error => 'UNKNOWN',
|
||||
vm_state_error => 'UNKNOWN',
|
||||
host_state_error => 'UNKNOWN',
|
||||
retention_dir => '/var/lib/centreon/centplugins',
|
||||
vsphere_server => {
|
||||
#'default' => {'url' => 'https://XXXXXX/sdk',
|
||||
# 'username' => 'XXXXX',
|
||||
|
|
Loading…
Reference in New Issue