enh(broadcom/fastpath): new metric labels (#3041)

This commit is contained in:
qgarnier 2021-08-12 09:02:32 +02:00 committed by GitHub
parent cab1094136
commit d14888a0f9
6 changed files with 102 additions and 80 deletions

View File

@ -30,7 +30,7 @@ my %map_fan_status = (
my $mapping = { my $mapping = {
boxServicesFanItemState => { oid => '.1.3.6.1.4.1.4413.1.1.43.1.6.1.3', map => \%map_fan_status }, boxServicesFanItemState => { oid => '.1.3.6.1.4.1.4413.1.1.43.1.6.1.3', map => \%map_fan_status },
boxServicesFanSpeed => { oid => '.1.3.6.1.4.1.4413.1.1.43.1.6.1.4' }, boxServicesFanSpeed => { oid => '.1.3.6.1.4.1.4413.1.1.43.1.6.1.4' }
}; };
my $oid_boxServicesFansEntry = '.1.3.6.1.4.1.4413.1.1.43.1.6.1'; my $oid_boxServicesFansEntry = '.1.3.6.1.4.1.4413.1.1.43.1.6.1';
@ -52,7 +52,7 @@ sub check {
next if ($oid !~ /^$mapping->{boxServicesFanItemState}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{boxServicesFanItemState}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_boxServicesFansEntry}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_boxServicesFansEntry}, instance => $instance);
next if ($self->check_filter(section => 'fan', instance => $instance)); next if ($self->check_filter(section => 'fan', instance => $instance));
if ($result->{boxServicesFanItemState} =~ /notpresent/i) { if ($result->{boxServicesFanItemState} =~ /notpresent/i) {
$self->absent_problem(section => 'fan', instance => $instance); $self->absent_problem(section => 'fan', instance => $instance);
@ -60,24 +60,32 @@ sub check {
} }
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("fan '%s' status is '%s' [instance = %s, speed = %s]", $self->{output}->output_add(
$instance, $result->{boxServicesFanItemState}, $instance, defined($result->{boxServicesFanSpeed}) ? $result->{boxServicesFanSpeed} : 'unknown')); long_msg => sprintf(
"fan '%s' status is '%s' [instance = %s, speed = %s]",
$instance, $result->{boxServicesFanItemState}, $instance, defined($result->{boxServicesFanSpeed}) ? $result->{boxServicesFanSpeed} : 'unknown'
)
);
$exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{boxServicesFanItemState}); $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{boxServicesFanItemState});
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' status is '%s'", $instance, $result->{boxServicesFanItemState})); severity => $exit,
short_msg => sprintf("Fan '%s' status is '%s'", $instance, $result->{boxServicesFanItemState})
);
} }
next if (!defined($result->{boxServicesFanSpeed}) || $result->{boxServicesFanSpeed} !~ /[0-9]+/); next if (!defined($result->{boxServicesFanSpeed}) || $result->{boxServicesFanSpeed} !~ /[0-9]+/);
($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{boxServicesFanSpeed}); ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{boxServicesFanSpeed});
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' rpm", $instance, $result->{boxServicesFanSpeed})); severity => $exit,
short_msg => sprintf("Fan '%s' is '%s' rpm", $instance, $result->{boxServicesFanSpeed})
);
} }
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => 'fan', unit => 'rpm',
nlabel => 'hardware.fan.speed.rpm', nlabel => 'hardware.fan.speed.rpm',
unit => 'rpm',
instances => $instance, instances => $instance,
value => $result->{boxServicesFanSpeed}, value => $result->{boxServicesFanSpeed},
warning => $warn, warning => $warn,

View File

@ -50,7 +50,7 @@ sub check {
next if ($oid !~ /^$mapping->{boxServicesPowSupplyItemState}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{boxServicesPowSupplyItemState}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{boxServicesPowSupplyItemState}->{oid}}, instance => $instance); my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{boxServicesPowSupplyItemState}->{oid}}, instance => $instance);
next if ($self->check_filter(section => 'psu', instance => $instance)); next if ($self->check_filter(section => 'psu', instance => $instance));
if ($result->{boxServicesPowSupplyItemState} =~ /notpresent/i) { if ($result->{boxServicesPowSupplyItemState} =~ /notpresent/i) {
$self->absent_problem(section => 'psu', instance => $instance); $self->absent_problem(section => 'psu', instance => $instance);
@ -58,12 +58,18 @@ sub check {
} }
$self->{components}->{psu}->{total}++; $self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s]", $self->{output}->output_add(
$instance, $result->{boxServicesPowSupplyItemState}, $instance)); long_msg => sprintf(
"power supply '%s' status is '%s' [instance = %s]",
$instance, $result->{boxServicesPowSupplyItemState}, $instance
)
);
$exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{boxServicesPowSupplyItemState}); $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{boxServicesPowSupplyItemState});
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'", $instance, $result->{boxServicesPowSupplyItemState})); severity => $exit,
short_msg => sprintf("Power supply '%s' status is '%s'", $instance, $result->{boxServicesPowSupplyItemState})
);
} }
} }
} }

