Debian Codegraph @

src/network/alcatel/omniswitch/snmp/mode/flashmemory.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 network::alcatel::omniswitch::snmp::mode::flashmemory;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_output {
29 my ($self, %options) = @_;
30
31 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
32 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
33 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
34
35 my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
36 $total_size_value . " " . $total_size_unit,
37 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
38 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
39 return $msg;
40 }
41
42 sub custom_usage_calc {
43 my ($self, %options) = @_;
44
45 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
46 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
47 $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'};
48 $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free};
49 $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
50 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
51 return 0;
52 }
53
54 sub set_counters {
55 my ($self, %options) = @_;
56
57 $self->{maps_counters_type} = [
58 { name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All flash memories are ok' },
59 ];
60
61 $self->{maps_counters}->{memory} = [
62 { label => 'usage', nlabel => 'flash.usage.bytes', set => {
63 key_values => [ { name => 'total' }, { name => 'free' }, { name => 'display' }, ],
64 closure_custom_calc => $self->can('custom_usage_calc'),
65 closure_custom_output => $self->can('custom_usage_output'),
66 threshold_use => 'prct_used',
67 perfdatas => [
68 { label => 'used', value => 'used', template => '%.2f', min => 0, max => 'total',
69 unit => 'B', label_extra_instance => 1, instance_use => 'display', cast_int => 1 },
70 ],
71 }
72 },
73 ];
74 }
75
76 sub prefix_memory_output {
77 my ($self, %options) = @_;
78
79 return "Memory '" . $options{instance_value}->{display} . "' ";
80 }
81
82 sub new {
83 my ($class, %options) = @_;
84 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
85 bless $self, $class;
86
87 $options{options}->add_options(arguments => {
88 });
89
90 return $self;
91 }
92
93 sub manage_selection {
94 my ($self, %options) = @_;
95
96 my $mapping = {
97 aos6 => {
98 entry => '.1.3.6.1.4.1.6486.800.1.1.1.3.1.1.9.1',
99 flash => {
100 chasSupervisionFlashSize => { oid => '.1.3.6.1.4.1.6486.800.1.1.1.3.1.1.9.1.2' }, # in B
101 chasSupervisionFlashFree => { oid => '.1.3.6.1.4.1.6486.800.1.1.1.3.1.1.9.1.3' }, # in B
102 },
103 },
104 aos7 => {
105 entry => '.1.3.6.1.4.1.6486.801.1.1.1.3.1.1.9.1',
106 flash => {
107 chasSupervisionFlashSize => { oid => '.1.3.6.1.4.1.6486.801.1.1.1.3.1.1.9.1.2' }, # in B
108 chasSupervisionFlashFree => { oid => '.1.3.6.1.4.1.6486.801.1.1.1.3.1.1.9.1.3' }, # in B
109 },
110 },
111 };
112
113 my $snmp_result = $options{snmp}->get_multiple_table(oids => [
114 { oid => $mapping->{aos6}->{entry} },
115 { oid => $mapping->{aos7}->{entry} },
116 ], nothing_quit => 1);
117
118 my $type = 'aos6';
119 if (scalar(keys %{$snmp_result->{ $mapping->{aos7}->{entry} }}) > 0) {
120 $type = 'aos7';
121 }
122
123 $self->{memory} = {};
124 foreach my $oid ($options{snmp}->oid_lex_sort(keys %{$snmp_result->{ $mapping->{$type}->{entry} }})) {
125 next if ($oid !~ /^$mapping->{$type}->{flash}->{chasSupervisionFlashSize}->{oid}\.(.*)$/);
126 my $instance = $1;
127 my $result = $options{snmp}->map_instance(mapping => $mapping->{$type}->{flash}, results => $snmp_result->{ $mapping->{$type}->{entry} }, instance => $instance);
128
129 # Skip if total = 0
130 next if ($result->{chasSupervisionFlashSize} == 0);
131
132 $self->{memory}->{$instance} = {
133 display => $instance,
134 free => $result->{chasSupervisionFlashFree},
135 total => $result->{chasSupervisionFlashSize},
136 };
137 }
138 }
139
140 1;
141
142 __END__
143
144 =head1 MODE
145
146 Check flash memory (AlcatelIND1Chassis.mib).
147
148 =over 8
149
150 =item B<--warning-usage>
151
152 Warning threshold in percent.
153
154 =item B<--critical-usage>
155
156 Critical threshold in percent.
157
158 =back
159
160 =cut