break(moxa): add new counters + manage eds405a (#3307)

This commit is contained in:
qgarnier 2021-12-08 11:25:30 +01:00 committed by GitHub
parent cc1678389a
commit 995134b65b
2 changed files with 142 additions and 138 deletions

View File

@ -25,101 +25,101 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub prefix_cpu_output {
my ($self, %options) = @_;
return 'cpu average usage: ';
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'cpu', type => 0, cb_prefix_output => 'prefix_cpu_output' } { name => 'global', type => 0, cb_prefix_output => 'prefix_cpu_output' }
]; ];
$self->{maps_counters}->{cpu} = [ $self->{maps_counters}->{global} = [
{ label => '5s', set => { { label => 'cpu-utilization-5s', nlabel => 'cpu.utilization.5s.percentage', set => {
key_values => [ { name => 'cpuLoading5s' } ], key_values => [ { name => 'cpu_load5s' } ],
output_template => '5 seconds : %.2f %%', output_template => '%.2f %% (5s)',
perfdatas => [ perfdatas => [
{ label => 'cpu_5s', value => 'cpuLoading5s', template => '%.2f', { template => '%.2f', unit => '%', min => 0, max => 100 }
min => 0, max => 100, unit => '%' }, ]
],
} }
}, },
{ label => '30s', set => { { label => 'cpu-utilization-1m', nlabel => 'cpu.utilization.1m.percentage', set => {
key_values => [ { name => 'cpuLoading30s' } ], key_values => [ { name => 'cpu_load1m' } ],
output_template => '30 seconds : %.2f %%', output_template => '%.2f %% (1m)',
perfdatas => [ perfdatas => [
{ label => 'cpu_30s', value => 'cpuLoading30s', template => '%.2f', { template => '%.2f', unit => '%', min => 0, max => 100 }
min => 0, max => 100, unit => '%' }, ]
],
} }
}, },
{ label => '300s', set => { { label => 'cpu-utilization-5m', nlabel => 'cpu.utilization.5m.percentage', set => {
key_values => [ { name => 'cpuLoading300s' } ], key_values => [ { name => 'cpu_load5m' } ],
output_template => '300 seconds : %.2f %%', output_template => '%.2f %% (5m)',
perfdatas => [ perfdatas => [
{ label => 'cpu_300s', value => 'cpuLoading300s', template => '%.2f', { template => '%.2f', unit => '%', min => 0, max => 100 }
min => 0, max => 100, unit => '%' }, ]
],
} }
}, }
]; ];
} }
sub prefix_cpu_output {
my ($self, %options) = @_;
return "CPU Usage ";
}
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;
} }
my $mappings = { my $mapping = {
iks6726a => { iks6726a => {
cpuLoading5s => { oid => '.1.3.6.1.4.1.8691.7.116.1.53' }, cpu_load5s => { oid => '.1.3.6.1.4.1.8691.7.116.1.53' },
cpuLoading30s => { oid => '.1.3.6.1.4.1.8691.7.116.1.54' }, cpu_load1m => { oid => '.1.3.6.1.4.1.8691.7.116.1.54' },
cpuLoading300s => { oid => '.1.3.6.1.4.1.8691.7.116.1.55' }, cpu_load5m => { oid => '.1.3.6.1.4.1.8691.7.116.1.55' }
},
eds405a => {
cpu_load5s => { oid => '.1.3.6.1.4.1.8691.7.6.1.53' },
cpu_load1m => { oid => '.1.3.6.1.4.1.8691.7.6.1.54' },
cpu_load5m => { oid => '.1.3.6.1.4.1.8691.7.6.1.55' }
}, },
edsp506e => { edsp506e => {
cpuLoading5s => { oid => '.1.3.6.1.4.1.8691.7.162.1.53' }, cpu_load5s => { oid => '.1.3.6.1.4.1.8691.7.162.1.53' },
cpuLoading30s => { oid => '.1.3.6.1.4.1.8691.7.162.1.54' }, cpu_load1m => { oid => '.1.3.6.1.4.1.8691.7.162.1.54' },
cpuLoading300s => { oid => '.1.3.6.1.4.1.8691.7.162.1.55' }, cpu_load5m => { oid => '.1.3.6.1.4.1.8691.7.162.1.55' }
}, },
edsp506a => { edsp506a => {
cpuLoading5s => { oid => '.1.3.6.1.4.1.8691.7.41.1.53' }, cpu_load5s => { oid => '.1.3.6.1.4.1.8691.7.41.1.53' },
cpuLoading30s => { oid => '.1.3.6.1.4.1.8691.7.41.1.54' }, cpu_load1m => { oid => '.1.3.6.1.4.1.8691.7.41.1.54' },
cpuLoading300s => { oid => '.1.3.6.1.4.1.8691.7.41.1.55' }, cpu_load5m => { oid => '.1.3.6.1.4.1.8691.7.41.1.55' }
}, }
};
my $oids = {
iks6726a => '.1.3.6.1.4.1.8691.7.116.1',
edsp506e => '.1.3.6.1.4.1.8691.7.162.1',
edsp506a => '.1.3.6.1.4.1.8691.7.41.1',
}; };
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $oids->{iks6726a}, start => $mappings->{iks6726a}->{cpuLoading5s}->{oid}, end => $mappings->{iks6726a}->{cpuLoading300s}->{oid} },
{ oid => $oids->{edsp506e}, start => $mappings->{edsp506e}->{cpuLoading5s}->{oid}, end => $mappings->{edsp506e}->{cpuLoading300s}->{oid} },
{ oid => $oids->{edsp506a}, start => $mappings->{edsp506a}->{cpuLoading5s}->{oid}, end => $mappings->{edsp506a}->{cpuLoading300s}->{oid} } ]);
foreach my $equipment (keys %{$oids}) { my $snmp_result = $options{snmp}->get_leef(
next if (!%{$snmp_result->{$oids->{$equipment}}}); oids => [
my $result = $options{snmp}->map_instance(mapping => $mappings->{$equipment}, results => $snmp_result->{$oids->{$equipment}}, instance => 0); map(
$self->{cpu} = { $_->{oid} . '.0',
cpuLoading5s => $result->{cpuLoading5s}, values(%{$mapping->{iks6726a}}),
cpuLoading30s => $result->{cpuLoading30s}, values(%{$mapping->{eds405a}}),
cpuLoading300s => $result->{cpuLoading300s}, values(%{$mapping->{edsp506e}}),
}; values(%{$mapping->{edsp506a}})
)
],
nothing_quit => 1
);
foreach (keys %$mapping) {
my $result = $options{snmp}->map_instance(mapping => $mapping->{$_}, results => $snmp_result, instance => 0);
next if (!defined($result->{cpu_load5m}));
$self->{global} = $result;
last;
} }
} }
@ -136,17 +136,12 @@ Check CPU usage
=item B<--filter-counters> =item B<--filter-counters>
Only display some counters (regexp can be used). Only display some counters (regexp can be used).
Example: --filter-counters='^(30s|300s)$' Example: --filter-counters='1m|5m'
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: '5s', '30s', '300s' Can be: 'cpu-utilization-1s', 'cpu-utilization-1m', 'cpu-utilization-5m'.
=item B<--critical-*>
Threshold critical.
Can be: '5s', '30s', '300s'
=back =back

