Debian Codegraph @

src/centreon/common/cps/ups/snmp/mode/inputlines.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package centreon::common::cps::ups::snmp::mode::inputlines;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf("status is '%s'", $self->{result_values}->{status});
33 }
34
35 sub set_counters {
36 my ($self, %options) = @_;
37
38 $self->{maps_counters_type} = [
39 { name => 'ilines', type => 0, cb_prefix_output => 'prefix_ilines_output', skipped_code => { -10 => 1 } },
40 ];
41
42 $self->{maps_counters}->{ilines} = [
43 { label => 'status', threshold => 0, set => {
44 key_values => [ { name => 'status' } ],
45 closure_custom_calc => \&catalog_status_calc,
46 closure_custom_output => $self->can('custom_status_output'),
47 closure_custom_perfdata => sub { return 0; },
48 closure_custom_threshold_check => \&catalog_status_threshold,
49 }
50 },
51 { label => 'voltage', nlabel => 'lines.input.voltage.volt', set => {
52 key_values => [ { name => 'voltage' } ],
53 output_template => 'Voltage : %.2f V',
54 perfdatas => [
55 { value => 'voltage', template => '%.2f', unit => 'V' },
56 ],
57 }
58 },
59 { label => 'frequence', nlabel => 'lines.input.frequence.hertz', set => {
60 key_values => [ { name => 'frequence' } ],
61 output_template => 'Frequence : %.2f Hz',
62 perfdatas => [
63 { value => 'frequence', template => '%.2f', min => 0, unit => 'Hz' },
64 ],
65 }
66 },
67 ];
68 }
69
70 sub prefix_ilines_output {
71 my ($self, %options) = @_;
72
73 return 'Input ';
74 }
75
76 sub new {
77 my ($class, %options) = @_;
78 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
79 bless $self, $class;
80
81 $options{options}->add_options(arguments => {
82 'unknown-status:s' => { name => 'unknown_status', default => '' },
83 'warning-status:s' => { name => 'warning_status', default => '' },
84 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /normal/' },
85 });
86
87 return $self;
88 }
89
90 sub check_options {
91 my ($self, %options) = @_;
92 $self->SUPER::check_options(%options);
93
94 $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
95 }
96
97 my $map_status = {
98 1 => 'normal', 2 => 'overVoltage',
99 3 => 'underVoltage', 4 => 'frequencyFailure', 5 => 'blackout',
100 };
101
102 my $mapping = {
103 upsAdvanceInputLineVoltage => { oid => '.1.3.6.1.4.1.3808.1.1.1.3.2.1' }, # in dV
104 upsAdvanceInputFrequency => { oid => '.1.3.6.1.4.1.3808.1.1.1.3.2.4' }, # in dHz
105 upsAdvanceInputStatus => { oid => '.1.3.6.1.4.1.3808.1.1.1.3.2.6', map => $map_status },
106 };
107
108 sub manage_selection {
109 my ($self, %options) = @_;
110
111 my $oid_upsAdvanceInput = '.1.3.6.1.4.1.3808.1.1.1.3.2';
112 my $snmp_result = $options{snmp}->get_table(oid => $oid_upsAdvanceInput, nothing_quit => 1);
113 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
114
115 $self->{ilines} = {
116 frequence => (defined($result->{upsAdvanceInputFrequency}) && $result->{upsAdvanceInputFrequency} =~ /\d/) ? $result->{upsAdvanceInputFrequency} * 0.1 : undef,
117 voltage => (defined($result->{upsAdvanceInputLineVoltage}) && $result->{upsAdvanceInputLineVoltage} =~ /\d/) ? $result->{upsAdvanceInputLineVoltage} * 0.1 : undef,
118 status => $result->{upsAdvanceInputStatus},
119 };
120 }
121
122 1;
123
124 __END__
125
126 =head1 MODE
127
128 Check INPUT lines metrics.
129
130 =over 8
131
132 =item B<--unknown-status>
133
134 Define the conditions to match for the status to be UNKNOWN (default: '').
135 You can use the following variables: %{status}
136
137 =item B<--warning-status>
138
139 Define the conditions to match for the status to be WARNING (default: '').
140 You can use the following variables: %{status}
141
142 =item B<--critical-status>
143
144 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /normal/').
145 You can use the following variables: %{status}
146
147 =item B<--warning-*> B<--critical-*>
148
149 Thresholds.
150 Can be: 'voltage', 'frequence'.
151
152 =back
153
154 =cut