Debian Codegraph @

src/cloud/microsoft/office365/management/mode/listservices.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 cloud::microsoft::office365::management::mode::listservices;
22
23 use base qw(centreon::plugins::templates::counter);
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 'filter-name:s' => { name => 'filter_name' }
35 });
36
37 return $self;
38 }
39
40 sub check_options {
41 my ($self, %options) = @_;
42 $self->SUPER::check_options(%options);
43 }
44
45 sub manage_selection {
46 my ($self, %options) = @_;
47
48 my $results = $options{custom}->get_services_health();
49 foreach my $service (@$results) {
50 next if (defined($self->{option_results}->{filter_service_name}) && $self->{option_results}->{filter_service_name} ne '' &&
51 $service->{service} !~ /$self->{option_results}->{filter_service_name}/);
52
53 $self->{services}->{ $service->{id} } = {
54 service_id => $service->{id},
55 service_name => $service->{service}
56 }
57 }
58 }
59
60 sub run {
61 my ($self, %options) = @_;
62
63 $self->manage_selection(%options);
64 foreach my $service (sort keys %{$self->{services}}) {
65 $self->{output}->output_add(
66 long_msg => sprintf(
67 "[service_id: %s] [service_name: %s]",
68 $self->{services}->{$service}->{service_id},
69 $self->{services}->{$service}->{service_name}
70 )
71 );
72 }
73
74 $self->{output}->output_add(
75 severity => 'OK',
76 short_msg => 'List services:'
77 );
78 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
79 $self->{output}->exit();
80 }
81
82 sub disco_format {
83 my ($self, %options) = @_;
84
85 $self->{output}->add_disco_format(elements => ['service_id', 'service_name']);
86 }
87
88 sub disco_show {
89 my ($self, %options) = @_;
90
91 $self->manage_selection(%options);
92 foreach my $service (sort keys %{$self->{services}}) {
93 $self->{output}->add_disco_entry(
94 service_id => $self->{services}->{$service}->{service_id},
95 service_name => $self->{services}->{$service}->{service_name}
96 );
97 }
98 }
99
100 1;
101
102 __END__
103
104 =head1 MODE
105
106 List services.
107
108 =over 8
109
110 =item B<--filter-name>
111
112 Filter service name (can be a regexp).
113
114 =back
115
116 =cut