Debian Codegraph @

src/apps/infor/ion/grid/mode/node.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 apps::infor::ion::grid::mode::node;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::misc;
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
29
30 sub custom_heap_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'Heap usage: %s%s/%s%s (%.2f%%)',
35 $self->{perfdata}->change_bytes(value => $self->{result_values}->{heap_used}),
36 $self->{perfdata}->change_bytes(value => $self->{result_values}->{heap_max}),
37 $self->{result_values}->{heap_percent}
38 );
39 }
40
41 sub custom_status_output {
42 my ($self, %options) = @_;
43
44 return sprintf(
45 "state is '%s'",
46 $self->{result_values}->{state}
47 );
48 }
49
50 sub prefix_node_output {
51 my ($self, %options) = @_;
52
53 return sprintf(
54 "Node '%s' with PID '%s' from application '%s' on host '%s' ",
55 $options{instance_value}->{name},
56 $options{instance_value}->{pid},
57 $options{instance_value}->{application_name},
58 $options{instance_value}->{host_name}
59 );
60 }
61
62 sub set_counters {
63 my ($self, %options) = @_;
64
65 $self->{maps_counters_type} = [
66 { name => 'nodes',
67 type => 1,
68 cb_prefix_output => 'prefix_node_output',
69 message_multiple => 'All nodes are ok' },
70 ];
71
72 $self->{maps_counters}->{nodes} = [
73 {
74 label => 'status',
75 type => 2,
76 warning_default => '%{state} !~ /online/',
77 set => {
78 key_values => [
79 { name => 'state' }, { name => 'name' }, { name => 'host_name' },
80 { name => 'application_name' }, { name => 'type' }, { name => 'pid' }
81 ],
82 closure_custom_output => $self->can('custom_status_output'),
83 closure_custom_perfdata => sub { return 0; },
84 closure_custom_threshold_check => \&catalog_status_threshold_ng
85 }
86 },
87 { label => 'log-error', nlabel => 'node.log.error.count', set => {
88 key_values => [{ name => 'logger_error' }, { name => 'pid' }],
89 output_template => 'Log error: %d',
90 perfdatas => [
91 { template => '%d', min => 0,
92 label_extra_instance => 1, instance_use => 'pid' }
93 ]
94 }
95 },
96 { label => 'log-warning', nlabel => 'node.log.warning.count', set => {
97 key_values => [{ name => 'logger_warning' }, { name => 'pid' }],
98 output_template => 'Log warning: %d',
99 perfdatas => [
100 { template => '%d', min => 0,
101 label_extra_instance => 1, instance_use => 'pid' }
102 ]
103 }
104 },
105 { label => 'uptime', nlabel => 'node.uptime.seconds', set => {
106 key_values => [{ name => 'uptime' }, { name => 'uptime_human' }],
107 output_template => 'Uptime: %s',
108 output_use => 'uptime_human',
109 closure_custom_perfdata => sub { return 0; },
110 }
111 },
112 { label => 'cpu-usage', nlabel => 'node.cpu.usage.percentage', set => {
113 key_values => [{ name => 'cpu_percent' }, { name => 'pid' }],
114 output_template => 'CPU usage: %.2f%%',
115 perfdatas => [
116 { template => '%.2f', min => 0, max => 100, unit => '%',
117 label_extra_instance => 1, instance_use => 'pid' }
118 ]
119 }
120 },
121 { label => 'heap-usage', nlabel => 'node.heap.usage.percentage', set => {
122 key_values => [{ name => 'heap_percent' }, { name => 'heap_used' },
123 { name => 'heap_max' }, { name => 'pid' }],
124 closure_custom_output => $self->can('custom_heap_output'),
125 perfdatas => [
126 { template => '%.2f', min => 0, max => 100, unit => '%',
127 label_extra_instance => 1, instance_use => 'pid' }
128 ]
129 }
130 }
131 ];
132 }
133
134 sub new {
135 my ($class, %options) = @_;
136 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
137 bless $self, $class;
138
139 $options{options}->add_options(arguments => {
140 'filter-type:s' => { name => 'filter_type' },
141 'filter-name:s' => { name => 'filter_name' },
142 'filter-application-name:s' => { name => 'filter_application_name' },
143 'filter-host-name:s' => { name => 'filter_host_name' }
144 });
145
146 return $self;
147 }
148
149 sub check_options {
150 my ($self, %options) = @_;
151 $self->SUPER::check_options(%options);
152 }
153
154 sub manage_selection {
155 my ($self, %options) = @_;
156
157 my $result = $options{custom}->request_api(
158 method => 'GET',
159 url_path => '/grid/rest/nodes'
160 );
161
162 foreach my $entry (@{$result}) {
163 next if (defined($self->{option_results}->{filter_type})
164 && $self->{option_results}->{filter_type} ne ''
165 && $entry->{entityType} !~ /$self->{option_results}->{filter_type}/i);
166 next if (defined($self->{option_results}->{filter_name})
167 && $self->{option_results}->{filter_name} ne ''
168 && $entry->{name} !~ /$self->{option_results}->{filter_name}/);
169 next if (defined($self->{option_results}->{filter_host_name})
170 && $self->{option_results}->{filter_host_name} ne ''
171 && $entry->{hostName} !~ /$self->{option_results}->{filter_host_name}/);
172 next if (defined($self->{option_results}->{filter_application_name})
173 && $self->{option_results}->{filter_application_name} ne ''
174 && $entry->{applicationName} !~ /$self->{option_results}->{filter_application_name}/);
175 $self->{nodes}->{$entry->{jvmId}} = {
176 type => ucfirst(lc($entry->{entityType})),
177 name => $entry->{name},
178 application_name => $entry->{applicationName},
179 host_name => $entry->{hostName},
180 uptime => ($entry->{upTime} > 0) ? $entry->{upTime} / 1000 : 0,
181 uptime_human => ($entry->{upTime} > 0) ? centreon::plugins::misc::change_seconds(value => $entry->{upTime} / 1000) : 0,
182 logger_error => $entry->{loggerErrorCount},
183 logger_warning => $entry->{loggerWarningCount},
184 heap_used => $entry->{memoryUsed},
185 heap_max => $entry->{memoryMax},
186 heap_percent => $entry->{memoryUsed} / $entry->{memoryMax} * 100,
187 cpu_percent => $entry->{cpuPercent},
188 state => ($entry->{online}) ? "online" : "offline"
189 };
190 $self->{nodes}->{$entry->{jvmId}}->{pid} = $1 if ($entry->{jvmId} =~ /-(\d+)$/); # 10.1.2.3:50156-5152
191 }
192
193 if (scalar(keys %{$self->{nodes}}) <= 0) {
194 $self->{output}->add_option_msg(short_msg => "No nodes found");
195 $self->{output}->option_exit();
196 }
197 }
198
199 1;
200
201 __END__
202
203 =head1 MODE
204
205 Monitor the status and the statistics of the nodes.
206
207 =over 8
208
209 =item B<--filter-type>
210
211 Define which nodes should be monitored based on the their type. This option will be treated as a regular expression.
212
213 =item B<--filter-name>
214
215 Define which nodes should be monitored based on the their name. This option will be treated as a regular expression.
216
217 =item B<--filter-application-name>
218
219 Define which applications should be monitored based on the their name. This option will be treated as a regular expression.
220
221 =item B<--filter-host-name>
222
223 Define which hosts should be monitored based on the their name. This option will be treated as a regular expression.
224
225 =item B<--warning-status>
226
227 Define the conditions to match to return a warning status (default: "%{state} !~ /online/").
228 The condition can be written using the following macros: %{state}, %{name}, %{host_name},
229 %{application_name}, %{type}.
230
231 =item B<--critical-status>
232
233 Define the conditions to match to return a critical status.
234 The condition can be written using the following macros: %{state}, %{name}, %{host_name},
235 %{application_name}, %{type}.
236
237 =item B<--warning-*> B<--critical-*>
238
239 Thresholds for 'log-error', 'log-warning', 'uptime' (s), 'cpu-usage', 'heap-usage' (%).
240
241 =back
242
243 =cut