Debian Codegraph @

src/apps/video/zixi/restapi/mode/broadcasteroutputusage.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::video::zixi::restapi::mode::broadcasteroutputusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32 my $msg = 'status : ' . $self->{result_values}->{status} . ' [error: ' . $self->{result_values}->{error} . ']';
33
34 return $msg;
35 }
36
37 sub custom_status_calc {
38 my ($self, %options) = @_;
39
40 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
41 $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
42 $self->{result_values}->{error} = $options{new_datas}->{$self->{instance} . '_error'};
43
44 return 0;
45 }
46
47 sub set_counters {
48 my ($self, %options) = @_;
49
50 $self->{maps_counters_type} = [
51 { name => 'output_stream', type => 1, cb_prefix_output => 'prefix_output_output', message_multiple => 'All outputs are ok', skipped_code => { -11 => 1 } },
52 ];
53
54 $self->{maps_counters}->{output_stream} = [
55 { label => 'status', threshold => 0, set => {
56 key_values => [ { name => 'status' }, { name => 'name' }, { name => 'error' } ],
57 closure_custom_calc => $self->can('custom_status_calc'),
58 closure_custom_output => $self->can('custom_status_output'),
59 closure_custom_perfdata => sub { return 0; },
60 closure_custom_threshold_check => \&catalog_status_threshold
61 }
62 },
63 { label => 'traffic-in', set => {
64 key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'name' } ],
65 output_change_bytes => 2,
66 output_template => 'Traffic In : %s %s/s',
67 perfdatas => [
68 { label => 'traffic_in', template => '%.2f',
69 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name' }
70 ]
71 }
72 },
73 { label => 'traffic-out', set => {
74 key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'name' } ],
75 output_change_bytes => 2,
76 output_template => 'Traffic Out : %s %s/s',
77 perfdatas => [
78 { label => 'traffic_out', template => '%.2f',
79 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name' }
80 ]
81 }
82 },
83 { label => 'dropped-in', set => {
84 key_values => [ { name => 'dropped_in', diff => 1 }, { name => 'name' } ],
85 output_template => 'Packets Dropped In : %s',
86 perfdatas => [
87 { label => 'dropped_in', template => '%.2f',
88 min => 0, label_extra_instance => 1, instance_use => 'name' }
89 ]
90 }
91 }
92 ];
93 }
94
95 sub new {
96 my ($class, %options) = @_;
97 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
98 bless $self, $class;
99
100 $options{options}->add_options(arguments => {
101 'filter-name:s' => { name => 'filter_name' },
102 'warning-status:s' => { name => 'warning_status' },
103 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Connecting|Connected/i || %{error} !~ /none/i' },
104 });
105
106 return $self;
107 }
108
109 sub check_options {
110 my ($self, %options) = @_;
111 $self->SUPER::check_options(%options);
112
113 $self->change_macros(macros => ['warning_status', 'critical_status']);
114 }
115
116 sub prefix_output_output {
117 my ($self, %options) = @_;
118
119 return "Output '" . $options{instance_value}->{name} . "' ";
120 }
121
122 my %mapping_output_status = (0 => 'none', 1 => 'unknown',
123 2 => 'resolve error', 3 => 'timeout', 4 => 'network error', 5 => 'protocol error',
124 6 => 'server is full', 7 => 'connection rejected', 8 => 'authentication error', 9 => 'license error',
125 10 => 'end of file', 11 => 'flood error', 12 => 'redirect', 13 => 'stopped',
126 14 => 'limit', 15 => 'not found', 16 => 'not supported', 17 => 'local file system error',
127 18 => 'remote file system error', 19 => 'stream replaced', 20 => 'p2p abort',
128 21 => 'compression error', 22 => 'source collision error', 23 => 'adaptive',
129 24 => 'tcp connection error', 25 => 'rtmp connection error', 26 => 'rtmp handshake error',
130 27 => 'tcp connection closed', 28 => 'rtmp stream error', 29 => 'rtmp publish error',
131 30 => 'rtmp stream closed', 31 => 'rtmp play error', 32 => 'rtmp protocol error',
132 33 => 'rtmp analyze timeout', 34 => 'busy', 35 => 'encryption error',
133 36 => 'transcoder error', 37 => 'error in invocation a transcoder subprocess',
134 38 => 'error communicating with a transcoder subprocess', 39 => 'error in RTMP Akamai authentication',
135 40 => 'maximum outputs for the source reached', 41 => 'generic error',
136 42 => 'zero bitrate warning', 43 => 'low bitrate warning', 44 => 'multicast join failed',
137 );
138
139 sub manage_selection {
140 my ($self, %options) = @_;
141
142 $self->{output_stream} = {};
143 my $result = $options{custom}->get(path => '/zixi/outputs.json?complete=1');
144
145 foreach my $entry (@{$result->{outputs}}) {
146 my $name = $entry->{name} . '/' . $entry->{requested_stream_id};
147 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
148 $name !~ /$self->{option_results}->{filter_name}/) {
149 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
150 next;
151 }
152
153 $self->{output_stream}->{$entry->{id}} = {
154 name => $name,
155 status => $entry->{status},
156 error => $mapping_output_status{$entry->{error_code}},
157 traffic_in => $entry->{stats}->{net_recv}->{bytes} * 8,
158 traffic_out => $entry->{stats}->{net_send}->{bytes} * 8,
159 dropped_in => $entry->{stats}->{net_recv}->{dropped},
160 };
161 }
162
163 if (scalar(keys %{$self->{output_stream}}) <= 0) {
164 $self->{output}->add_option_msg(short_msg => "No output found.");
165 $self->{output}->option_exit();
166 }
167
168 $self->{cache_name} = "zixi_" . $self->{mode} . '_' . $options{custom}->{hostname} . '_' . $options{custom}->{port} . '_' .
169 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
170 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
171 }
172
173 1;
174
175 __END__
176
177 =head1 MODE
178
179 Check output usage.
180
181 =over 8
182
183 =item B<--filter-name>
184
185 Filter name (can be a regexp).
186
187 =item B<--filter-counters>
188
189 Only display some counters (regexp can be used).
190 Example: --filter-counters='^status$'
191
192 =item B<--warning-*>
193
194 Warning threshold.
195 Can be: 'traffic-in', 'traffic-out', 'dropped-in'.
196
197 =item B<--critical-*>
198
199 Critical threshold.
200 Can be: 'traffic-in', 'traffic-out', 'dropped-in'.
201
202 =item B<--warning-status>
203
204 Define the conditions to match for the status to be WARNING (default: -)
205 You can use the following variables: %{name}, %{status}, %{error}.
206
207 =item B<--critical-status>
208
209 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /Connecting|Connected/i || %{error} !~ /none/i').
210 You can use the following variables: %{name}, %{status}, %{error}.
211
212 =back
213
214 =cut