View File

@ -25,94 +25,111 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub custom_usage_output { sub custom_memory_usage_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
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});
return sprintf(
my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", "memory usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used}); $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
return $msg; );
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'memory', type => 0 }, { name => 'global', type => 0, skipped_code => { -10 => 1 } }
]; ];
$self->{maps_counters}->{memory} = [ $self->{maps_counters}->{global} = [
{ label => 'usage', set => { { label => 'memory-usage', nlabel => 'memory.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'total' }, { name => 'prct_used' } ], key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_usage_output'), closure_custom_output => $self->can('custom_memory_usage_output'),
threshold_use => 'prct_used',
perfdatas => [ perfdatas => [
{ label => 'used', value => 'used', template => '%.2f', { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
threshold_total => 'total', cast_int => 1, ]
min => 0, max => 'total', unit => 'B' },
],
} }
}, },
{ label => 'memory-usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_memory_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
]
}
},
{ label => 'memory-usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => {
key_values => [ { name => 'prct_used' }, { name => 'free' }, { name => 'used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_memory_usage_output'),
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
}
]; ];
} }
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;
} }
my $mappings = { my $mapping = {
iks6726a => { iks6726a => {
totalMemory => { oid => '.1.3.6.1.4.1.8691.7.116.1.56' }, total => { oid => '.1.3.6.1.4.1.8691.7.116.1.56' },
freeMemory => { oid => '.1.3.6.1.4.1.8691.7.116.1.57' }, free => { oid => '.1.3.6.1.4.1.8691.7.116.1.57' },
usedMemory => { oid => '.1.3.6.1.4.1.8691.7.116.1.58' }, used => { oid => '.1.3.6.1.4.1.8691.7.116.1.58' }
},
eds405a => {
total => { oid => '.1.3.6.1.4.1.8691.7.6.1.56' },
free => { oid => '.1.3.6.1.4.1.8691.7.6.1.57' },
used => { oid => '.1.3.6.1.4.1.8691.7.6.1.58' }
}, },
edsp506e => { edsp506e => {
totalMemory => { oid => '.1.3.6.1.4.1.8691.7.162.1.56' }, total => { oid => '.1.3.6.1.4.1.8691.7.162.1.56' },
freeMemory => { oid => '.1.3.6.1.4.1.8691.7.162.1.57' }, free => { oid => '.1.3.6.1.4.1.8691.7.162.1.57' },
usedMemory => { oid => '.1.3.6.1.4.1.8691.7.162.1.58' }, used => { oid => '.1.3.6.1.4.1.8691.7.162.1.58' }
}, },
edsp506a => { edsp506a => {
totalMemory => { oid => '.1.3.6.1.4.1.8691.7.41.1.56' }, total => { oid => '.1.3.6.1.4.1.8691.7.41.1.56' },
freeMemory => { oid => '.1.3.6.1.4.1.8691.7.41.1.57' }, free => { oid => '.1.3.6.1.4.1.8691.7.41.1.57' },
usedMemory => { oid => '.1.3.6.1.4.1.8691.7.41.1.58' }, used => { oid => '.1.3.6.1.4.1.8691.7.41.1.58' }
}, }
};
my $oids = {
iks6726a => '.1.3.6.1.4.1.8691.7.116.1',
edsp506e => '.1.3.6.1.4.1.8691.7.162.1',
edsp506a => '.1.3.6.1.4.1.8691.7.41.1',
}; };
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $oids->{iks6726a}, start => $mappings->{iks6726a}->{totalMemory}->{oid}, end => $mappings->{iks6726a}->{usedMemory}->{oid} }, my $snmp_result = $options{snmp}->get_leef(
{ oid => $oids->{edsp506e}, start => $mappings->{edsp506e}->{totalMemory}->{oid}, end => $mappings->{edsp506e}->{usedMemory}->{oid} }, oids => [
{ oid => $oids->{edsp506a}, start => $mappings->{edsp506a}->{totalMemory}->{oid}, end => $mappings->{edsp506a}->{usedMemory}->{oid} } ]); map(
$_->{oid} . '.0',
values(%{$mapping->{iks6726a}}),
values(%{$mapping->{eds405a}}),
values(%{$mapping->{edsp506e}}),
values(%{$mapping->{edsp506a}})
)
],
nothing_quit => 1
);
foreach my $equipment (keys %{$oids}) { foreach (keys %$mapping) {
next if (!%{$snmp_result->{$oids->{$equipment}}}); my $result = $options{snmp}->map_instance(mapping => $mapping->{$_}, results => $snmp_result, instance => 0);
my $result = $options{snmp}->map_instance(mapping => $mappings->{$equipment}, results => $snmp_result->{$oids->{$equipment}}, instance => 0); next if (!defined($result->{total}));
$self->{memory} = { $self->{global} = $result;
used => $result->{usedMemory}, $self->{global}->{prct_used} = $result->{used} * 100 / $result->{total};
free => $result->{freeMemory}, $self->{global}->{prct_free} = $result->{free} * 100 / $result->{total};
total => $result->{totalMemory}, last;
prct_used => $result->{usedMemory} * 100 / $result->{totalMemory},
};
} }
} }
@ -126,18 +143,10 @@ Check memory usage
=over 8 =over 8
=item B<--filter-counters> =item B<--warning-*> B<--critical-*>
Only display some counters (regexp can be used). Thresholds.
Example: --filter-counters='^(memory)$' Can be: 'memory-usage-prct', 'memory-usage', 'memory-usage-free',
=item B<--warning-usage>
Threshold warning.
=item B<--critical-usage>
Threshold critical.
=back =back