| 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 os::windows::wsman::mode::listinterfaces; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($class, %options) = @_; |
| 30 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 31 |
bless $self, $class; |
| 32 |
|
| 33 |
$options{options}->add_options(arguments => {}); |
| 34 |
|
| 35 |
return $self; |
| 36 |
} |
| 37 |
|
| 38 |
sub check_options { |
| 39 |
my ($self, %options) = @_; |
| 40 |
$self->SUPER::init(%options); |
| 41 |
} |
| 42 |
|
| 43 |
my @labels = ('name', 'status', 'speed', 'enabled'); |
| 44 |
my $map_status = { |
| 45 |
0 => 'down', |
| 46 |
1 => 'connecting', |
| 47 |
2 => 'up', |
| 48 |
3 => 'disconnecting', |
| 49 |
4 => 'hardwareNotPresent', |
| 50 |
5 => 'hardwareDisable', |
| 51 |
6 => 'hardwarMalfunction', |
| 52 |
7 => 'mediaDisconnect', |
| 53 |
8 => 'auth', |
| 54 |
9 => 'authSucceeded', |
| 55 |
10 => 'AuthFailed', |
| 56 |
11 => 'invalidAddress', |
| 57 |
12 => 'credentialsRequired' |
| 58 |
}; |
| 59 |
|
| 60 |
sub manage_selection { |
| 61 |
my ($self, %options) = @_; |
| 62 |
|
| 63 |
my $entries = $options{wsman}->request( |
| 64 |
uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', |
| 65 |
wql_filter => 'Select DeviceID, Name, MaxSpeed, NetConnectionStatus, NetEnabled from Win32_NetworkAdapter', |
| 66 |
result_type => 'array' |
| 67 |
); |
| 68 |
|
| 69 |
my $results = {}; |
| 70 |
foreach (@$entries) { |
| 71 |
my $status = (!defined($_->{NetConnectionStatus}) || $_->{NetConnectionStatus} eq '') ? 0 : $_->{NetConnectionStatus}; |
| 72 |
$results->{ $_->{DeviceID} } = { |
| 73 |
name => $_->{Name}, |
| 74 |
speed => (!defined($_->{MaxSpeed}) || $_->{MaxSpeed} eq '') ? 0 : $_->{MaxSpeed}, |
| 75 |
status => $map_status->{$status}, |
| 76 |
enabled => (!defined($_->{NetEnabled}) || $_->{NetEnabled} eq '') ? 'false' : $_->{NetEnabled} |
| 77 |
}; |
| 78 |
} |
| 79 |
|
| 80 |
return $results; |
| 81 |
} |
| 82 |
|
| 83 |
sub run { |
| 84 |
my ($self, %options) = @_; |
| 85 |
|
| 86 |
my $results = $self->manage_selection(wsman => $options{wsman}); |
| 87 |
foreach my $instance (sort keys %$results) { |
| 88 |
$self->{output}->output_add(long_msg => |
| 89 |
join('', map("[$_: " . $results->{$instance}->{$_} . ']', @labels)) |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
$self->{output}->output_add( |
| 94 |
severity => 'OK', |
| 95 |
short_msg => 'List interfaces:' |
| 96 |
); |
| 97 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 98 |
$self->{output}->exit(); |
| 99 |
} |
| 100 |
|
| 101 |
sub disco_format { |
| 102 |
my ($self, %options) = @_; |
| 103 |
|
| 104 |
$self->{output}->add_disco_format(elements => [@labels]); |
| 105 |
} |
| 106 |
|
| 107 |
sub disco_show { |
| 108 |
my ($self, %options) = @_; |
| 109 |
|
| 110 |
my $results = $self->manage_selection(wsman => $options{wsman}); |
| 111 |
foreach (sort keys %$results) { |
| 112 |
$self->{output}->add_disco_entry( |
| 113 |
%{$results->{$_}} |
| 114 |
); |
| 115 |
} |
| 116 |
} |
| 117 |
1; |
| 118 |
|
| 119 |
__END__ |
| 120 |
|
| 121 |
=head1 MODE |
| 122 |
|
| 123 |
List interfaces. |
| 124 |
|
| 125 |
=over 8 |
| 126 |
|
| 127 |
=back |
| 128 |
|
| 129 |
=cut |