enh(fujitsu/eternus/dx): psu mode - check drive power supplies (#3025)

This commit is contained in:
qgarnier 2021-08-06 11:18:53 +02:00 committed by GitHub
parent 2ae600546d
commit f0bcbc76e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 101 additions and 80 deletions

View File

@ -26,6 +26,7 @@ use strict;
use warnings; use warnings;
use centreon::plugins::misc; use centreon::plugins::misc;
use centreon::common::powershell::exchange::listdatabases; use centreon::common::powershell::exchange::listdatabases;
use JSON::XS;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
@ -42,6 +43,7 @@ sub new {
'command-path:s' => { name => 'command_path' }, 'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-exec-only' => { name => 'ps_exec_only' },
'ps-display' => { name => 'ps_display' },
'ps-database-filter:s' => { name => 'ps_database_filter' } 'ps-database-filter:s' => { name => 'ps_database_filter' }
}); });
@ -53,6 +55,20 @@ sub check_options {
$self->SUPER::init(%options); $self->SUPER::init(%options);
} }
sub manage_selection {
my ($self, %options) = @_;
my $decoded;
eval {
$decoded = JSON::XS->new->decode($options{stdout});
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
$self->{output}->option_exit();
}
return $decoded;
}
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -75,9 +91,9 @@ sub run {
$self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps);
} }
my ($stdout) = centreon::plugins::misc::windows_execute( my ($stdout) = centreon::plugins::misc::execute(
output => $self->{output}, output => $self->{output},
timeout => $self->{option_results}->{timeout}, options => $self->{option_results},
command => $self->{option_results}->{command}, command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path}, command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} command_options => $self->{option_results}->{command_options}
@ -92,7 +108,18 @@ sub run {
severity => 'OK', severity => 'OK',
short_msg => 'List databases:' short_msg => 'List databases:'
); );
centreon::common::powershell::exchange::listdatabases::list($self, stdout => $stdout);
my $decoded = $self->manage_selection(stdout => $stdout);
foreach my $db (@$decoded) {
$self->{output}->output_add(
long_msg => sprintf(
"[name: %s][server: %s][mounted: %s]",
$db->{name},
$db->{server},
$db->{mounted} =~ /True|1/i ? 'true' : 'false'
)
);
}
} }
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
@ -117,14 +144,24 @@ sub disco_show {
); );
$self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps);
} }
my ($stdout) = centreon::plugins::misc::windows_execute(
my ($stdout) = centreon::plugins::misc::execute(
output => $self->{output}, output => $self->{output},
timeout => $self->{option_results}->{timeout}, options => $self->{option_results},
command => $self->{option_results}->{command}, command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path}, command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} command_options => $self->{option_results}->{command_options}
); );
centreon::common::powershell::exchange::listdatabases::disco_show($self, stdout => $stdout);
my $decoded = $self->manage_selection(stdout => $stdout);
foreach my $db (@$decoded) {
$self->{output}->add_disco_entry(
name => $db->{name},
server => $db->{server},
mounted => $db->{mounted} =~ /True|1/i ? 'true' : 'false'
);
}
} }
1; 1;

View File

@ -24,11 +24,14 @@ use strict;
use warnings; use warnings;
use centreon::plugins::misc; use centreon::plugins::misc;
use centreon::common::powershell::exchange::powershell; use centreon::common::powershell::exchange::powershell;
use centreon::common::powershell::functions;
sub get_powershell { sub get_powershell {
my (%options) = @_; my (%options) = @_;
my $ps = centreon::common::powershell::exchange::powershell::powershell_init(%options); my $ps = centreon::common::powershell::exchange::powershell::powershell_init(%options);
$ps .= centreon::common::powershell::functions::escape_jsonstring(%options);
$ps .= centreon::common::powershell::functions::convert_to_json(%options);
$ps .= ' $ps .= '
# Check to make sure all databases are mounted # Check to make sure all databases are mounted
@ -51,57 +54,28 @@ try {
Write-Host $Error[0].Exception Write-Host $Error[0].Exception
exit 1 exit 1
} }
$items = New-Object System.Collections.Generic.List[Hashtable];
Foreach ($DB in $MountedDB) { Foreach ($DB in $MountedDB) {
Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "][size=" $DB.DatabaseSize "][asize=" $DB.AvailableNewMailboxSpace "]" -NoNewline $item = @{}
$item.name = $DB.Name
$item.server = $DB.Server.Name
$item.mounted = $DB.Mounted
$item.size = $DB.DatabaseSize.ToBytes().ToString()
$item.asize = $DB.AvailableNewMailboxSpace.ToBytes().ToString()
$items.Add($item)
'; ';
$ps .= ' $ps .= '
} }
$jsonString = $items | ConvertTo-JSON-20 -forceArray $true
Write-Host $jsonString
exit 0 exit 0
'; ';
return $ps; return $ps;
} }
sub list {
my ($self, %options) = @_;
# Following output:
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][size= 136.1 MB (142,671,872 bytes) ][asize= 124.4 MB (130,482,176 bytes) ][mapi= Success ][mailflow= Success ][latency= 50,00 ]
#...
foreach my $line (split /\n/, $options{stdout}) {
next if ($line !~ /^\[name=(.*?)\]\[server=(.*?)\]\[mounted=(.*?)\]\[size=(.*?)\]\[asize=(.*?)\]/);
my ($database, $server, $mounted, $size, $asize) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5));
$self->{output}->output_add(long_msg => "'" . $database . "' [server = $server, mounted = " . $mounted . ']');
}
}
sub disco_show {
my ($self, %options) = @_;
# Following output:
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][size= 136.1 MB (142,671,872 bytes) ][asize= 124.4 MB (130,482,176 bytes) ][mapi= Success ][mailflow= Success ][latency= 50,00 ]
#...
foreach my $line (split /\n/, $options{stdout}) {
next if ($line !~ /^\[name=(.*?)\]\[server=(.*?)\]\[mounted=(.*?)\]\[size=(.*?)\]\[asize=(.*?)\]/);
my ($database, $server, $mounted, $size, $asize) = (
centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5)
);
$self->{output}->add_disco_entry(
name => $database,
server => $server,
mounted => $mounted
);
}
}
1; 1;
__END__ __END__

