From 0b8c4575e5e237a878c39bfd8d5bb8bc2d20daea Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Mon, 15 Sep 2014 18:06:15 +0200 Subject: [PATCH] Refs #5673 WIP --- centreon/plugins/values.pm | 2 +- hardware/ups/eaton/plugin.pm | 8 +- hardware/ups/powerware/mode/batterystatus.pm | 150 +++++++++ hardware/ups/powerware/mode/inputlines.pm | 289 ++++++++++++++++++ hardware/ups/powerware/mode/outputlines.pm | 305 +++++++++++++++++++ hardware/ups/powerware/mode/outputsource.pm | 100 ++++++ hardware/ups/powerware/plugin.pm | 69 +++++ network/alteon/5224/plugin.pm | 4 +- 8 files changed, 920 insertions(+), 7 deletions(-) create mode 100644 hardware/ups/powerware/mode/batterystatus.pm create mode 100644 hardware/ups/powerware/mode/inputlines.pm create mode 100644 hardware/ups/powerware/mode/outputlines.pm create mode 100644 hardware/ups/powerware/mode/outputsource.pm create mode 100644 hardware/ups/powerware/plugin.pm diff --git a/centreon/plugins/values.pm b/centreon/plugins/values.pm index b7c0648bb..ddba7274f 100644 --- a/centreon/plugins/values.pm +++ b/centreon/plugins/values.pm @@ -253,7 +253,7 @@ sub execute { if ($quit == 2) { $self->{error_msg} = "skipped (no value(s))"; - return -1; + return -10; } if ($quit == 1) { diff --git a/hardware/ups/eaton/plugin.pm b/hardware/ups/eaton/plugin.pm index 80470360b..6f65effe4 100644 --- a/hardware/ups/eaton/plugin.pm +++ b/hardware/ups/eaton/plugin.pm @@ -43,12 +43,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object - + # $options->{options} = options object + $self->{version} = '0.1'; %{$self->{modes}} = ( - 'group' => 'hardware::ups::eaton::mode::group', - 'outlet' => 'hardware::ups::eaton::mode::outlet', + 'group' => 'hardware::ups::eaton::mode::group', + 'outlet' => 'hardware::ups::eaton::mode::outlet', ); return $self; diff --git a/hardware/ups/powerware/mode/batterystatus.pm b/hardware/ups/powerware/mode/batterystatus.pm new file mode 100644 index 000000000..112b33e13 --- /dev/null +++ b/hardware/ups/powerware/mode/batterystatus.pm @@ -0,0 +1,150 @@ +################################################################################ +# 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::batterystatus; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my %battery_status = ( + 1 => ['batteryCharging', 'OK'], + 2 => ['batteryDischarging', 'WARNING'], + 3 => ['batteryFloating', 'WARNING'], + 4 => ['batteryResting', 'OK'], + 5 => ['unknown', 'UNKNOWN'], +); + +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) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_xupsBattery = '.1.3.6.1.4.1.534.1.2'; + my $oid_xupsBatteryAbmStatus = '.1.3.6.1.4.1.534.1.2.5.0'; + my $oid_xupsBatTimeRemaining = '.1.3.6.1.4.1.534.1.2.1.0'; # in seconds + my $oid_xupsBatCapacity = '.1.3.6.1.4.1.534.1.2.4.0'; + my $oid_xupsBatVoltage = '.1.3.6.1.4.1.534.1.2.2.0'; # in dV + my $oid_xupsBatCurrent = '.1.3.6.1.4.1.534.1.2.3.0'; # in dA + + my $result = $self->{snmp}->get_table(oid => $oid_xupsBattery, nothing_quit => 1); + + my $current = defined($result->{$oid_xupsBatCurrent}) ? $result->{$oid_xupsBatCurrent} * 0.1 : 0; + my $voltage = defined($result->{$oid_xupsBatVoltage}) ? $result->{$oid_xupsBatVoltage} * 0.1 : 0; + my $min_remain = defined($result->{$oid_xupsBatTimeRemaining}) ? int($result->{$oid_xupsBatTimeRemaining} / 60) : 'unknown'; + my $charge_remain = defined($result->{$oid_xupsBatCapacity}) ? $result->{$oid_xupsBatCapacity} : 'unknown'; + my $status = defined($result->{$oid_xupsBatteryAbmStatus}) ? $result->{$oid_xupsBatteryAbmStatus} : 5; # we put unknown ??? + + $self->{output}->output_add(severity => ${$battery_status{$status}}[1], + short_msg => sprintf("Battery status is %s", ${$battery_status{$status}}[0])); + 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, + ); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check Battery Status and battery charge remaining (XUPS-MIB) + +=over 8 + +=item B<--warning> + +Threshold warning in percent of charge remaining. + +=item B<--critical> + +Threshold critical in percent of charge remaining. + +=back + +=cut diff --git a/hardware/ups/powerware/mode/inputlines.pm b/hardware/ups/powerware/mode/inputlines.pm new file mode 100644 index 000000000..2acab94d4 --- /dev/null +++ b/hardware/ups/powerware/mode/inputlines.pm @@ -0,0 +1,289 @@ +################################################################################ +# 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::inputlines; + +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 }, + ], + } + }, + power => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'power', no_value => 0 }, + ], + output_template => 'Power: %.2f W', output_error_template => 'Power: %s', + perfdatas => [ + { value => 'power_absolute', label => 'power', template => '%.2f', + unit => 'W', min => 0, label_extra_instance => 1 }, + ], + } + }, +}; + +my $maps_counters2 = { + 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_xupsInputVoltageEntry = '.1.3.6.1.4.1.534.1.3.4.1.2'; # in V +my $oid_xupsInputCurrentEntry = '.1.3.6.1.4.1.534.1.3.4.1.3'; # in A +my $oid_xupsInputWattsEntry = '.1.3.6.1.4.1.534.1.3.4.1.4'; # in W +my $oid_xupsInputFrequencyEntry = '.1.3.6.1.4.1.534.1.3.1'; +my $oid_xupsInputFrequency = '.1.3.6.1.4.1.534.1.3.1.0'; # in dHZ + +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 => '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 . "'"); + } + + if (defined($self->{results}->{$oid_xupsInputFrequencyEntry}->{$oid_xupsInputFrequencyEntry . '.0'})) { + $self->{instance_selected}->{frequence} = { frequence => $self->{results}->{$oid_xupsInputFrequencyEntry}->{$oid_xupsInputFrequencyEntry . '.0'} * 0.1 }; + $self->manage_counters(instance => 'frequence', maps_counters => $maps_counters2, label => "Input 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{instance}}; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + { oid => $oid_xupsInputVoltageEntry }, + { oid => $oid_xupsInputCurrentEntry }, + { oid => $oid_xupsInputWattsEntry }, + { oid => $oid_xupsInputFrequencyEntry }, + ], + , nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}->{$oid_xupsInputVoltageEntry}}) { + $oid =~ /^$oid_xupsInputVoltageEntry\.(\d)$/; + $self->add_result(instance => $1, name => 'voltage', oid => $oid_xupsInputVoltageEntry); + } + foreach my $oid (keys %{$self->{results}->{$oid_xupsInputCurrentEntry}}) { + $oid =~ /^$oid_xupsInputCurrentEntry\.(\d)$/; + $self->add_result(instance => $1, name => 'current', oid => $oid_xupsInputCurrentEntry); + } + foreach my $oid (keys %{$self->{results}->{$oid_xupsInputWattsEntry}}) { + $oid =~ /^$oid_xupsInputWattsEntry\.(\d)$/; + $self->add_result(instance => $1, name => 'power', oid => $oid_xupsInputWattsEntry); + } + + if (scalar(keys %{$self->{instance_selected}}) <= 0) { + if (defined($self->{option_results}->{name})) { + $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 and true power). + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'frequence', 'voltage', 'current', 'power'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'frequence', 'voltage', 'current', 'power'. + +=back + +=cut diff --git a/hardware/ups/powerware/mode/outputlines.pm b/hardware/ups/powerware/mode/outputlines.pm new file mode 100644 index 000000000..f8a3430b7 --- /dev/null +++ b/hardware/ups/powerware/mode/outputlines.pm @@ -0,0 +1,305 @@ +################################################################################ +# 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::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 }, + ], + } + }, + power => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'power', no_value => 0 }, + ], + output_template => 'Power: %.2f W', output_error_template => 'Power: %s', + perfdatas => [ + { value => 'power_absolute', label => 'power', template => '%.2f', + unit => 'W', min => 0, label_extra_instance => 1 }, + ], + } + }, +}; + +my $maps_counters2 = { + 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 $oid_xupsOutputVoltageEntry = '.1.3.6.1.4.1.534.1.4.4.1.2'; # in V +my $oid_xupsOutputCurrentEntry = '.1.3.6.1.4.1.534.1.4.4.1.3'; # in A +my $oid_xupsOutputWattsEntry = '.1.3.6.1.4.1.534.1.4.4.1.4'; # in W +my $oid_xupsOutputFrequencyEntry = '.1.3.6.1.4.1.534.1.4.2'; +my $oid_xupsOutputFrequency = '.1.3.6.1.4.1.534.1.4.2.0'; # in dHZ +my $oid_xupsOutputLoadEntry = '.1.3.6.1.4.1.534.1.4.1'; +my $oid_xupsOutputLoad = '.1.3.6.1.4.1.534.1.4.1.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}}); + } + 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 . "'"); + } + + $self->{instance_selected}->{lines} = { frequence => defined($self->{results}->{$oid_xupsOutputFrequencyEntry}->{$oid_xupsOutputFrequency}) ? $self->{results}->{$oid_xupsOutputFrequencyEntry}->{$oid_xupsOutputFrequency} * 0.1 : 0, + load => defined($self->{results}->{$oid_xupsOutputLoadEntry}->{$oid_xupsOutputLoad}) ? $self->{results}->{$oid_xupsOutputLoadEntry}->{$oid_xupsOutputLoad} : -1 }; + $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{instance}}; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + { oid => $oid_xupsOutputVoltageEntry }, + { oid => $oid_xupsOutputCurrentEntry }, + { oid => $oid_xupsOutputWattsEntry }, + { oid => $oid_xupsOutputFrequencyEntry }, + { oid => $oid_xupsOutputLoadEntry }, + ], + , nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}->{$oid_xupsOutputVoltageEntry}}) { + $oid =~ /^$oid_xupsOutputVoltageEntry\.(\d)$/; + $self->add_result(instance => $1, name => 'voltage', oid => $oid_xupsOutputVoltageEntry); + } + foreach my $oid (keys %{$self->{results}->{$oid_xupsOutputCurrentEntry}}) { + $oid =~ /^$oid_xupsOutputCurrentEntry\.(\d)$/; + $self->add_result(instance => $1, name => 'current', oid => $oid_xupsOutputCurrentEntry); + } + foreach my $oid (keys %{$self->{results}->{$oid_xupsOutputWattsEntry}}) { + $oid =~ /^$oid_xupsOutputWattsEntry\.(\d)$/; + $self->add_result(instance => $1, name => 'power', oid => $oid_xupsOutputWattsEntry); + } + + if (scalar(keys %{$self->{instance_selected}}) <= 0) { + if (defined($self->{option_results}->{name})) { + $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 and true power). + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'load', 'voltage', 'current', 'power'. +Load is a rate for X phase. + +=item B<--critical-*> + +Threshold critical. +Can be: 'load', 'voltage', 'current', 'power'. +Load is a rate for X phase. + +=back + +=cut diff --git a/hardware/ups/powerware/mode/outputsource.pm b/hardware/ups/powerware/mode/outputsource.pm new file mode 100644 index 000000000..486460fd2 --- /dev/null +++ b/hardware/ups/powerware/mode/outputsource.pm @@ -0,0 +1,100 @@ +################################################################################ +# 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::standard::rfc1628::mode::outputsource; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my %outputsource_status = ( + 1 => ['other', 'UNKNOWN'], + 2 => ['none', 'CRITICAL'], + 3 => ['normal', 'OK'], + 4 => ['bypass', 'WARNING'], + 5 => ['battery', 'WARNING'], + 6 => ['booster', 'WARNING'], + 7 => ['reducer', 'WARNING'], +); + +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 check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_upsOutputSource = '.1.3.6.1.2.1.33.1.4.1.0'; + + my $result = $self->{snmp}->get_leef(oids => [$oid_upsOutputSource], nothing_quit => 1); + my $status = $result->{'.1.3.6.1.2.1.33.1.4.1.0'}; + + $self->{output}->output_add(severity => ${$outputsource_status{$status}}[1], + short_msg => sprintf("Output source status is %s", ${$outputsource_status{$status}}[0])); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check output source status. + +=over 8 + +=back + +=cut diff --git a/hardware/ups/powerware/plugin.pm b/hardware/ups/powerware/plugin.pm new file mode 100644 index 000000000..5e416cbc3 --- /dev/null +++ b/hardware/ups/powerware/plugin.pm @@ -0,0 +1,69 @@ +################################################################################ +# 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::powerware::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::powerware::mode::environment', + 'input-lines' => 'hardware::ups::powerware::mode::inputlines', + 'output-lines' => 'hardware::ups::powerware::mode::outputlines', + 'output-source' => 'hardware::ups::powerware::mode::outputsource', + 'alarms' => 'hardware::ups::powerware::mode::alarms', + 'battery-status' => 'hardware::ups::powerware::mode::batterystatus', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check UPS Powerware (branch of EATON) in SNMP. + +=cut diff --git a/network/alteon/5224/plugin.pm b/network/alteon/5224/plugin.pm index ce44064d4..03dc16f9c 100644 --- a/network/alteon/5224/plugin.pm +++ b/network/alteon/5224/plugin.pm @@ -47,9 +47,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::alteon::common::mode::cpu', + 'cpu' => 'network::alteon::common::mode::cpu', 'hardware' => 'network::alteon::common::mode::hardware', - 'memory' => 'network::alteon::common::mode::memory', + 'memory' => 'network::alteon::common::mode::memory', ); return $self;