Debian Codegraph @

src/apps/video/openheadend/snmp/mode/nodeusage.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::nodeusage;
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 = 'dependancy 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}->{dep_status} = $options{new_datas}->{$self->{instance} . '_nodeDepStatus'};
40 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
41 return 0;
42 }
43
44 sub set_counters {
45 my ($self, %options) = @_;
46
47 $self->{maps_counters_type} = [
48 { name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes are ok', skipped_code => { -10 => 1 } }
49 ];
50
51 $self->{maps_counters}->{node} = [
52 { label => 'status', threshold => 0, set => {
53 key_values => [ { name => 'nodeDepStatus' }, { name => 'display' } ],
54 closure_custom_calc => $self->can('custom_status_calc'),
55 closure_custom_output => $self->can('custom_status_output'),
56 closure_custom_perfdata => sub { return 0; },
57 closure_custom_threshold_check => \&catalog_status_threshold,
58 }
59 },
60 { label => 'bitrate', set => {
61 key_values => [ { name => 'nodeBitrate' }, { name => 'display' } ],
62 output_template => 'bitRate : %s %s/s',
63 output_change_bytes => 2,
64 perfdatas => [
65 { label => 'bitrate', value => 'nodeBitrate', template => '%d',
66 unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' },
67 ],
68 }
69 },
70 ];
71 }
72
73 sub new {
74 my ($class, %options) = @_;
75 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
76 bless $self, $class;
77
78 $options{options}->add_options(arguments =>
79 {
80 "filter-name:s" => { name => 'filter_name' },
81 "warning-status:s" => { name => 'warning_status', default => '' },
82 "critical-status:s" => { name => 'critical_status', default => '%{dep_status} =~ /false/i' },
83 });
84
85 return $self;
86 }
87
88 sub check_options {
89 my ($self, %options) = @_;
90 $self->SUPER::check_options(%options);
91
92 $self->change_macros(macros => ['warning_status', 'critical_status']);
93 }
94
95 sub prefix_node_output {
96 my ($self, %options) = @_;
97
98 return "Node '" . $options{instance_value}->{display} . "' ";
99 }
100
101 my %map_type = (1 => 'net', 2 => 'dvb', 3 => 'file', 4 => 'circular-file',
102 5 => 'directory', 6 => 'asi-rx', 7 => 'rtsp', 8 => 'jpeg',
103 9 => 'video', 10 => 'audio', 11 => 'video-rx', 12 => 'extract'
104 );
105 my %map_status = (1 => 'true', 2 => 'false');
106 my $mapping = {
107 nodeType => { oid => '.1.3.6.1.4.1.35902.1.4.1.1.3', map => \%map_type },
108 nodeDepStatus => { oid => '.1.3.6.1.4.1.35902.1.4.1.1.5', map => \%map_status },
109 nodeName => { oid => '.1.3.6.1.4.1.35902.1.4.1.1.7' },
110 nodeBitrate => { oid => '.1.3.6.1.4.1.35902.1.4.2.1.9' },
111 };
112
113 sub manage_selection {
114 my ($self, %options) = @_;
115
116 $self->{node} = {};
117 my $snmp_result = $options{snmp}->get_multiple_table(
118 oids => [
119 { oid => $mapping->{nodeType}->{oid} },
120 { oid => $mapping->{nodeDepStatus}->{oid} },
121 { oid => $mapping->{nodeName}->{oid} },
122 { oid => $mapping->{nodeBitrate}->{oid} },
123 ],
124 return_type => 1, nothing_quit => 1);
125
126 foreach my $oid (keys %{$snmp_result}) {
127 next if ($oid !~ /^$mapping->{nodeName}->{oid}\.(.*)$/);
128 my $instance = $1;
129 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
130
131 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
132 $result->{nodeName} !~ /$self->{option_results}->{filter_name}/) {
133 $self->{output}->output_add(long_msg => "skipping '" . $result->{nodeName} . "': no matching filter.", debug => 1);
134 next;
135 }
136
137 $result->{nodeBitrate} = !defined($result->{nodeBitrate}) || $result->{nodeBitrate} == 0 ? undef : $result->{nodeBitrate};
138 $self->{node}->{$instance} = {
139 display => $result->{nodeName},
140 %$result
141 };
142 }
143
144 if (scalar(keys %{$self->{node}}) <= 0) {
145 $self->{output}->add_option_msg(short_msg => "No node found.");
146 $self->{output}->option_exit();
147 }
148 }
149
150 1;
151
152 __END__
153
154 =head1 MODE
155
156 Check node usage.
157
158 =over 8
159
160 =item B<--filter-counters>
161
162 Only display some counters (regexp can be used).
163 Example: --filter-counters='^status$'
164
165 =item B<--filter-name>
166
167 Filter node name (can be a regexp).
168
169 =item B<--warning-status>
170
171 Define the conditions to match for the status to be WARNING.
172 You can use the following variables: %{dep_status}, %{display}
173
174 =item B<--critical-status>
175
176 Define the conditions to match for the status to be CRITICAL (default: '%{dep_status} =~ /false/i').
177 You can use the following variables: %{dep_status}, %{display}
178
179 =item B<--warning-*>
180
181 Warning threshold.
182 Can be: 'bitrate'.
183
184 =item B<--critical-*>
185
186 Critical threshold.
187 Can be: 'bitrate'.
188
189 =back
190
191 =cut