View File

@ -25,18 +25,18 @@ use warnings;
my %map_temp_status = ( my %map_temp_status = (
0 => 'low', 1 => 'normal', 2 => 'warning', 3 => 'critical', 0 => 'low', 1 => 'normal', 2 => 'warning', 3 => 'critical',
4 => 'shutdown', 5 => 'notpresent', 6 => 'notoperational', 4 => 'shutdown', 5 => 'notpresent', 6 => 'notoperational'
); );
my $mapping = { my $mapping = {
boxServicesTempSensorState => { oid => '.1.3.6.1.4.1.4413.1.1.43.1.8.1.4', map => \%map_temp_status }, boxServicesTempSensorState => { oid => '.1.3.6.1.4.1.4413.1.1.43.1.8.1.4', map => \%map_temp_status },
boxServicesTempSensorTemperature => { oid => '.1.3.6.1.4.1.4413.1.1.43.1.8.1.5' }, boxServicesTempSensorTemperature => { oid => '.1.3.6.1.4.1.4413.1.1.43.1.8.1.5' }
}; };
my $oid_boxServicesTempSensorsEntry = '.1.3.6.1.4.1.4413.1.1.43.1.8.1'; my $oid_boxServicesTempSensorsEntry = '.1.3.6.1.4.1.4413.1.1.43.1.8.1';
sub load { sub load {
my ($self) = @_; my ($self) = @_;
push @{$self->{request}}, { oid => $oid_boxServicesTempSensorsEntry, begin => $mapping->{boxServicesTempSensorState}->{oid}, end => $mapping->{boxServicesTempSensorTemperature}->{oid} }; push @{$self->{request}}, { oid => $oid_boxServicesTempSensorsEntry, begin => $mapping->{boxServicesTempSensorState}->{oid}, end => $mapping->{boxServicesTempSensorTemperature}->{oid} };
} }
@ -60,28 +60,36 @@ sub check {
} }
$self->{components}->{temperature}->{total}++; $self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s, temperature = %s]", $self->{output}->output_add(
$instance, $result->{boxServicesTempSensorState}, $instance, defined($result->{boxServicesTempSensorTemperature}) ? $result->{boxServicesTempSensorTemperature} : 'unknown')); long_msg => sprintf(
"temperature '%s' status is '%s' [instance = %s, temperature = %s]",
$instance, $result->{boxServicesTempSensorState}, $instance, defined($result->{boxServicesTempSensorTemperature}) ? $result->{boxServicesTempSensorTemperature} : 'unknown'
)
);
$exit = $self->get_severity(section => 'temperature', value => $result->{boxServicesTempSensorState}); $exit = $self->get_severity(section => 'temperature', value => $result->{boxServicesTempSensorState});
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' status is '%s'", $instance, $result->{boxServicesTempSensorState})); severity => $exit,
short_msg => sprintf("Temperature '%s' status is '%s'", $instance, $result->{boxServicesTempSensorState})
);
} }
next if (!defined($result->{boxServicesTempSensorTemperature}) || $result->{boxServicesTempSensorTemperature} !~ /[0-9]+/); next if (!defined($result->{boxServicesTempSensorTemperature}) || $result->{boxServicesTempSensorTemperature} !~ /[0-9]+/);
($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{boxServicesTempSensorTemperature}); ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{boxServicesTempSensorTemperature});
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' rpm", $instance, $result->{boxServicesTempSensorTemperature})); severity => $exit,
short_msg => sprintf("Temperature '%s' is '%s' rpm", $instance, $result->{boxServicesTempSensorTemperature})
);
} }
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => 'temp', unit => 'C',
nlabel => 'hardware.temperature.celsius', nlabel => 'hardware.temperature.celsius',
unit => 'C',
instances => $instance, instances => $instance,
value => $result->{boxServicesTempSensorTemperature}, value => $result->{boxServicesTempSensorTemperature},
warning => $warn, warning => $warn,
critical => $crit, critical => $crit
); );
} }
} }

View File

