Debian Codegraph @

src/apps/backup/rapidrecovery/snmp/mode/agent.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 apps::backup::rapidrecovery::snmp::mode::agent;
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 my $msg = 'status : ' . $self->{result_values}->{status};
33 return $msg;
34 }
35
36 sub set_counters {
37 my ($self, %options) = @_;
38
39 $self->{maps_counters_type} = [
40 { name => 'global', type => 0 },
41 { name => 'agent', type => 1, cb_prefix_output => 'prefix_agent_output', message_multiple => 'All agents are ok', skipped_code => { -10 => 1 } }
42 ];
43
44 $self->{maps_counters}->{global} = [
45 { label => 'total', display_ok => 0, nlabel => 'agents.total.count', set => {
46 key_values => [ { name => 'total' } ],
47 output_template => 'total agents: %d',
48 perfdatas => [
49 { value => 'total', template => '%d', min => 0 },
50 ],
51 }
52 },
53 ];
54
55 $self->{maps_counters}->{agent} = [
56 { label => 'status', threshold => 0, set => {
57 key_values => [ { name => 'status' }, { name => 'display' } ],
58 closure_custom_calc => \&catalog_status_calc,
59 closure_custom_output => $self->can('custom_status_output'),
60 closure_custom_perfdata => sub { return 0; },
61 closure_custom_threshold_check => \&catalog_status_threshold,
62 }
63 },
64 { label => 'recoverypoints', nlabel => 'agent.recoverypoints.count', set => {
65 key_values => [ { name => 'recovery_points' }, { name => 'display' } ],
66 output_template => 'recovery points: %s',
67 perfdatas => [
68 { value => 'recovery_points', template => '%s', min => 0,
69 label_extra_instance => 1, instance_use => 'display' },
70 ],
71 }
72 },
73 ];
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 'filter-name:s' => { name => 'filter_name' },
83 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unreachable/i' },
84 'warning-status:s' => { name => 'warning_status', default => '' },
85 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /failed|authenticationError/i' },
86 });
87
88 return $self;
89 }
90
91 sub check_options {
92 my ($self, %options) = @_;
93 $self->SUPER::check_options(%options);
94
95 $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
96 }
97
98 sub prefix_agent_output {
99 my ($self, %options) = @_;
100
101 return "Agent '" . $options{instance_value}->{display} . "' ";
102 }
103
104 my $map_status = {
105 0 => 'online', 1 => 'pendingFailover',
106 2 => 'unreachable', 3 => 'authenticationError',
107 4 => 'failed', 5 => 'loading'
108 };
109
110 my $mapping = {
111 agentName => { oid => '.1.3.6.1.4.1.674.11000.1000.200.100.300.1.3' },
112 agentStatus => { oid => '.1.3.6.1.4.1.674.11000.1000.200.100.300.1.5', map => $map_status },
113 agentRecoveryPointsCount => { oid => '.1.3.6.1.4.1.674.11000.1000.200.100.300.1.7' },
114 };
115
116 sub manage_selection {
117 my ($self, %options) = @_;
118
119 my $oid_agentEntry = '.1.3.6.1.4.1.674.11000.1000.200.100.300.1';
120 my $snmp_result = $options{snmp}->get_table(
121 oid => $oid_agentEntry,
122 start => $mapping->{agentName}->{oid},
123 end => $mapping->{agentRecoveryPointsCount}->{oid},
124 nothing_quit => 1
125 );
126
127 $self->{agent} = {};
128 foreach my $oid (keys %$snmp_result) {
129 next if ($oid !~ /^$mapping->{agentName}->{oid}\.(.*)/);
130 my $instance = $1;
131 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
132 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
133 $result->{agentName} !~ /$self->{option_results}->{filter_name}/) {
134 $self->{output}->output_add(long_msg => "skipping '" . $result->{agentName} . "': no matching filter.", debug => 1);
135 next;
136 }
137
138 $self->{agent}->{$instance} = {
139 display => $result->{agentName},
140 status => $result->{agentStatus},
141 recovery_points => $result->{agentRecoveryPointsCount}
142 };
143 }
144
145 $self->{global} = { total => scalar(keys %{$self->{agent}}) };
146 }
147
148 1;
149
150 __END__
151
152 =head1 MODE
153
154 Check agents.
155
156 =over 8
157
158 =item B<--unknown-status>
159
160 Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unreachable/i').
161 You can use the following variables: %{status}, %{display}
162
163 =item B<--warning-status>
164
165 Define the conditions to match for the status to be WARNING (default: '').
166 You can use the following variables: %{status}, %{display}
167
168 =item B<--critical-status>
169
170 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /failed|authenticationError/i').
171 You can use the following variables: %{status}, %{display}
172
173 =item B<--warning-*> B<--critical-*>
174
175 Thresholds.
176 Can be: 'total', 'recoverypoints'.
177
178 =item B<--filter-name>
179
180 Filter agent name (can be a regexp).
181
182 =back
183
184 =cut