Debian Codegraph @

src/apps/infor/ion/grid/mode/listnodes.pm

raw
1 #
2 # Copyright 2023 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::infor::ion::grid::mode::listnodes;
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 sub manage_selection {
44 my ($self, %options) = @_;
45
46 my $result = $options{custom}->request_api(
47 method => 'GET',
48 url_path => '/grid/rest/nodes'
49 );
50
51 my @nodes;
52 foreach my $entry (@{$result}) {
53 push @nodes, {
54 type => ucfirst(lc($entry->{entityType})),
55 name => $entry->{name},
56 application_name => $entry->{applicationName},
57 host_name => $entry->{hostName},
58 state => ($entry->{online}) ? "online" : "offline"
59 }
60 }
61
62 return \@nodes;
63 }
64
65 sub run {
66 my ($self, %options) = @_;
67
68 my $results = $self->manage_selection(%options);
69 foreach (@$results) {
70 $self->{output}->output_add(
71 long_msg => sprintf(
72 '[type: %s][name: %s][application_name: %s][host_name: %s][state: %s]',
73 $_->{type},
74 $_->{name},
75 $_->{application_name},
76 $_->{host_name},
77 $_->{state}
78 )
79 );
80 }
81
82 $self->{output}->output_add(
83 severity => 'OK',
84 short_msg => 'List nodes:'
85 );
86
87 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
88 $self->{output}->exit();
89 }
90
91 sub disco_format {
92 my ($self, %options) = @_;
93
94 $self->{output}->add_disco_format(elements => ['type', 'name', 'application_name', 'host_name', 'state']);
95 }
96
97 sub disco_show {
98 my ($self, %options) = @_;
99
100 my $results = $self->manage_selection(%options);
101 foreach (@$results) {
102 $self->{output}->add_disco_entry(%$_);
103 }
104 }
105
106 1;
107
108
109 =head1 MODE
110
111 List nodes.
112
113 =over 8
114
115 =back
116
117 =cut