enhance imm

This commit is contained in:
garnier-quentin 2020-12-30 14:21:52 +01:00
parent ffb1894886
commit b95ee6ca18
9 changed files with 109 additions and 53 deletions

View File

@ -40,7 +40,7 @@ sub check {
my ($self) = @_; my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking cpus"); $self->{output}->output_add(long_msg => "Checking cpus");
$self->{components}->{cpu} = {name => 'cpus', total => 0, skip => 0}; $self->{components}->{cpu} = { name => 'cpus', total => 0, skip => 0 };
return if ($self->check_filter(section => 'cpu')); return if ($self->check_filter(section => 'cpu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cpuEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cpuEntry}})) {
@ -51,12 +51,20 @@ sub check {
next if ($self->check_filter(section => 'cpu', instance => $instance)); next if ($self->check_filter(section => 'cpu', instance => $instance));
$self->{components}->{cpu}->{total}++; $self->{components}->{cpu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("CPU '%s' is '%s' [instance = %s]", $self->{output}->output_add(
$result->{cpuDescr}, $result->{cpuHealthStatus}, $instance)); long_msg => sprintf(
my $exit = $self->get_severity(section => 'health', value => $result->{cpuHealthStatus}); "cpu '%s' is '%s' [instance = %s]",
$result->{cpuDescr},
$result->{cpuHealthStatus},
$instance
)
);
my $exit = $self->get_severity(label => 'health', section => 'cpu', value => $result->{cpuHealthStatus});
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("CPU '%s' is '%s'", $result->{cpuDescr}, $result->{cpuHealthStatus})); severity => $exit,
short_msg => sprintf("CPU '%s' is '%s'", $result->{cpuDescr}, $result->{cpuHealthStatus})
);
} }
} }
} }

View File

@ -40,7 +40,7 @@ sub check {
my ($self) = @_; my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking disks"); $self->{output}->output_add(long_msg => "Checking disks");
$self->{components}->{disk} = {name => 'disks', total => 0, skip => 0}; $self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 };
return if ($self->check_filter(section => 'disk')); return if ($self->check_filter(section => 'disk'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_diskEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_diskEntry}})) {
@ -51,12 +51,20 @@ sub check {
next if ($self->check_filter(section => 'disk', instance => $instance)); next if ($self->check_filter(section => 'disk', instance => $instance));
$self->{components}->{disk}->{total}++; $self->{components}->{disk}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Disk '%s' is '%s' [instance = %s]", $self->{output}->output_add(
$result->{diskDescr}, $result->{diskHealthStatus}, $instance)); long_msg => sprintf(
my $exit = $self->get_severity(section => 'health', value => $result->{diskHealthStatus}); "disk '%s' is '%s' [instance = %s]",
$result->{diskDescr},
$result->{diskHealthStatus},
$instance
)
);
my $exit = $self->get_severity(label => 'health', section => 'disk', value => $result->{diskHealthStatus});
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("Disk '%s' is '%s'", $result->{diskDescr}, $result->{diskHealthStatus})); severity => $exit,
short_msg => sprintf("Disk '%s' is '%s'", $result->{diskDescr}, $result->{diskHealthStatus})
);
} }
} }
} }

View File

