Merge pull request #592 from cgagnaire/master

Add raisecom plugin
This commit is contained in:
qgarnier 2017-08-10 16:15:19 +02:00 committed by GitHub
commit 4dabc5181b
7 changed files with 675 additions and 0 deletions

View File

@ -0,0 +1,78 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::raisecom::snmp::mode::components::fan;
use strict;
use warnings;
my %map_fan_state = (
1 => 'normal',
2 => 'abnormal',
);
my $mapping = {
raisecomFanSpeedValue => { oid => '.1.3.6.1.4.1.8886.1.1.5.2.2.1.2' },
raisecomFanWorkState => { oid => '.1.3.6.1.4.1.8886.1.1.5.2.2.1.3', map => \%map_fan_state },
};
my $oid_raisecomFanMonitorStateEntry = '.1.3.6.1.4.1.8886.1.1.5.2.2.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_raisecomFanMonitorStateEntry };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fan', total => 0, skip => 0};
return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_raisecomFanMonitorStateEntry}})) {
next if ($oid !~ /^$mapping->{raisecomFanWorkState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_raisecomFanMonitorStateEntry}, instance => $instance);
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Fan '%s' status is '%s' [instance = %s]",
$instance, $result->{raisecomFanWorkState}, $instance));
my $exit = $self->get_severity(section => 'fan', value => $result->{raisecomFanWorkState});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Fan '%s' status is '%s'", $instance, $result->{raisecomFanWorkState}));
}
my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'fan.speed', instance => $instance, value => $result->{raisecomFanSpeedValue});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2,
short_msg => sprintf("Fan speed '%s' is %s rpm", $instance, $result->{raisecomFanSpeedValue}));
$self->{output}->perfdata_add(label => 'fan_speed_' . $instance, unit => 'rpm',
value => $result->{raisecomFanSpeedValue},
warning => $warn,
critical => $crit,
);
}
}
}
1;

View File

@ -0,0 +1,83 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::raisecom::snmp::mode::components::temperature;
use strict;
use warnings;
my $mapping = {
raisecomTemperatureValue => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.1' },
raisecomTemperatureThresholdLow => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.5' },
raisecomTemperatureThresholdHigh => { oid => '.1.3.6.1.4.1.8886.1.1.4.2.6' },
};
my $oid_raisecomTemperatureEntry = '.1.3.6.1.4.1.8886.1.1.4.2';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_raisecomTemperatureEntry };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_filter(section => 'temperature'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_raisecomTemperatureEntry}})) {
next if ($oid !~ /^$mapping->{raisecomTemperatureValue}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_raisecomTemperatureEntry}, instance => $instance);
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("temperature '%s' is %.2f C [instance: %s].",
$instance, $result->{raisecomTemperatureValue}, $instance
));
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{raisecomTemperatureValue});
if ($checked == 0) {
my $warn_th = ':' . $result->{raisecomTemperatureThresholdLow};
my $crit_th = ':' . $result->{raisecomTemperatureThresholdHigh};
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
$exit = $self->{perfdata}->threshold_check(value => $result->{raisecomTemperatureValue}, threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } ]);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-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)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Temperature '%s' is %.2f C", $instance, $result->{raisecomTemperatureValue}));
}
$self->{output}->perfdata_add(label => 'temp_' . $instance, unit => 'C',
value => $result->{raisecomTemperatureValue},
warning => $warn,
critical => $crit,
);
}
}
1;

View File

@ -0,0 +1,83 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::raisecom::snmp::mode::components::voltage;
use strict;
use warnings;
my $mapping = {
raisecomVoltValue => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.3' },
raisecomVoltThresholdLow => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.7' },
raisecomVoltThresholdHigh => { oid => '.1.3.6.1.4.1.8886.1.1.4.3.1.1.8' },
};
my $oid_raisecomVoltEntry = '.1.3.6.1.4.1.8886.1.1.4.3.1.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_raisecomVoltEntry };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking voltages");
$self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0};
return if ($self->check_filter(section => 'voltage'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_raisecomVoltEntry}})) {
next if ($oid !~ /^$mapping->{raisecomVoltValue}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_raisecomVoltEntry}, instance => $instance);
next if ($self->check_filter(section => 'voltage', instance => $instance));
$self->{components}->{voltage}->{total}++;
$self->{output}->output_add(long_msg => sprintf("voltage '%s' is %.2f V [instance: %s].",
$instance, $result->{raisecomVoltValue}, $instance
));
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{raisecomVoltValue});
if ($checked == 0) {
my $warn_th = ':' . $result->{raisecomVoltThresholdLow};
my $crit_th = ':' . $result->{raisecomVoltThresholdHigh};
$self->{perfdata}->threshold_validate(label => 'warning-voltage-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-voltage-instance-' . $instance, value => $crit_th);
$exit = $self->{perfdata}->threshold_check(value => $result->{raisecomVoltValue}, threshold => [ { label => 'critical-voltage-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-voltage-instance-' . $instance, exit_litteral => 'warning' } ]);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-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)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Voltage '%s' is %.2f V", $instance, $result->{raisecomVoltValue}));
}
$self->{output}->perfdata_add(label => 'volt_' . $instance, unit => 'V',
value => $result->{raisecomVoltValue},
warning => $warn,
critical => $crit,
);
}
}
1;

View File