View File

@ -35,8 +35,8 @@ my $thresholds = {
['Undefined', 'WARNING'], ['Undefined', 'WARNING'],
['Normal (Inside unused parts)', 'WARNING'], ['Normal (Inside unused parts)', 'WARNING'],
['Error', 'CRITICAL'], ['Error', 'CRITICAL'],
['Unknown', 'UNKNOWN'], ['Unknown', 'UNKNOWN']
], ]
}; };
sub new { sub new {
@ -44,20 +44,20 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'hostname:s' => { name => 'hostname' },
"hostname:s" => { name => 'hostname' }, 'ssh-option:s@' => { name => 'ssh_option' },
"ssh-option:s@" => { name => 'ssh_option' }, 'ssh-path:s' => { name => 'ssh_path' },
"ssh-path:s" => { name => 'ssh_path' }, 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, 'timeout:s' => { name => 'timeout', default => 30 },
"timeout:s" => { name => 'timeout', default => 30 }, 'command:s' => { name => 'command', default => 'show' },
"command:s" => { name => 'command', default => 'show' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => 'enclosure-status -type all' },
"command-options:s" => { name => 'command_options', default => 'enclosure-status -type all' }, 'filter:s@' => { name => 'filter' },
"filter:s@" => { name => 'filter' }, 'threshold-overload:s@' => { name => 'threshold_overload' },
"threshold-overload:s@" => { name => 'threshold_overload' }, 'no-component:s' => { name => 'no_component' }
"no-component:s" => { name => 'no_component' }, });
});
$self->{no_components} = undef; $self->{no_components} = undef;
return $self; return $self;
} }
@ -76,7 +76,7 @@ sub check_options {
my @values = split (/,/, $val); my @values = split (/,/, $val);
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
} }
$self->{overload_th} = {}; $self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) { if ($val !~ /^(.*?),(.*?),(.*)$/) {
@ -104,12 +104,14 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output}, my $stdout = centreon::plugins::misc::execute(
options => $self->{option_results}, output => $self->{output},
ssh_pipe => 1, options => $self->{option_results},
command => $self->{option_results}->{command}, ssh_pipe => 1,
command_path => $self->{option_results}->{command_path}, command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options}); command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
#Controller Enclosure #0 Information #Controller Enclosure #0 Information
#... #...
@ -149,35 +151,43 @@ sub run {
# PSU#1 [Normal / 0xE001] # PSU#1 [Normal / 0xE001]
my $total_components = 0; my $total_components = 0;
while ($stdout =~ /^(Controller|Frontend)\s+Enclosure\s+(#\d+\s+|)Status(.*?)(\n\n|\Z)/msg) { while ($stdout =~ /^(Controller|Frontend|Drive)\s+Enclosure\s+(#\d+\s+|)Status(.*?)(\n\n|\Z)/msg) {
my ($type, $num, $content) = ($1, $2, $3); my ($type, $num, $content) = ($1, $2, $3);
my $prefix = 'fe'; my $prefix = 'fe';
if ($type =~ /^C/) { if ($type =~ /controller/i) {
$prefix = 'ce' . centreon::plugins::misc::trim($num); $prefix = 'ce' . centreon::plugins::misc::trim($num);
} elsif ($type =~ /drive/i) {
$prefix = 'drive' . centreon::plugins::misc::trim($num);
} }
while ($content =~ /PSU#(\d+)\s+\[\s*(\S+)/msig) { while ($content =~ /PSU#(\d+)\s+\[\s*(\S+)/msig) {
my ($psu_number, $psu_status) = ($1, $2); my ($psu_number, $psu_status) = ($1, $2);
my $psu_name = $prefix . '_' . $psu_number; my $psu_name = $prefix . '_' . $psu_number;
next if ($self->check_filter(section => 'psu', instance => $psu_name)); next if ($self->check_filter(section => 'psu', instance => $psu_name));
$total_components++; $total_components++;
$self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is '%s'", $psu_name, $psu_status)); $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is '%s'", $psu_name, $psu_status));
my $exit = $self->get_severity(section => 'psu', value => $psu_status); my $exit = $self->get_severity(section => 'psu', value => $psu_status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(
short_msg => sprintf("Power Supply '%s' status is '%s'.", $psu_name, $psu_status)); severity => $exit,
short_msg => sprintf("Power Supply '%s' status is '%s'.", $psu_name, $psu_status)
);
} }
} }
} }
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => sprintf("All %d power supplies are ok.", $total_components)); severity => 'OK',
short_msg => sprintf("All %d power supplies are ok.", $total_components)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) { if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components}, $self->{output}->output_add(
short_msg => 'No components are checked.'); severity => $self->{no_components},
short_msg => 'No components are checked.'
);
} }
$self->{output}->display(); $self->{output}->display();