Debian Codegraph @

src/network/paloalto/ssh/mode/interfaces.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 network::paloalto::ssh::mode::interfaces;
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_ng);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'state: %s [type: %s]',
35 $self->{result_values}->{state},
36 $self->{result_values}->{type}
37 );
38 }
39
40 sub set_counters {
41 my ($self, %options) = @_;
42
43 $self->{maps_counters_type} = [
44 { name => 'global', type => 0 },
45 { name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interface are ok', skipped_code => { -10 => 1 } }
46 ];
47
48 $self->{maps_counters}->{global} = [
49 { label => 'total', nlabel => 'interfaces.total.count', display_ok => 0, set => {
50 key_values => [ { name => 'total' } ],
51 output_template => 'total interfaces: %s',
52 perfdatas => [
53 { template => '%s', min => 0 }
54 ]
55 }
56 },
57 ];
58
59 $self->{maps_counters}->{interface} = [
60 { label => 'status', type => 2, critical_default => '%{state} ne "up"', set => {
61 key_values => [
62 { name => 'state' }, { name => 'type' },
63 { name => 'ha_state' }, { name => 'display' }
64 ],
65 closure_custom_output => $self->can('custom_status_output'),
66 closure_custom_perfdata => sub { return 0; },
67 closure_custom_threshold_check => \&catalog_status_threshold_ng
68 }
69 }
70 ];
71 }
72
73 sub prefix_interface_output {
74 my ($self, %options) = @_;
75
76 return "interface '" . $options{instance_value}->{display} . "' ";
77 }
78
79 sub new {
80 my ($class, %options) = @_;
81 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
82 bless $self, $class;
83
84 $options{options}->add_options(arguments => {
85 'filter-name:s' => { name => 'filter_name' }
86 });
87
88 return $self;
89 }
90
91 sub manage_selection {
92 my ($self, %options) = @_;
93
94 my $result = $options{custom}->execute_command(command => 'show high-availability state');
95 my $ha_state = defined($result->{group}->{'local-info'}->{state}) ? $result->{group}->{'local-info'}->{state} : 'disabled';
96
97 $result = $options{custom}->execute_command(command => 'show interface all', ForceArray => ['entry']);
98
99 $self->{global} = { total => 0 };
100 $self->{interface} = {};
101 foreach (@{$result->{hw}->{entry}}) {
102 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
103 $_->{name} !~ /$self->{option_results}->{filter_name}/) {
104 $self->{output}->output_add(long_msg => "skipping interface '" . $_->{name} . "': no matching filter.", debug => 1);
105 next;
106 }
107
108 $self->{interface}->{$_->{name}} = {
109 display => $_->{name},
110 type => $_->{type},
111 state => $_->{state},
112 ha_state => $ha_state
113 };
114 $self->{global}->{total}++;
115 }
116 }
117
118 1;
119
120 __END__
121
122 =head1 MODE
123
124 Check interfaces.
125
126 =over 8
127
128 =item B<--filter-name>
129
130 Filter interface name (can be a regexp).
131
132 =item B<--unknown-status>
133
134 Define the conditions to match for the status to be UNKNOWN (default: '').
135 You can use the following variables: %{state}, %{type}, %{ha_state}, %{display}
136
137 =item B<--warning-status>
138
139 Define the conditions to match for the status to be WARNING (default: '').
140 You can use the following variables: %{state}, %{type}, %{ha_state}, %{display}
141
142 =item B<--critical-status>
143
144 Define the conditions to match for the status to be CRITICAL (default: '%{state} ne "active"').
145 You can use the following variables: %{state}, %{type}, %{ha_state}, %{display}
146
147 =item B<--warning-*> B<--critical-*>
148
149 Thresholds.
150 Can be: 'total'.
151
152 =back
153
154 =cut