@ -41,7 +41,7 @@ sub check {
my ($self) = @_; my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking fans"); $self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 };
return if ($self->check_filter(section => 'fan')); return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanEntry}})) {
@ -54,12 +54,18 @@ sub check {
next if ($self->check_filter(section => 'fan', instance => $instance)); next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Fan '%s' speed is '%s' [instance = %s]", $self->{output}->output_add(
$result->{fanDescr}, $result->{fanSpeed}, $instance)); long_msg => sprintf(
my $exit = $self->get_severity(section => 'health', value => $result->{fanHealthStatus}); "fan '%s' speed is '%s' [instance = %s]",
$result->{fanDescr}, $result->{fanSpeed}, $instance
)
);
my $exit = $self->get_severity(label => 'health', section => 'fan', value => $result->{fanHealthStatus});
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("Fan '%s' is '%s'", $result->{fanDescr}, $result->{fanHealthStatus})); severity => $exit,
short_msg => sprintf("Fan '%s' is '%s'", $result->{fanDescr}, $result->{fanHealthStatus})
);
} }
next if ($result->{fanSpeed} !~ /(\d+)/); next if ($result->{fanSpeed} !~ /(\d+)/);
@ -67,16 +73,19 @@ sub check {
my $fan_speed = $1; my $fan_speed = $1;
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $fan_speed); my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $fan_speed);
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2, $self->{output}->output_add(
short_msg => sprintf("Fan '%s' is '%s' %%", $result->{fanDescr}, $fan_speed)); severity => $exit2,
short_msg => sprintf("Fan '%s' is '%s' %%", $result->{fanDescr}, $fan_speed)
);
} }
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => 'fan', unit => '%',
nlabel => 'hardware.fan.speed.percentage', nlabel => 'hardware.fan.speed.percentage',
instances => $result->{fanDescr}, instances => $result->{fanDescr},
value => $fan_speed, value => $fan_speed,
warning => $warn, warning => $warn,
critical => $crit, min => 0, max => 100 critical => $crit,
unit => '%',
min => 0, max => 100
); );
} }
} }

View File

@ -54,13 +54,21 @@ sub check {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{systemHealthStat}->{oid}}, instance => '0'); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{systemHealthStat}->{oid}}, instance => '0');
$self->{components}->{global}->{total}++; $self->{components}->{global}->{total}++;
$self->{output}->output_add(long_msg => sprintf("system health status is '%s'", $self->{output}->output_add(
$result->{systemHealthStat})); long_msg => sprintf(
"system health status is '%s'",
$result->{systemHealthStat}
)
);
my $exit = $self->get_severity(section => 'global', value => $result->{systemHealthStat}); my $exit = $self->get_severity(section => 'global', value => $result->{systemHealthStat});
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("System health status is '%s'.", severity => $exit,
$result->{systemHealthStat})); short_msg => sprintf(
"System health status is '%s'.",
$result->{systemHealthStat}
)
);
} }
} }

View File

@ -40,7 +40,7 @@ sub check {
my ($self) = @_; my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking memorys"); $self->{output}->output_add(long_msg => "Checking memorys");
$self->{components}->{memory} = {name => 'memorys', total => 0, skip => 0}; $self->{components}->{memory} = { name => 'memorys', total => 0, skip => 0 };
return if ($self->check_filter(section => 'memory')); return if ($self->check_filter(section => 'memory'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_memoryEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_memoryEntry}})) {
@ -51,12 +51,18 @@ sub check {
next if ($self->check_filter(section => 'memory', instance => $instance)); next if ($self->check_filter(section => 'memory', instance => $instance));
$self->{components}->{memory}->{total}++; $self->{components}->{memory}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Memory '%s' is '%s' [instance = %s]", $self->{output}->output_add(
$result->{memoryDescr}, $result->{memoryHealthStatus}, $instance)); long_msg => sprintf(
my $exit = $self->get_severity(section => 'health', value => $result->{memoryHealthStatus}); "memory '%s' is '%s' [instance = %s]",
$result->{memoryDescr}, $result->{memoryHealthStatus}, $instance
)
);
my $exit = $self->get_severity(label => 'health', section => 'memory', value => $result->{memoryHealthStatus});
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("Memory '%s' is '%s'", $result->{memoryDescr}, $result->{memoryHealthStatus})); severity => $exit,
short_msg => sprintf("Memory '%s' is '%s'", $result->{memoryDescr}, $result->{memoryHealthStatus})
);
} }
} }
} }

View File

