Debian Codegraph @

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