@ -25,6 +25,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub prefix_cpu_output {
my ($self, %options) = @_;
return 'CPU ';
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -33,50 +39,39 @@ sub set_counters {
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => '5s', set => { { label => '5s', nlabel => 'cpu.utilization.5s.percentage', set => {
key_values => [ { name => 'usage_5s' } ], key_values => [ { name => 'usage_5s' } ],
output_template => '%.2f %% (5sec)', output_error_template => "%s (5sec)", output_template => '%.2f %% (5sec)', output_error_template => "%s (5sec)",
perfdatas => [ perfdatas => [
{ label => 'cpu_5s', value => 'usage_5s', template => '%.2f', { template => '%.2f', unit => '%', min => 0, max => 100 }
unit => '%', min => 0, max => 100 }, ]
],
} }
}, },
{ label => '1m', set => { { label => '1m', nlabel => 'cpu.utilization.1m.percentage', set => {
key_values => [ { name => 'usage_1m' } ], key_values => [ { name => 'usage_1m' } ],
output_template => '%.2f %% (1m)', output_error_template => "%s (1min)", output_template => '%.2f %% (1m)', output_error_template => "%s (1min)",
perfdatas => [ perfdatas => [
{ label => 'cpu_1m', value => 'usage_1m', template => '%.2f', { template => '%.2f', unit => '%', min => 0, max => 100 }
unit => '%', min => 0, max => 100 }, ]
],
} }
}, },
{ label => '5m', set => { { label => '5m', nlabel => 'cpu.utilization.5m.percentage', set => {
key_values => [ { name => 'usage_5m' } ], key_values => [ { name => 'usage_5m' } ],
output_template => '%.2f %% (5min)', output_error_template => "%s (5min)", output_template => '%.2f %% (5min)', output_error_template => "%s (5min)",
perfdatas => [ perfdatas => [
{ label => 'cpu_5m', value => 'usage_5m', template => '%.2f', { template => '%.2f', unit => '%', min => 0, max => 100 }
unit => '%', min => 0, max => 100 }, ]
],
} }
}, }
]; ];
} }
sub prefix_cpu_output {
my ($self, %options) = @_;
return "CPU ";
}
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 => {});
{
});
return $self; return $self;
} }

View File

@ -40,7 +40,7 @@ sub set_system {
['notpowering', 'WARNING'], ['notpowering', 'WARNING'],
['powering', 'OK'], ['powering', 'OK'],
['nopower', 'OK'], ['nopower', 'OK'],
['incompatible', 'WARNING'], ['incompatible', 'WARNING']
], ],
temperature => [ temperature => [
['low', 'OK'], ['low', 'OK'],
@ -49,8 +49,8 @@ sub set_system {
['critical', 'CRITICAL'], ['critical', 'CRITICAL'],
['notpresent', 'OK'], ['notpresent', 'OK'],
['shutdown', 'OK'], ['shutdown', 'OK'],
['notoperational', 'WARNING'], ['notoperational', 'WARNING']
], ]
}; };
$self->{components_path} = 'centreon::common::broadcom::fastpath::snmp::mode::components'; $self->{components_path} = 'centreon::common::broadcom::fastpath::snmp::mode::components';
@ -66,12 +66,12 @@ 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 => {
}); });
return $self; return $self;
} }

View File

@ -28,17 +28,23 @@ use warnings;
sub custom_usage_perfdata { sub custom_usage_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{output}->perfdata_add(label => 'used', unit => 'B', $self->{output}->perfdata_add(
value => $self->{result_values}->{used}, nlabel => 'memory.usage.bytes',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), unit => 'B',
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), value => $self->{result_values}->{used},
min => 0, max => $self->{result_values}->{total}); warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total}
);
} }
sub custom_usage_threshold { sub custom_usage_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); my $exit = $self->{perfdata}->threshold_check(
value => $self->{result_values}->{prct_used},
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]
);
return $exit; return $exit;
} }
@ -49,11 +55,12 @@ sub custom_usage_output {
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", return sprintf(
$total_size_value . " " . $total_size_unit, "Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_size_value . " " . $total_size_unit,
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
return $msg; $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
);
} }
sub custom_usage_calc { sub custom_usage_calc {
@ -65,7 +72,7 @@ sub custom_usage_calc {
$self->{result_values}->{used} = int($self->{result_values}->{prct_used} * $self->{result_values}->{total} / 100); $self->{result_values}->{used} = int($self->{result_values}->{prct_used} * $self->{result_values}->{total} / 100);
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
return 0; return 0;
} }
@ -82,21 +89,19 @@ sub set_counters {
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'), closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'), closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'), closure_custom_threshold_check => $self->can('custom_usage_threshold')
} }
}, }
]; ];
} }
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 =>{ });
{
});
return $self; return $self;
} }
@ -110,7 +115,7 @@ sub manage_selection {
my $total = $snmp_result->{$oid_agentSwitchCpuProcessMemAvailable} * 1024; my $total = $snmp_result->{$oid_agentSwitchCpuProcessMemAvailable} * 1024;
$self->{memory} = { $self->{memory} = {
prct_used => ($total - $snmp_result->{$oid_agentSwitchCpuProcessMemFree} * 1024) * 100 / $total, prct_used => ($total - $snmp_result->{$oid_agentSwitchCpuProcessMemFree} * 1024) * 100 / $total,
total => $total, total => $total
}; };
} }