@ -0,0 +1,153 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::raisecom::snmp::mode::cpu;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'cpu', type => 0, cb_prefix_output => 'prefix_cpu_output' }
];
$self->{maps_counters}->{cpu} = [
{ label => '1s', set => {
key_values => [ { name => 'raisecomCPUUtilization1sec' } ],
output_template => '1 seconde : %.2f %%',
perfdatas => [
{ label => 'cpu_1s', value => 'raisecomCPUUtilization1sec_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => '5s', set => {
key_values => [ { name => 'raisecomCPUUtilization5sec' } ],
output_template => '5 secondes : %.2f %%',
perfdatas => [
{ label => 'cpu_5s', value => 'raisecomCPUUtilization5sec_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => '1m', set => {
key_values => [ { name => 'raisecomCPUUtilization1min' } ],
output_template => '1 minute : %.2f %%',
perfdatas => [
{ label => 'cpu_1m', value => 'raisecomCPUUtilization1min_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => '10m', set => {
key_values => [ { name => 'raisecomCPUUtilization10min' } ],
output_template => '10 minutes : %.2f %%',
perfdatas => [
{ label => 'cpu_10m', value => 'raisecomCPUUtilization10min_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => '2h', set => {
key_values => [ { name => 'raisecomCPUUtilization2h' } ],
output_template => '2 hours : %.2f %%',
perfdatas => [
{ label => 'cpu_2h', value => 'raisecomCPUUtilization2h_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
];
}
sub prefix_cpu_output {
my ($self, %options) = @_;
return "CPU Usage ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# RAISECOM-SYSTEM-MIB
my $oid_raisecomCPUUtilization1sec = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.1';
my $oid_raisecomCPUUtilization5sec = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.2';
my $oid_raisecomCPUUtilization1min = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.3';
my $oid_raisecomCPUUtilization10min = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.4';
my $oid_raisecomCPUUtilization2h = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3.5';
my $results = $options{snmp}->get_leef(oids => [$oid_raisecomCPUUtilization1sec, $oid_raisecomCPUUtilization5sec,
$oid_raisecomCPUUtilization1min, , $oid_raisecomCPUUtilization10min,
$oid_raisecomCPUUtilization2h ],
nothing_quit => 1);
$self->{cpu} = { raisecomCPUUtilization1sec => $results->{$oid_raisecomCPUUtilization1sec},
raisecomCPUUtilization5sec => $results->{$oid_raisecomCPUUtilization5sec},
raisecomCPUUtilization1min => $results->{$oid_raisecomCPUUtilization1min},
raisecomCPUUtilization10min => $results->{$oid_raisecomCPUUtilization10min},
raisecomCPUUtilization2h => $results->{$oid_raisecomCPUUtilization2h},
};
}
1;
__END__
=head1 MODE
Check CPU usage.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^(1s|1m)$'
=item B<--warning-*>
Threshold warning.
Can be: '1s', '5s', '1m', '10m', '2h'
=item B<--critical-*>
Threshold critical.
Can be: '1s', '5s', '1m', '10m', '2h'
=back
=cut

View File

@ -0,0 +1,110 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::raisecom::snmp::mode::hardware;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(temperature|fan|voltage)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan|voltage)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
fan => [
['abnormal', 'CRITICAL'],
['normal', 'OK'],
],
};
$self->{components_path} = 'network::raisecom::snmp::mode::components';
$self->{components_module} = ['fan', 'temperature', 'voltage'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
1;
__END__
=head1 MODE
Check hardware (temperatures, fans, voltages).
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'temperature'.
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu)
Can also exclude specific instance: --filter=fan,1
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='fan,CRITICAL,^(?!(good)$)'
=item B<--warning>
Set warning threshold for temperatures, fan speed (syntax: type,instance,threshold)
Example: --warning='temperature,.*,30'
=item B<--critical>
Set critical threshold for temperatures, fan speed (syntax: type,instance,threshold)
Example: --critical='temperature,.*,40'
=back
=cut

View File

@ -0,0 +1,116 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::raisecom::snmp::mode::memory;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $oid_raisecomAvailableMemory = '.1.3.6.1.4.1.8886.1.1.3.2.0';
my $oid_raisecomTotalMemory = '.1.3.6.1.4.1.8886.1.1.3.1.0';
my $oids = [$oid_raisecomAvailableMemory, $oid_raisecomTotalMemory];
my $result = $self->{snmp}->get_leef(oids => $oids,
nothing_quit => 1);
my $free_size = $result->{$oid_raisecomAvailableMemory};
my $total_size = $result->{$oid_raisecomTotalMemory};
my $used_size = $total_size - $free_size;
my $prct_used = $used_size * 100 / $total_size;
my $prct_free = 100 - $prct_used;
my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size);
my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $used_size);
my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $free_size);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Memory Total: %s, Used: %s (%.2f%%), Free: %s (%.2f%%)",
$total_value . " " . $total_unit,
$used_value . " " . $used_unit, $prct_used,
$free_value . " " . $free_unit, $prct_free));
$self->{output}->perfdata_add(label => "used", unit => 'B',
value => $used_size,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1),
min => 0, max => $total_size);
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check memory usage.
=over 8
=item B<--warning>
Threshold warning in percent.
=item B<--critical>
Threshold critical in percent.
=back
=cut

View File

@ -0,0 +1,52 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::raisecom::snmp::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_snmp);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'cpu' => 'network::raisecom::snmp::mode::cpu',
'memory' => 'network::raisecom::snmp::mode::memory',
'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'hardware' => 'network::raisecom::snmp::mode::hardware',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Raisecom devices through SNMP
=cut