Debian Codegraph @

src/hardware/server/cisco/ucs/snmp/mode/serviceprofile.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 hardware::server::cisco::ucs::snmp::mode::serviceprofile;
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_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'status: %s',
34 $self->{result_values}->{status}
35 );
36 }
37
38 sub prefix_sp_output {
39 my ($self, %options) = @_;
40
41 return sprintf(
42 "Service profile '%s' ",
43 $options{instance_value}->{dn}
44 );
45 }
46
47 sub prefix_global_output {
48 my ($self, %options) = @_;
49
50 return 'Service profiles ';
51 }
52
53 sub set_counters {
54 my ($self, %options) = @_;
55
56 $self->{maps_counters_type} = [
57 { name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 },
58 { name => 'sp', type => 1, cb_prefix_output => 'prefix_sp_output', message_multiple => 'All service profiles are ok' }
59 ];
60
61 $self->{maps_counters}->{global} = [
62 { label => 'total', nlabel => 'serviceprofiles.total.count', display_ok => 0, set => {
63 key_values => [ { name => 'total' } ],
64 output_template => 'total: %s',
65 perfdatas => [
66 { template => '%s', min => 0 }
67 ]
68 }
69 },
70 { label => 'online', nlabel => 'serviceprofiles.online.count', display_ok => 0, set => {
71 key_values => [ { name => 'online' }, { name => 'total' } ],
72 output_template => 'online: %s',
73 perfdatas => [
74 { template => '%s', min => 0, max => 'total' }
75 ]
76 }
77 },
78 { label => 'offline', nlabel => 'serviceprofiles.offline.count', display_ok => 0, set => {
79 key_values => [ { name => 'offline' }, { name => 'total' } ],
80 output_template => 'offline: %s',
81 perfdatas => [
82 { template => '%s', min => 0, max => 'total' }
83 ]
84 }
85 }
86 ];
87
88 $self->{maps_counters}->{sp} = [
89 {
90 label => 'status', type => 2, critical_default => '%{status} eq "offline"',
91 set => {
92 key_values => [ { name => 'dn' }, { name => 'status' } ],
93 closure_custom_output => $self->can('custom_status_output'),
94 closure_custom_perfdata => sub { return 0; },
95 closure_custom_threshold_check => \&catalog_status_threshold_ng
96 }
97 }
98 ];
99 }
100
101 sub new {
102 my ($class, %options) = @_;
103 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
104 bless $self, $class;
105
106 $options{options}->add_options(arguments => {
107 });
108
109 return $self;
110 }
111
112 my $map_status = {
113 1 => 'online',
114 2 => 'offline'
115 };
116
117 my $mapping = {
118 dn => { oid => '.1.3.6.1.4.1.9.9.719.1.26.2.1.2' }, # cucsLsBindingDn
119 status => { oid => '.1.3.6.1.4.1.9.9.719.1.26.2.1.10', map => $map_status } # cucsLsBindingOperState
120 };
121
122 sub manage_selection {
123 my ($self, %options) = @_;
124
125 my $snmp_result = $options{snmp}->get_multiple_table(
126 oids => [ map({ oid => $_->{oid} }, values(%$mapping)) ],
127 return_type => 1,
128 nothing_quit => 1
129 );
130
131 $self->{global} = { total => 0, online => 0, offline => 0 };
132 $self->{sp} = {};
133 foreach my $oid (keys %$snmp_result) {
134 next if ($oid !~ /^$mapping->{dn}->{oid}\.(.*)$/);
135 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
136 $self->{sp}->{ $result->{dn} } = $result;
137 $self->{global}->{ $result->{status} }++;
138 $self->{global}->{total}++;
139 }
140 }
141
142 1;
143
144 __END__
145
146 =head1 MODE
147
148 Check service profiles.
149
150 =over 8
151
152 =item B<--warning-status>
153
154 Define the conditions to match for the status to be WARNING.
155 You can use the following variables: %{dn}, %{status}
156
157 =item B<--critical-status>
158
159 Define the conditions to match for the status to be CRITICAL (default: '%{status} eq "offline"').
160 You can use the following variables: %{dn}, %{status}
161
162 =item B<--warning-*> B<--critical-*>
163
164 Thresholds.
165 Can be: 'total', 'online', 'offline'.
166
167 =back
168
169 =cut