Debian Codegraph @

src/hardware/devices/hikvision/nvr/isapi/mode/protocols.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 hardware::devices::hikvision::nvr::isapi::mode::protocols;
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_ng);
28
29 sub prefix_protocol_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "protocol '%s' ",
34 $options{instance}
35 );
36 }
37
38 sub set_counters {
39 my ($self, %options) = @_;
40
41 $self->{maps_counters_type} = [
42 { name => 'protocols', type => 1, cb_prefix_output => 'prefix_protocol_output', message_multiple => 'All protocols are ok', skipped_code => { -10 => 1 } }
43 ];
44
45 $self->{maps_counters}->{protocols} = [
46 {
47 label => 'status',
48 type => 2,
49 set => {
50 key_values => [ { name => 'enabled' }, { name => 'name' } ],
51 output_template => 'enabled: %s',
52 closure_custom_perfdata => sub { return 0; },
53 closure_custom_threshold_check => \&catalog_status_threshold_ng
54 }
55 }
56 ];
57 }
58
59 sub new {
60 my ($class, %options) = @_;
61 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
62 bless $self, $class;
63
64 $options{options}->add_options(arguments => {
65 'filter-name:s' => { name => 'filter_name' }
66 });
67
68 return $self;
69 }
70
71 sub manage_selection {
72 my ($self, %options) = @_;
73
74 my $result = $options{custom}->request_api(endpoint => '/ISAPI/Security/adminAccesses/capabilities', force_array => ['AdminAccessProtocol']);
75 if (!defined($result->{AdminAccessProtocol})) {
76 $self->{output}->add_option_msg(short_msg => "Cannot find protocol informations");
77 $self->{output}->option_exit();
78 }
79
80 $self->{protocols} = {};
81 foreach (@{$result->{AdminAccessProtocol}}) {
82 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
83 $_->{protocol}->{content} !~ /$self->{option_results}->{filter_name}/) {
84 $self->{output}->output_add(long_msg => "skipping protocol '" . $_->{protocol}->{content} . "'.", debug => 1);
85 next;
86 }
87
88 $self->{protocols}->{ $_->{protocol}->{content} } = {
89 name => $_->{protocol}->{content},
90 enabled => $_->{enabled}->{content}
91 };
92 }
93 }
94
95 1;
96
97 __END__
98
99 =head1 MODE
100
101 Check protocols.
102
103 =over 8
104
105 =item B<--filter-name>
106
107 Filter protocols by name (can be a regexp).
108
109 =item B<--unknown-status>
110
111 Define the conditions to match for the status to be UNKNOWN.
112 You can use the following variables: %{enabled}, %{name}
113
114 =item B<--warning-status>
115
116 Define the conditions to match for the status to be WARNING.
117 You can use the following variables: %{enabled}, %{name}
118
119 =item B<--critical-status>
120
121 Define the conditions to match for the status to be CRITICAL.
122 You can use the following variables: %{enabled}, %{name}
123 =back
124
125 =cut