@ -40,7 +40,7 @@ sub check {
my ($self) = @_; my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking powers"); $self->{output}->output_add(long_msg => "Checking powers");
$self->{components}->{power} = {name => 'powers', total => 0, skip => 0}; $self->{components}->{power} = { name => 'powers', total => 0, skip => 0 };
return if ($self->check_filter(section => 'power')); return if ($self->check_filter(section => 'power'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerEntry}})) {
@ -51,12 +51,18 @@ sub check {
next if ($self->check_filter(section => 'power', instance => $instance)); next if ($self->check_filter(section => 'power', instance => $instance));
$self->{components}->{power}->{total}++; $self->{components}->{power}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Power '%s' is '%s' [instance = %s]", $self->{output}->output_add(
$result->{powerDescr}, $result->{powerHealthStatus}, $instance)); long_msg => sprintf(
my $exit = $self->get_severity(section => 'health', value => $result->{powerHealthStatus}); "power '%s' is '%s' [instance = %s]",
$result->{powerDescr}, $result->{powerHealthStatus}, $instance
)
);
my $exit = $self->get_severity(label => 'health', section => 'power', value => $result->{powerHealthStatus});
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 '%s' is '%s'", $result->{powerDescr}, $result->{powerHealthStatus})); severity => $exit,
short_msg => sprintf("Power '%s' is '%s'", $result->{powerDescr}, $result->{powerHealthStatus})
);
} }
} }
} }

View File

@ -56,8 +56,12 @@ sub check {
$result->{tempDescr} = centreon::plugins::misc::trim($result->{tempDescr}); $result->{tempDescr} = centreon::plugins::misc::trim($result->{tempDescr});
$self->{components}->{temperature}->{total}++; $self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("temperature '%s' value is %s C [instance: %s].", $self->{output}->output_add(
$result->{tempDescr}, $result->{tempReading}, $instance)); long_msg => sprintf(
"temperature '%s' value is %s C [instance: %s].",
$result->{tempDescr}, $result->{tempReading}, $instance
)
);
if (defined($result->{tempReading})) { if (defined($result->{tempReading})) {
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{tempReading}); my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{tempReading});
@ -75,11 +79,13 @@ sub check {
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
} }
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("Temperature '%s' is %s C", $result->{tempDescr}, $result->{tempReading})); severity => $exit,
short_msg => sprintf("Temperature '%s' is %s C", $result->{tempDescr}, $result->{tempReading})
);
} }
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => "temp", unit => 'C', unit => 'C',
nlabel => 'hardware.temperature.celsius', nlabel => 'hardware.temperature.celsius',
instances => $result->{tempDescr}, instances => $result->{tempDescr},
value => $result->{tempReading}, value => $result->{tempReading},

View File

@ -56,8 +56,12 @@ sub check {
$result->{voltDescr} = centreon::plugins::misc::trim($result->{voltDescr}); $result->{voltDescr} = centreon::plugins::misc::trim($result->{voltDescr});
$self->{components}->{voltage}->{total}++; $self->{components}->{voltage}->{total}++;
$self->{output}->output_add(long_msg => sprintf("voltage '%s' value is %s [instance: %s].", $self->{output}->output_add(
$result->{voltDescr}, $result->{voltReading}, $instance)); long_msg => sprintf(
"voltage '%s' value is %s [instance: %s].",
$result->{voltDescr}, $result->{voltReading}, $instance
)
);
if (defined($result->{voltReading})) { if (defined($result->{voltReading})) {
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{voltReading}); my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{voltReading});
@ -75,11 +79,12 @@ sub check {
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-voltage-instance-' . $instance); $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-voltage-instance-' . $instance);
} }
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("Voltage '%s' is %s", $result->{voltDescr}, $result->{voltReading})); severity => $exit,
short_msg => sprintf("Voltage '%s' is %s", $result->{voltDescr}, $result->{voltReading})
);
} }
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => "volt",
nlabel => 'hardware.voltage.volt', nlabel => 'hardware.voltage.volt',
instances => $result->{voltDescr}, instances => $result->{voltDescr},
value => $result->{voltReading}, value => $result->{voltReading},

View File

@ -28,7 +28,7 @@ use warnings;
sub set_system { sub set_system {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{regexp_threshold_numeric_check_section_option} = '^(fan|temperature|voltage)$'; $self->{regexp_threshold_numeric_check_section_option} = '^(?:fan|temperature|voltage)$';
$self->{cb_hook2} = 'snmp_execute'; $self->{cb_hook2} = 'snmp_execute';
@ -59,7 +59,7 @@ sub snmp_execute {
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => {}); $options{options}->add_options(arguments => {});