diff --git a/hardware/ups/mge/mode/alarms.pm b/hardware/ups/mge/mode/alarms.pm new file mode 100644 index 000000000..272ce46ad --- /dev/null +++ b/hardware/ups/mge/mode/alarms.pm @@ -0,0 +1,214 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package hardware::ups::powerware::mode::alarms; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::plugins::statefile; + +my %alarm_type_map = ( + '.1.3.6.1.4.1.534.1.7.3' => 'OnBattery', + '.1.3.6.1.4.1.534.1.7.4' => 'LowBattery', + '.1.3.6.1.4.1.534.1.7.5' => 'UtilityPowerRestored', + '.1.3.6.1.4.1.534.1.7.6' => 'ReturnFromLowBattery', + '.1.3.6.1.4.1.534.1.7.7' => 'OutputOverload', + '.1.3.6.1.4.1.534.1.7.8' => 'InternalFailure', + '.1.3.6.1.4.1.534.1.7.9' => 'BatteryDischarged', + '.1.3.6.1.4.1.534.1.7.10' => 'InverterFailure', + '.1.3.6.1.4.1.534.1.7.11' => 'OnBypass', + '.1.3.6.1.4.1.534.1.7.12' => 'BypassNotAvailable', + '.1.3.6.1.4.1.534.1.7.13' => 'OutputOff', + '.1.3.6.1.4.1.534.1.7.14' => 'InputFailure', + '.1.3.6.1.4.1.534.1.7.15' => 'BuildingAlarm', + '.1.3.6.1.4.1.534.1.7.16' => 'ShutdownImminent', + '.1.3.6.1.4.1.534.1.7.17' => 'OnInverter', + '.1.3.6.1.4.1.534.1.7.20' => 'BreakerOpen', + '.1.3.6.1.4.1.534.1.7.21' => 'AlarmEntryAdded', + '.1.3.6.1.4.1.534.1.7.22' => 'AlarmEntryRemoved', + '.1.3.6.1.4.1.534.1.7.23' => 'AlarmBatteryBad', + '.1.3.6.1.4.1.534.1.7.24' => 'OutputOffAsRequested', + '.1.3.6.1.4.1.534.1.7.25' => 'DiagnosticTestFailed', + '.1.3.6.1.4.1.534.1.7.26' => 'CommunicationsLost', + '.1.3.6.1.4.1.534.1.7.27' => 'UpsShutdownPending', + '.1.3.6.1.4.1.534.1.7.28' => 'AlarmTestInProgress', + '.1.3.6.1.4.1.534.1.7.29' => 'AmbientTempBad', + '.1.3.6.1.4.1.534.1.7.30' => 'LossOfRedundancy', + '.1.3.6.1.4.1.534.1.7.31' => 'AlarmTempBad', + '.1.3.6.1.4.1.534.1.7.32' => 'AlarmChargerFailed', + '.1.3.6.1.4.1.534.1.7.33' => 'AlarmFanFailure', + '.1.3.6.1.4.1.534.1.7.34' => 'AlarmFuseFailure', + '.1.3.6.1.4.1.534.1.7.35' => 'PowerSwitchBad', + '.1.3.6.1.4.1.534.1.7.36' => 'ModuleFailure', + '.1.3.6.1.4.1.534.1.7.37' => 'OnAlternatePowerSource', + '.1.3.6.1.4.1.534.1.7.38' => 'AltPowerNotAvailable', + '.1.3.6.1.4.1.534.1.7.39' => 'NoticeCondition', + '.1.3.6.1.4.1.534.1.7.40' => 'RemoteTempBad', + '.1.3.6.1.4.1.534.1.7.41' => 'RemoteHumidityBad', + '.1.3.6.1.4.1.534.1.7.42' => 'AlarmOutputBad', + '.1.3.6.1.4.1.534.1.7.43' => 'AlarmAwaitingPower', + '.1.3.6.1.4.1.534.1.7.44' => 'OnMaintenanceBypass', +); + +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 => + { + "filter-type:s" => { name => 'filter_type', + default => '^(?!(UtilityPowerRestored|NoticeCondition|ReturnFromLowBattery|AlarmEntryAdded|AlarmEntryRemoved))' }, + "memory" => { name => 'memory' }, + "warning" => { name => 'warning' }, + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->check_options(%options); + } +} + + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + $self->{snmp_port} = $self->{snmp}->get_port(); + my $datas = {}; + my $last_time; + my $exit = defined($self->{option_results}->{warning}) ? 'WARNING' : 'CRITICAL'; + my ($num_alarms_checked, $num_errors) = (0, 0); + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => "cache_ups_powerware_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); + $self->{output}->output_add(severity => 'OK', + short_msg => "No new problems detected."); + $last_time = $self->{statefile_cache}->get(name => 'last_time'); + } else { + $self->{output}->output_add(severity => 'OK', + short_msg => "No problems detected."); + } + + my $oid_xupsAlarmEntry = '.1.3.6.1.4.1.534.1.7.2.1'; + my $oid_xupsAlarmDescr = '.1.3.6.1.4.1.534.1.7.2.1.2'; + my $oid_xupsAlarmTime = '.1.3.6.1.4.1.534.1.7.2.1.3'; + + my $result = $self->{snmp}->get_table(oid => $oid_xupsAlarmEntry); + + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /^$oid_xupsAlarmDescr\.(\d+)$/); + my $instance = $1; + + my $type = $alarm_type_map{$result->{$key}}; + my $time = $result->{$oid_xupsAlarmTime . '.' . $instance}; + + if (defined($self->{option_results}->{memory})) { + $datas->{$instance . '_type'} = $type; + $datas->{$instance . '_time'} = $time; + my $compare_type = $self->{statefile_cache}->get(name => $instance . '_type'); + my $compare_time = $self->{statefile_cache}->get(name => $instance . '_time'); + next if (defined($compare_type) && defined($compare_time) && $type eq $compare_type && $time eq $compare_time); + } + + $num_alarms_checked++; + + next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && $type !~ /$self->{option_results}->{filter_type}/); + + my ($days, $hours, $minutes, $seconds) = ($time / 100 / 86400, $time / 100 % 86400 / 3600, $time / 100 % 86400 % 3600 / 60, $time / 100 % 86400 % 3600 % 60); + $num_errors++; + $self->{output}->output_add(long_msg => sprintf("%d day(s), %d:%d:%d : %s", + $days, $hours, $minutes, $seconds, + $type + ) + ); + + + } + + $self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_alarms_checked)); + if ($num_errors != 0) { + # Message problem + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors) + ); + } + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->write(data => $datas); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check alarms (XUPS-MIB). + +=over 8 + +=item B<--warning> + +Use warning return instead 'critical'. + +=item B<--memory> + +Only check new alarms. + +=item B<--filter-type> + +Filter on type. (can be a regexp) +Default: ^(?!(UtilityPowerRestored|NoticeCondition|ReturnFromLowBattery|AlarmEntryAdded|AlarmEntryRemoved)) + +=back + +=cut + \ No newline at end of file diff --git a/hardware/ups/mge/mode/batterystatus.pm b/hardware/ups/mge/mode/batterystatus.pm new file mode 100644 index 000000000..3235ac6fd --- /dev/null +++ b/hardware/ups/mge/mode/batterystatus.pm @@ -0,0 +1,172 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package hardware::ups::mge::mode::batterystatus; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my %map_battery_status = ( + '.1.3.6.1.4.1.705.1.5.9.0' => 'BatteryFaultBattery', + '.1.3.6.1.4.1.705.1.5.10.0' => 'BatteryNoBattery', + '.1.3.6.1.4.1.705.1.5.11.0' => 'BatteryReplacement', + '.1.3.6.1.4.1.705.1.5.12.0' => 'BatteryUnavailableBattery', + '.1.3.6.1.4.1.705.1.5.13.0' => 'BatteryNotHighCharge', + '.1.3.6.1.4.1.705.1.5.14.0' => 'BatteryLowBattery', + '.1.3.6.1.4.1.705.1.5.15.0' => 'BatteryChargerFault', + '.1.3.6.1.4.1.705.1.5.16.0' => 'BatteryLowCondition', + '.1.3.6.1.4.1.705.1.5.17.0' => 'BatteryLowRecharge', +); + +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', }, + "filter-status:s" => { name => 'filter_status', }, + }); + + 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) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_upsmgBattery = '.1.3.6.1.4.1.705.1.5'; + my $oid_upsmgBatteryRemainingTime = '.1.3.6.1.4.1.705.1.5.1.0'; # in seconds + my $oid_upsmgBatteryLevel = '.1.3.6.1.4.1.705.1.5.2.0'; + my $oid_upsmgBatteryVoltage = '.1.3.6.1.4.1.705.1.5.5.0'; # in dV + my $oid_upsmgBatteryCurrent = '.1.3.6.1.4.1.705.1.5.6.0'; # in dA + my $oid_upsmgBatteryTemperature = '.1.3.6.1.4.1.705.1.5.7.0'; # in degrees Centigrade + + my $result = $self->{snmp}->get_table(oid => $oid_upsmgBattery, nothing_quit => 1); + + my $current = defined($result->{$oid_upsmgBatteryCurrent}) ? $result->{$oid_upsmgBatteryCurrent} * 0.1 : 0; + my $voltage = defined($result->{$oid_upsmgBatteryVoltage}) ? $result->{$oid_upsmgBatteryVoltage} * 0.1 : 0; + my $min_remain = defined($result->{$oid_upsmgBatteryRemainingTime}) ? int($result->{$oid_upsmgBatteryRemainingTime} / 60) : 'unknown'; + my $charge_remain = defined($result->{$oid_upsmgBatteryLevel}) ? $result->{$oid_upsmgBatteryLevel} : 'unknown'; + my $temp = defined($result->{$oid_upsmgBatteryTemperature}) ? $result->{$oid_upsmgBatteryTemperature} : 0; + + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("Battery status is ok")); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %map_battery_status)) { + next if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' && $map_battery_status{$oid} =~ /$self->{option_results}->{filter_status}/); + if (defined($result->{$oid}) && $result->{$oid} == 1) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Battery status is '%s'", $map_battery_status{$oid})); + } + } + + my $exit_code = 'ok'; + if ($charge_remain ne 'unknown') { + $exit_code = $self->{perfdata}->threshold_check(value => $charge_remain, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->perfdata_add(label => 'load', unit => '%', + value => $charge_remain, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, max => 100); + } + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("Charge remaining: %s%% (%s minutes remaining)", $charge_remain, $min_remain)); + + if ($current != 0) { + $self->{output}->perfdata_add(label => 'current', unit => 'A', + value => $current, + ); + } + if ($voltage != 0) { + $self->{output}->perfdata_add(label => 'voltage', unit => 'V', + value => $voltage, + ); + } + if ($temp != 0) { + $self->{output}->perfdata_add(label => 'temp', unit => 'C', + value => $temp, + ); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check Battery Status and battery charge remaining. + +=over 8 + +=item B<--warning> + +Threshold warning in percent of charge remaining. + +=item B<--critical> + +Threshold critical in percent of charge remaining. + +=item B<--filter-status> + +Filter on status. (can be a regexp) + +=back + +=cut diff --git a/hardware/ups/mge/mode/environment.pm b/hardware/ups/mge/mode/environment.pm new file mode 100644 index 000000000..71ab21f99 --- /dev/null +++ b/hardware/ups/mge/mode/environment.pm @@ -0,0 +1,194 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package hardware::ups::mge::mode::environment; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::values; + +my $maps_counters = { + temperature => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'temperature', no_value => 0, }, + ], + output_template => 'Ambiant Temperature: %.2f C', output_error_template => 'Ambiant Temperature: %s', + perfdatas => [ + { value => 'temperature_absolute', label => 'temperature', template => '%.2f', + unit => 'C' }, + ], + } + }, + humidity => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'humidity', no_value => 0 }, + ], + output_template => 'Humidity: %.2f %%', output_error_template => 'Humidity: %s', + perfdatas => [ + { value => 'humidity_absolute', label => 'humidity', template => '%.2f', + unit => '%', min => 0, max => 100 }, + ], + } + }, +}; + +my $oid_upsmgEnvironAmbientTemp = '.1.3.6.1.4.1.705.1.8.1.0'; # in degree centigrade +my $oid_upsmgEnvironAmbientHumidity = '.1.3.6.1.4.1.705.1.8.2.0'; # in % + +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 => + { + }); + + $self->{instance_selected} = {}; + + foreach (keys %{$maps_counters}) { + $options{options}->add_options(arguments => { + 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, + 'critical-' . $_ . ':s' => { name => 'critical-' . $_ }, + }); + my $class = $maps_counters->{$_}->{class}; + $maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata}, + label => $_); + $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); + } + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach (keys %{$maps_counters}) { + $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); + } +} + +sub manage_counters { + my ($self, %options) = @_; + + foreach (sort keys %{$options{maps_counters}}) { + $options{maps_counters}->{$_}->{obj}->set(instance => $options{instance}); + + my ($value_check) = $options{maps_counters}->{$_}->{obj}->execute(values => $self->{instance_selected}->{$options{instance}}); + + # We don't want to display no value + next if ($value_check == -10); + if ($value_check != 0) { + next; + } + my $exit = $options{maps_counters}->{$_}->{obj}->threshold_check(); + + my $output = $options{maps_counters}->{$_}->{obj}->output(); + + $self->{output}->output_add(severity => $exit, + short_msg => $output + ); + + $options{maps_counters}->{$_}->{obj}->perfdata(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + + $self->manage_counters(instance => 'ambiant', maps_counters => $maps_counters); + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub manage_selection { + my ($self, %options) = @_; + my $values_ok = 0; + $self->{instance_selected}->{ambiant} = {}; + + $self->{results} = $self->{snmp}->get_leef(oids => [$oid_upsmgEnvironAmbientTemp, $oid_upsmgEnvironAmbientHumidity], + nothing_quit => 1); + + if (defined($self->{results}->{$oid_upsmgEnvironAmbientTemp}) && $self->{results}->{$oid_upsmgEnvironAmbientTemp} ne '' && + $self->{results}->{$oid_upsmgEnvironAmbientTemp} != 0) { + $self->{instance_selected}->{ambiant}->{temperature} = $self->{results}->{$oid_upsmgEnvironAmbientTemp}; + $values_ok++; + } + if (defined($self->{results}->{$oid_upsmgEnvironAmbientHumidity}) && $self->{results}->{$oid_upsmgEnvironAmbientHumidity} ne '' && + $self->{results}->{$oid_upsmgEnvironAmbientHumidity} != 0) { + $self->{instance_selected}->{ambiant}->{humidity} = $self->{results}->{$oid_upsmgEnvironAmbientHumidity}; + $values_ok++; + } + + if ($values_ok == 0) { + $self->{output}->add_option_msg(short_msg => "Cannot get temperature and humidity values."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check environment (temperature and humidity). + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'temperature', 'humidity'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'temperature', 'humidity'. + +=back + +=cut diff --git a/hardware/ups/mge/mode/inputlines.pm b/hardware/ups/mge/mode/inputlines.pm new file mode 100644 index 000000000..33c075b14 --- /dev/null +++ b/hardware/ups/mge/mode/inputlines.pm @@ -0,0 +1,291 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package hardware::ups::mge::mode::inputlines; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::values; + +my %map_input_status = ( + 1 => 'no', + 2 => 'outoftolvolt', + 3 => 'outoftolfreq', + 4 => 'utilityoff', +); + +my $maps_counters = { + voltage => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'voltage', no_value => 0, }, + ], + output_template => 'Voltage: %.2f V', output_error_template => 'Voltage: %s', + perfdatas => [ + { value => 'voltage_absolute', label => 'voltage', template => '%.2f', + unit => 'V', min => 0, label_extra_instance => 1 }, + ], + } + }, + current => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'current', no_value => 0 }, + ], + output_template => 'Current: %.2f A', output_error_template => 'Current: %s', + perfdatas => [ + { value => 'current_absolute', label => 'current', template => '%.2f', + unit => 'A', min => 0, label_extra_instance => 1 }, + ], + } + }, + frequence => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'frequence', no_value => 0, }, + ], + output_template => 'Frequence: %.2f Hz', output_error_template => 'Frequence: %s', + perfdatas => [ + { value => 'frequence_absolute', label => 'frequence', template => '%.2f', + unit => 'Hz', min => 0 }, + ], + } + }, +}; + +my $oid_upsmgInputPhaseNumEntry = '.1.3.6.1.4.1.705.1.6.1'; +my $oid_mginputVoltageEntry = '.1.3.6.1.4.1.705.1.6.2.1.2'; # in dV +my $oid_mginputFrequencyEntry = '.1.3.6.1.4.1.705.1.6.2.1.3'; # in dHz +my $oid_mginputCurrentEntry = '.1.3.6.1.4.1.705.1.6.2.1.6'; # in dA +my $oid_upsmgInputBadStatusEntry = '.1.3.6.1.4.1.705.1.6.3'; +my $oid_upsmgInputLineFailCauseEntry = '.1.3.6.1.4.1.705.1.6.4'; + +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 => + { + }); + + $self->{instance_selected} = {}; + + foreach (keys %{$maps_counters}) { + $options{options}->add_options(arguments => { + 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, + 'critical-' . $_ . ':s' => { name => 'critical-' . $_ }, + }); + my $class = $maps_counters->{$_}->{class}; + $maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata}, + label => $_); + $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); + } + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach (keys %{$maps_counters}) { + $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); + } +} + +sub manage_counters { + my ($self, %options) = @_; + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + foreach (sort keys %{$options{maps_counters}}) { + $options{maps_counters}->{$_}->{obj}->set(instance => $options{instance}); + + my ($value_check) = $options{maps_counters}->{$_}->{obj}->execute(values => $self->{instance_selected}->{$options{instance}}); + + # We don't want to display no value + next if ($value_check == -10); + if ($value_check != 0) { + $long_msg .= $long_msg_append . $options{maps_counters}->{$_}->{obj}->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $options{maps_counters}->{$_}->{obj}->threshold_check(); + push @exits, $exit2; + + my $output = $options{maps_counters}->{$_}->{obj}->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $options{maps_counters}->{$_}->{obj}->perfdata(extra_instance => $self->{multiple}); + } + + $self->{output}->output_add(long_msg => $options{label} . " " . $long_msg); + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => $options{label} . " " . $short_msg + ); + } + + if ($self->{multiple} == 0) { + $self->{output}->output_add(short_msg => $options{label} . " " . $long_msg); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + + $self->{output}->output_add(severity => 'OK', + short_msg => 'Input Line(s) status is ok'); + if (defined($self->{results}->{$oid_upsmgInputBadStatusEntry}->{$oid_upsmgInputBadStatusEntry . '.0'}) && + $self->{results}->{$oid_upsmgInputBadStatusEntry}->{$oid_upsmgInputBadStatusEntry . '.0'} == 1) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Input Line(s) status is '%s'", + $map_input_status{$self->{results}->{$oid_upsmgInputLineFailCauseEntry}->{$oid_upsmgInputLineFailCauseEntry . '.0'}})); + } + + $self->{multiple} = 1; + if (scalar(keys %{$self->{instance_selected}}) == 1) { + $self->{multiple} = 0; + } + + if ($self->{multiple} == 1) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'Input Lines are ok'); + } + + foreach my $id (sort keys %{$self->{instance_selected}}) { + $self->manage_counters(instance => $id, maps_counters => $maps_counters, label => "Input Line '" . $id . "'"); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub add_result { + my ($self, %options) = @_; + + $self->{instance_selected}->{$options{instance}} = {} if (!defined($self->{instance_selected}->{$options{instance}})); + $self->{instance_selected}->{$options{instance}}->{$options{name}} = $self->{results}->{$options{oid}}->{$options{oid} . '.' . $options{instance2}} * 0.1; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + { oid => $oid_upsmgInputPhaseNumEntry }, + { oid => $oid_mginputVoltageEntry }, + { oid => $oid_mginputFrequencyEntry }, + { oid => $oid_mginputCurrentEntry }, + { oid => $oid_upsmgInputBadStatusEntry }, + { oid => $oid_upsmgInputLineFailCauseEntry }, + ], + , nothing_quit => 1); + + if (!defined($self->{results}->{$oid_upsmgInputPhaseNumEntry}->{$oid_upsmgInputPhaseNumEntry . '.0'}) || + $self->{results}->{$oid_upsmgInputPhaseNumEntry}->{$oid_upsmgInputPhaseNumEntry . '.0'} == 0) { + $self->{output}->add_option_msg(short_msg => "No input lines found."); + $self->{output}->option_exit(); + } + + my %instances = (); + # can be 'xxx.1' or 'xxx.1.0' (cannot respect MIB :) + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_mginputVoltageEntry}})) { + $oid =~ /^$oid_mginputVoltageEntry\.((\d+).*)/; + if (scalar(keys %instances) < $self->{results}->{$oid_upsmgInputPhaseNumEntry}->{$oid_upsmgInputPhaseNumEntry . '.0'}) { + $instances{$2} = 1; + $self->add_result(instance => $2, instance2 => $1, name => 'voltage', oid => $oid_mginputVoltageEntry); + } + } + %instances = (); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_mginputCurrentEntry}})) { + $oid =~ /^$oid_mginputCurrentEntry\.((\d+).*)/; + if (scalar(keys %instances) < $self->{results}->{$oid_upsmgInputPhaseNumEntry}->{$oid_upsmgInputPhaseNumEntry . '.0'}) { + $instances{$2} = 1; + $self->add_result(instance => $2, instance2 => $1, name => 'current', oid => $oid_mginputCurrentEntry); + } + } + %instances = (); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_mginputFrequencyEntry}})) { + $oid =~ /^$oid_mginputFrequencyEntry\.((\d+).*)/; + if (scalar(keys %instances) < $self->{results}->{$oid_upsmgInputPhaseNumEntry}->{$oid_upsmgInputPhaseNumEntry . '.0'}) { + $instances{$2} = 1; + $self->add_result(instance => $2, instance2 => $1, name => 'frequence', oid => $oid_mginputFrequencyEntry); + } + } + + if (scalar(keys %{$self->{instance_selected}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No input lines found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Input lines metrics (frequence, voltage, current). + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'frequence', 'voltage', 'current'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'frequence', 'voltage', 'current'. + +=back + +=cut diff --git a/hardware/ups/mge/mode/outputlines.pm b/hardware/ups/mge/mode/outputlines.pm new file mode 100644 index 000000000..bfc83c074 --- /dev/null +++ b/hardware/ups/mge/mode/outputlines.pm @@ -0,0 +1,337 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package hardware::ups::mge::mode::outputlines; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::values; + +my $maps_counters = { + voltage => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'voltage', no_value => 0 }, + ], + output_template => 'Voltage: %.2f V', output_error_template => 'Voltage: %s', + perfdatas => [ + { value => 'voltage_absolute', label => 'voltage', template => '%.2f', + unit => 'V', min => 0, label_extra_instance => 1 }, + ], + } + }, + current => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'current', no_value => 0 }, + ], + output_template => 'Current: %.2f A', output_error_template => 'Current: %s', + perfdatas => [ + { value => 'current_absolute', label => 'current', template => '%.2f', + unit => 'A', min => 0, label_extra_instance => 1 }, + ], + } + }, + frequence => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'frequence', no_value => 0 }, + ], + output_template => 'Frequence: %.2f Hz', output_error_template => 'Frequence: %s', + perfdatas => [ + { value => 'frequence_absolute', label => 'frequence', template => '%.2f', + unit => 'Hz', min => 0 }, + ], + } + }, + load => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'load', no_value => -1 }, + ], + output_template => 'Load: %.2f %%', output_error_template => 'Load: %s', + perfdatas => [ + { value => 'load_absolute', label => 'load', template => '%.2f', + unit => '%', min => 0 }, + ], + } + }, +}; + +my $maps_counters2 = { + 'stdev-3phases' => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'stdev' }, + ], + output_template => 'Load Standard Deviation : %.2f', output_error_template => 'Load Standard Deviation : %s', + perfdatas => [ + { value => 'stdev_absolute', label => 'stdev', template => '%.2f', + min => 0 }, + ], + } + }, +}; + +my $oid_upsmgOutputPhaseNumEntry = '.1.3.6.1.4.1.705.1.7.1'; +my $oid_mgoutputVoltageEntry = '.1.3.6.1.4.1.705.1.7.2.1.2'; # in dV +my $oid_mgoutputFrequencyEntry = '.1.3.6.1.4.1.705.1.7.2.1.3'; # in dHz +my $oid_mgoutputCurrentEntry = '.1.3.6.1.4.1.705.1.7.2.1.5'; # in dA +my $oid_mgoutputLoadPerPhaseEntry = '.1.3.6.1.4.1.705.1.7.2.1.4'; # in % + +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 => + { + }); + + $self->{instance_selected} = {}; + + foreach (keys %{$maps_counters}) { + $options{options}->add_options(arguments => { + 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, + 'critical-' . $_ . ':s' => { name => 'critical-' . $_ }, + }); + my $class = $maps_counters->{$_}->{class}; + $maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata}, + label => $_); + $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); + } + foreach (keys %{$maps_counters2}) { + $options{options}->add_options(arguments => { + 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, + 'critical-' . $_ . ':s' => { name => 'critical-' . $_ }, + }); + my $class = $maps_counters2->{$_}->{class}; + $maps_counters2->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata}, + label => $_); + $maps_counters2->{$_}->{obj}->set(%{$maps_counters2->{$_}->{set}}); + } + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach (keys %{$maps_counters}) { + $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); + } + foreach (keys %{$maps_counters2}) { + $maps_counters2->{$_}->{obj}->init(option_results => $self->{option_results}); + } +} + +sub manage_counters { + my ($self, %options) = @_; + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + foreach (sort keys %{$options{maps_counters}}) { + $options{maps_counters}->{$_}->{obj}->set(instance => $options{instance}); + + my ($value_check) = $options{maps_counters}->{$_}->{obj}->execute(values => $self->{instance_selected}->{$options{instance}}); + + # We don't want to display no value + next if ($value_check == -10); + if ($value_check != 0) { + $long_msg .= $long_msg_append . $options{maps_counters}->{$_}->{obj}->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $options{maps_counters}->{$_}->{obj}->threshold_check(); + push @exits, $exit2; + + my $output = $options{maps_counters}->{$_}->{obj}->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $options{maps_counters}->{$_}->{obj}->perfdata(extra_instance => $self->{multiple}); + } + + $self->{output}->output_add(long_msg => $options{label} . " " . $long_msg); + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => $options{label} . " " . $short_msg + ); + } + + if ($self->{multiple} == 0) { + $self->{output}->output_add(short_msg => $options{label} . " " . $long_msg); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + + $self->{multiple} = 1; + if (scalar(keys %{$self->{instance_selected}}) == 1) { + $self->{multiple} = 0; + } + + if ($self->{multiple} == 1) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'Output Lines are ok.'); + } + + foreach my $id (sort keys %{$self->{instance_selected}}) { + $self->manage_counters(instance => $id, maps_counters => $maps_counters, label => "Output Line '" . $id . "'"); + } + + if ($self->{results}->{$oid_upsmgOutputPhaseNumEntry}->{$oid_upsmgOutputPhaseNumEntry . '.0'} > 1) { + $self->{instance_selected}->{lines} = { stdev => $self->{stdev} }; + $self->manage_counters(instance => 'lines', maps_counters => $maps_counters2, label => "Output Lines"); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub add_result { + my ($self, %options) = @_; + + $self->{instance_selected}->{$options{instance}} = {} if (!defined($self->{instance_selected}->{$options{instance}})); + $self->{instance_selected}->{$options{instance}}->{$options{name}} = $self->{results}->{$options{oid}}->{$options{oid} . '.' . $options{instance2}} * $options{multiple}; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + { oid => $oid_upsmgOutputPhaseNumEntry }, + { oid => $oid_mgoutputVoltageEntry }, + { oid => $oid_mgoutputFrequencyEntry }, + { oid => $oid_mgoutputCurrentEntry }, + { oid => $oid_mgoutputLoadPerPhaseEntry }, + ], + , nothing_quit => 1); + + if (!defined($self->{results}->{$oid_upsmgOutputPhaseNumEntry}->{$oid_upsmgOutputPhaseNumEntry . '.0'}) || + $self->{results}->{$oid_upsmgOutputPhaseNumEntry}->{$oid_upsmgOutputPhaseNumEntry . '.0'} == 0) { + $self->{output}->add_option_msg(short_msg => "No output lines found."); + $self->{output}->option_exit(); + } + + my %instances = (); + # can be 'xxx.1' or 'xxx.1.0' (cannot respect MIB :) + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_mgoutputVoltageEntry}})) { + $oid =~ /^$oid_mgoutputVoltageEntry\.((\d+).*)/; + if (scalar(keys %instances) < $self->{results}->{$oid_upsmgOutputPhaseNumEntry}->{$oid_upsmgOutputPhaseNumEntry . '.0'}) { + $instances{$2} = 1; + $self->add_result(instance => $2, instance2 => $1, name => 'voltage', oid => $oid_mgoutputVoltageEntry, multiple => 0.1); + } + } + %instances = (); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_mgoutputCurrentEntry}})) { + $oid =~ /^$oid_mgoutputCurrentEntry\.((\d+).*)/; + if (scalar(keys %instances) < $self->{results}->{$oid_upsmgOutputPhaseNumEntry}->{$oid_upsmgOutputPhaseNumEntry . '.0'}) { + $instances{$2} = 1; + $self->add_result(instance => $2, instance2 => $1, name => 'current', oid => $oid_mgoutputCurrentEntry, multiple => 0.1); + } + } + %instances = (); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_mgoutputFrequencyEntry}})) { + $oid =~ /^$oid_mgoutputFrequencyEntry\.((\d+).*)/; + if (scalar(keys %instances) < $self->{results}->{$oid_upsmgOutputPhaseNumEntry}->{$oid_upsmgOutputPhaseNumEntry . '.0'}) { + $instances{$2} = 1; + $self->add_result(instance => $2, instance2 => $1, name => 'frequence', oid => $oid_mgoutputFrequencyEntry, multiple => 0.1); + } + } + + %instances = (); + # Calculate stdev + my $total = 0; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_mgoutputLoadPerPhaseEntry}})) { + $oid =~ /^$oid_mgoutputLoadPerPhaseEntry\.((\d+).*)/; + if (scalar(keys %instances) < $self->{results}->{$oid_upsmgOutputPhaseNumEntry}->{$oid_upsmgOutputPhaseNumEntry . '.0'}) { + $instances{$2} = $self->{results}->{$oid_mgoutputLoadPerPhaseEntry}->{$oid}; + $self->add_result(instance => $2, instance2 => $1, name => 'load', oid => $oid_mgoutputLoadPerPhaseEntry, multiple => 1); + $total += $self->{results}->{$oid_mgoutputLoadPerPhaseEntry}->{$oid}; + } + } + + my $mean = $total / $self->{results}->{$oid_upsmgOutputPhaseNumEntry}->{$oid_upsmgOutputPhaseNumEntry . '.0'}; + $total = 0; + foreach (keys %instances) { + $total += ($mean - $instances{$_}) ** 2; + } + $self->{stdev} = sqrt($total / $self->{results}->{$oid_upsmgOutputPhaseNumEntry}->{$oid_upsmgOutputPhaseNumEntry . '.0'}); + + if (scalar(keys %{$self->{instance_selected}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No output lines found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Output lines metrics (load, voltage, current). + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'load', 'voltage', 'current', 'frequence', 'stdev-3phases'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'load', 'voltage', 'current', 'frequence', 'stdev-3phases'. + +=back + +=cut diff --git a/hardware/ups/mge/mode/outputsource.pm b/hardware/ups/mge/mode/outputsource.pm new file mode 100644 index 000000000..85f819449 --- /dev/null +++ b/hardware/ups/mge/mode/outputsource.pm @@ -0,0 +1,115 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package hardware::ups::mge::mode::outputsource; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_upsmgOutput = '.1.3.6.1.4.1.705.1.7'; +my $oid_upsmgOutputOnBatteryEntry = '.1.3.6.1.4.1.705.1.7.3'; + +my %map_output_status = ( + '.1.3.6.1.4.1.705.1.7.3.0' => 'OutputOnBattery', + '.1.3.6.1.4.1.705.1.7.4.0' => 'OutputOnByPass', + '.1.3.6.1.4.1.705.1.7.5.0' => 'OutputUnavailableByPass', + '.1.3.6.1.4.1.705.1.7.6.0' => 'OutputNoByPass', + '.1.3.6.1.4.1.705.1.7.7.0' => 'OutputUtilityOff', + '.1.3.6.1.4.1.705.1.7.8.0' => 'OutputOnBoost', + '.1.3.6.1.4.1.705.1.7.9.0' => 'OutputInverterOff', + '.1.3.6.1.4.1.705.1.7.10.0' => 'OutputOverLoad', + '.1.3.6.1.4.1.705.1.7.11.0' => 'OutputOverTemp', + '.1.3.6.1.4.1.705.1.7.12.0' => 'OutputOnBuck', +); + +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 => + { + "filter-status:s" => { name => 'filter_status', default => '^OutputInverterOff'}, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $result = $self->{snmp}->get_table(oid => $oid_upsmgOutput, start => $oid_upsmgOutputOnBatteryEntry, nothing_quit => 1); + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("Output status is ok")); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %map_output_status)) { + next if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' && $map_output_status{$oid} =~ /$self->{option_results}->{filter_status}/); + if (defined($result->{$oid}) && $result->{$oid} == 1) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Output status is '%s'", $map_output_status{$oid})); + } + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check output source status. + +=over 8 + +=item B<--filter-status> + +Filter on status. (can be a regexp) +Default: ^OutputInverterOff + +=back + +=cut diff --git a/hardware/ups/mge/plugin.pm b/hardware/ups/mge/plugin.pm new file mode 100644 index 000000000..b0a3119de --- /dev/null +++ b/hardware/ups/mge/plugin.pm @@ -0,0 +1,68 @@ +################################################################################ +# Copyright 2005-2014 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Stéphane Duret +# +#################################################################################### + +package hardware::ups::mge::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; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'environment' => 'hardware::ups::mge::mode::environment', + 'input-lines' => 'hardware::ups::mge::mode::inputlines', + 'output-lines' => 'hardware::ups::mge::mode::outputlines', + 'output-source' => 'hardware::ups::mge::mode::outputsource', + 'battery-status' => 'hardware::ups::mge::mode::batterystatus', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check UPS MerlinGerin in SNMP. + +=cut diff --git a/hardware/ups/standard/rfc1628/mode/outputlines.pm b/hardware/ups/standard/rfc1628/mode/outputlines.pm index 4c261306d..c1b647587 100644 --- a/hardware/ups/standard/rfc1628/mode/outputlines.pm +++ b/hardware/ups/standard/rfc1628/mode/outputlines.pm @@ -164,7 +164,7 @@ sub stdev { $total = 0; foreach my $instance (keys %{$self->{instances_done}}) { next if ($self->{counters_value}->{$instance}->{load} == -1); # Not present - $total = ($mean - $self->{counters_value}->{$instance}->{load}) ** 2; + $total += ($mean - $self->{counters_value}->{$instance}->{load}) ** 2; } my $stdev = sqrt($total / $num_present);