Debian Codegraph @

src/apps/video/zixi/restapi/mode/feederinputusage.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::feederinputusage;
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 = 'active : ' . $self->{result_values}->{active} . ' [error: ' . ($self->{result_values}->{error} ne '' ? $self->{result_values}->{error} : '-') . ']';
33
34 return $msg;
35 }
36
37 sub custom_status_calc {
38 my ($self, %options) = @_;
39
40 $self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'};
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 => '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 => 'active' }, { 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 => $self->can('custom_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 ];
74 }
75
76 sub new {
77 my ($class, %options) = @_;
78 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
79 bless $self, $class;
80
81 $options{options}->add_options(arguments => {
82 'filter-name:s' => { name => 'filter_name' },
83 'warning-status:s' => { name => 'warning_status' },
84 'critical-status:s' => { name => 'critical_status' }
85 });
86
87 return $self;
88 }
89
90 sub check_options {
91 my ($self, %options) = @_;
92 $self->SUPER::check_options(%options);
93
94 $self->change_macros(macros => ['warning_status', 'critical_status']);
95 }
96
97 sub prefix_input_output {
98 my ($self, %options) = @_;
99
100 return "Input '" . $options{instance_value}->{name} . "' ";
101 }
102
103 sub manage_selection {
104 my ($self, %options) = @_;
105
106 $self->{input} = {};
107 my $result = $options{custom}->get(path => '/inputs_data');
108 foreach my $entry (@{$result->{inputs}}) {
109 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
110 $entry->{name} !~ /$self->{option_results}->{filter_name}/) {
111 $self->{output}->output_add(long_msg => "skipping '" . $entry->{source} . "': no matching filter.", debug => 1);
112 next;
113 }
114
115 $self->{input}->{$entry->{name}} = {
116 name => $entry->{name},
117 active => $entry->{active} == 0 ? 'false' : 'true',
118 error => $entry->{error},
119 traffic_in => $entry->{bytes} * 8,
120 };
121 }
122
123 if (scalar(keys %{$self->{input}}) <= 0) {
124 $self->{output}->add_option_msg(short_msg => "No input found.");
125 $self->{output}->option_exit();
126 }
127
128 $self->{cache_name} = "zixi_" . $self->{mode} . '_' . $options{custom}->{hostname} . '_' . $options{custom}->{port} . '_' .
129 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
130 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
131 }
132
133 1;
134
135 __END__
136
137 =head1 MODE
138
139 Check feeder input usage.
140
141 =over 8
142
143 =item B<--filter-name>
144
145 Filter name (can be a regexp).
146
147 =item B<--filter-counters>
148
149 Only display some counters (regexp can be used).
150 Example: --filter-counters='^status$'
151
152 =item B<--warning-*>
153
154 Warning threshold.
155 Can be: 'traffic-in'.
156
157 =item B<--critical-*>
158
159 Critical threshold.
160 Can be: 'traffic-in'.
161
162 =item B<--warning-status>
163
164 Define the conditions to match for the status to be WARNING (default: -)
165 You can use the following variables: %{name}, %{active}, %{error}.
166
167 =item B<--critical-status>
168
169 Define the conditions to match for the status to be CRITICAL (default: -).
170 You can use the following variables: %{name}, %{active}, %{error}.
171
172 =back
173
174 =cut