Debian Codegraph @

src/apps/video/openheadend/snmp/mode/operationstatus.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::openheadend::snmp::mode::operationstatus;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = 'status : ' . $self->{result_values}->{dep_status};
33 return $msg;
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_operationOpStatus'};
40 $self->{result_values}->{dep_status} = $options{new_datas}->{$self->{instance} . '_operationDepStatus'};
41 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
42 return 0;
43 }
44
45 sub set_counters {
46 my ($self, %options) = @_;
47
48 $self->{maps_counters_type} = [
49 { name => 'operation', type => 1, cb_prefix_output => 'prefix_operation_output', message_multiple => 'All operations are ok', skipped_code => { -10 => 1 } }
50 ];
51
52 $self->{maps_counters}->{operation} = [
53 { label => 'status', threshold => 0, set => {
54 key_values => [ { name => 'operationOpStatus' }, { name => 'operationDepStatus' }, { name => 'display' } ],
55 closure_custom_calc => $self->can('custom_status_calc'),
56 closure_custom_output => $self->can('custom_status_output'),
57 closure_custom_perfdata => sub { return 0; },
58 closure_custom_threshold_check => \&catalog_status_threshold,
59 }
60 },
61 ];
62 }
63
64 sub new {
65 my ($class, %options) = @_;
66 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
67 bless $self, $class;
68
69 $options{options}->add_options(arguments =>
70 {
71 "filter-id:s" => { name => 'filter_id' },
72 "warning-status:s" => { name => 'warning_status', default => '' },
73 "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /false/i' },
74 });
75
76 return $self;
77 }
78
79 sub check_options {
80 my ($self, %options) = @_;
81 $self->SUPER::check_options(%options);
82
83 $self->change_macros(macros => ['warning_status', 'critical_status']);
84 }
85
86 sub prefix_operation_output {
87 my ($self, %options) = @_;
88
89 return "Operation '" . $options{instance_value}->{display} . "' ";
90 }
91
92 my %map_type = (1 => 'demux', 2 => 'monitor-pid', 3 => 'monitor-type',
93 4 => 'playout-file', 5 => 'playout-circular-file', 6 => 'monitor-sid',
94 7 => 'playout-directory', 8 => 'hint', 9 => 'transcode-avc', 10 => 'transcode-mp2',
95 11 => 'transcode-aac', 12 => 'transmit-input', 13 => 'transmit-output',
96 14 => 'transcode-a52', 15 => 'grid-input', 16 => 'grid-acquire-mono',
97 17 => 'grid-acquire-stereo', 18 => 'acquire-mono', 19 => 'acquire-stereo',
98 20 => 'mux-input', 21 => 'remap-pid', 22 => 'remap-sid',
99 23 => 'mosaic', 24 => 'hint-scte35',
100 );
101 my %map_status = (1 => 'true', 2 => 'false');
102 my $mapping = {
103 operationType => { oid => '.1.3.6.1.4.1.35902.1.6.1.1.3', map => \%map_type },
104 operationDepStatus => { oid => '.1.3.6.1.4.1.35902.1.6.1.1.5', map => \%map_status },
105 operationOpStatus => { oid => '.1.3.6.1.4.1.35902.1.6.1.1.7', map => \%map_status },
106 };
107
108 sub manage_selection {
109 my ($self, %options) = @_;
110
111 $self->{operation} = {};
112 my $snmp_result = $options{snmp}->get_multiple_table(
113 oids => [
114 { oid => $mapping->{operationType}->{oid} },
115 { oid => $mapping->{operationDepStatus}->{oid} },
116 { oid => $mapping->{operationOpStatus}->{oid} },
117 ],
118 return_type => 1, nothing_quit => 1);
119
120 foreach my $oid (keys %{$snmp_result}) {
121 next if ($oid !~ /^$mapping->{operationOpStatus}->{oid}\.(.*)$/);
122 my $instance = $1;
123 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
124
125 if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' &&
126 $instance !~ /$self->{option_results}->{filter_id}/) {
127 $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching filter.", debug => 1);
128 next;
129 }
130 if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
131 $result->{operationType} !~ /$self->{option_results}->{filter_type}/) {
132 $self->{output}->output_add(long_msg => "skipping '" . $result->{operationType} . "': no matching filter.", debug => 1);
133 next;
134 }
135
136 $self->{operation}->{$instance} = {
137 display => $instance,
138 %$result
139 };
140 }
141
142 if (scalar(keys %{$self->{operation}}) <= 0) {
143 $self->{output}->add_option_msg(short_msg => "No operation found.");
144 $self->{output}->option_exit();
145 }
146 }
147
148 1;
149
150 __END__
151
152 =head1 MODE
153
154 Check operation status.
155
156 =over 8
157
158 =item B<--filter-id>
159
160 Filter by operation ID (can be a regexp).
161
162 =item B<--filter-type>
163
164 Filter by operation type (can be a regexp).
165
166 =item B<--warning-status>
167
168 Define the conditions to match for the status to be WARNING.
169 You can use the following variables: %{status}, %{dep_status}, %{display}
170
171 =item B<--critical-status>
172
173 Define the conditions to match for the status to be CRITICAL (default: '%{dep_status} =~ /false/i').
174 You can use the following variables: %{status}, %{dep_status}, %{display}
175
176 =back
177
178 =cut