Debian Codegraph @

src/network/bluecoat/snmp/mode/clienttraffic.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::bluecoat::snmp::mode::clienttraffic;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::statefile;
28
29 sub new {
30 my ($class, %options) = @_;
31 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
32 bless $self, $class;
33
34 $options{options}->add_options(arguments =>
35 {
36 "warning-received:s" => { name => 'warning_received' },
37 "critical-received:s" => { name => 'critical_received' },
38 "warning-delivered:s" => { name => 'warning_delivered' },
39 "critical-delivered:s" => { name => 'critical_delivered' },
40 });
41 $self->{statefile_value} = centreon::plugins::statefile->new(%options);
42
43 return $self;
44 }
45
46 sub check_options {
47 my ($self, %options) = @_;
48 $self->SUPER::init(%options);
49
50 if (($self->{perfdata}->threshold_validate(label => 'warning_received', value => $self->{option_results}->{warning_received})) == 0) {
51 $self->{output}->add_option_msg(short_msg => "Wrong warning 'received' threshold '" . $self->{option_results}->{warning_received} . "'.");
52 $self->{output}->option_exit();
53 }
54 if (($self->{perfdata}->threshold_validate(label => 'critical_received', value => $self->{option_results}->{critical_received})) == 0) {
55 $self->{output}->add_option_msg(short_msg => "Wrong critical 'received' threshold '" . $self->{option_results}->{critical_received} . "'.");
56 $self->{output}->option_exit();
57 }
58 if (($self->{perfdata}->threshold_validate(label => 'warning_delivered', value => $self->{option_results}->{warning_delivered})) == 0) {
59 $self->{output}->add_option_msg(short_msg => "Wrong warning 'delivered' threshold '" . $self->{option_results}->{warning_delivered} . "'.");
60 $self->{output}->option_exit();
61 }
62 if (($self->{perfdata}->threshold_validate(label => 'critical_delivered', value => $self->{option_results}->{critical_delivered})) == 0) {
63 $self->{output}->add_option_msg(short_msg => "Wrong critical 'delivered' threshold '" . $self->{option_results}->{critical_delivered} . "'.");
64 $self->{output}->option_exit();
65 }
66
67 $self->{statefile_value}->check_options(%options);
68 }
69
70 sub run {
71 my ($self, %options) = @_;
72 $self->{snmp} = $options{snmp};
73 $self->{hostname} = $self->{snmp}->get_hostname();
74 $self->{snmp_port} = $self->{snmp}->get_port();
75
76 if ($self->{snmp}->is_snmpv1()) {
77 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
78 $self->{output}->option_exit();
79 }
80
81 $self->{statefile_value}->read(statefile => 'bluecoat_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode});
82
83 my $result = $self->{snmp}->get_leef(oids => ['.1.3.6.1.4.1.3417.2.11.3.1.1.9.0',
84 '.1.3.6.1.4.1.3417.2.11.3.1.1.10.0'], nothing_quit => 1);
85
86 my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
87 my $old_client_in_bytes = $self->{statefile_value}->get(name => 'client_in_bytes');
88 my $old_client_out_bytes = $self->{statefile_value}->get(name => 'client_out_bytes');
89
90 my $new_datas = {};
91 $new_datas->{last_timestamp} = time();
92 $new_datas->{client_in_bytes} = $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.9.0'};
93 $new_datas->{client_out_bytes} = $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.10.0'};
94
95 $self->{statefile_value}->write(data => $new_datas);
96
97 if (!defined($old_timestamp) || !defined($old_client_in_bytes)) {
98 $self->{output}->output_add(severity => 'OK',
99 short_msg => "Buffer creation...");
100 $self->{output}->display();
101 $self->{output}->exit();
102 }
103
104 if ($new_datas->{client_in_bytes} < $old_client_in_bytes) {
105 # We set 0. Has reboot.
106 $old_client_in_bytes = 0;
107 $old_client_out_bytes = 0;
108 }
109
110 my $delta_time = $new_datas->{last_timestamp} - $old_timestamp;
111 my $in_bytes_sec = sprintf("%.2f", ($new_datas->{client_in_bytes} - $old_client_in_bytes) / $delta_time);
112 my $out_bytes_sec = sprintf("%.2f", ($new_datas->{client_out_bytes} - $old_client_out_bytes) / $delta_time);
113
114 my $exit1 = $self->{perfdata}->threshold_check(value => $in_bytes_sec, threshold => [ { label => 'critical_received', 'exit_litteral' => 'critical' }, { label => 'warning_received', exit_litteral => 'warning' } ]);
115 my $exit2 = $self->{perfdata}->threshold_check(value => $out_bytes_sec, threshold => [ { label => 'critical_delivered', 'exit_litteral' => 'critical' }, { label => 'warning_delivered', exit_litteral => 'warning' } ]);
116 my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
117
118 my ($value_in, $unit_in) = $self->{perfdata}->change_bytes(value => $in_bytes_sec);
119 my ($value_out, $unit_out) = $self->{perfdata}->change_bytes(value => $out_bytes_sec);
120
121 $self->{output}->output_add(severity => $exit,
122 short_msg => "Traffic: In $value_in $unit_in/s, Out $value_out $unit_out/s");
123 $self->{output}->perfdata_add(label => 'traffic_in', unit => 'B/s',
124 value => $in_bytes_sec,
125 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_received'),
126 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_received'),
127 min => 0);
128 $self->{output}->perfdata_add(label => 'traffic_out', unit => 'B/s',
129 value => $out_bytes_sec,
130 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_delivered'),
131 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_delivered'),
132 min => 0);
133
134 $self->{output}->display();
135 $self->{output}->exit();
136 }
137
138 1;
139
140 __END__
141
142 =head1 MODE
143
144 Check bytes/s received/delivered to clients
145
146 =over 8
147
148 =item B<--warning-received>
149
150 Warning threshold for received (in bytes/s).
151
152 =item B<--critical-received>
153
154 Critical threshold for received (in bytes/s).
155
156 =item B<--warning-delivered>
157
158 Warning threshold2 for delivered (in bytes/s).
159
160 =item B<--critical-delivered>
161
162 Critical threshold for delivered (in bytes/s).
163
164 =back
165
166 =cut