Debian Codegraph @

src/apps/infor/ion/grid/mode/application.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::application;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "state is '%s' [online: %s] [started: %s]",
34 $self->{result_values}->{state},
35 $self->{result_values}->{online},
36 $self->{result_values}->{started}
37 );
38 }
39
40 sub prefix_application_output {
41 my ($self, %options) = @_;
42
43 return sprintf(
44 "Application '%s' [description: %s] ",
45 $options{instance_value}->{name},
46 $options{instance_value}->{description}
47 );
48 }
49
50 sub prefix_global_output {
51 my ($self, %options) = @_;
52
53 return "Total applications ";
54 }
55
56 sub set_counters {
57 my ($self, %options) = @_;
58
59 $self->{maps_counters_type} = [
60 { name => 'global',
61 type => 0,
62 cb_prefix_output => 'prefix_global_output' },
63 { name => 'applications',
64 type => 1,
65 cb_prefix_output => 'prefix_application_output',
66 message_multiple => 'All applications are ok' },
67 ];
68
69 $self->{maps_counters}->{global} = [
70 { label => 'total',
71 nlabel => 'ion.grid.applications.total.count',
72 set => {
73 key_values => [{ name => 'total' }],
74 output_template => "Total : %s",
75 perfdatas => [{ template => '%d', min => 0 }] }
76 }
77 ];
78
79 $self->{maps_counters}->{applications} = [
80 {
81 label => 'status',
82 type => 2,
83 critical_default => '%{online} =~ /true/ && %{state} !~ /^(OK)/i',
84 set => {
85 key_values => [
86 { name => 'state' }, { name => 'online' }, { name => 'name' },
87 { name => 'description' }, { name => 'started' }
88 ],
89 closure_custom_output => $self->can('custom_status_output'),
90 closure_custom_perfdata => sub { return 0; },
91 closure_custom_threshold_check => \&catalog_status_threshold_ng
92 }
93 }
94 ];
95 }
96
97 sub new {
98 my ($class, %options) = @_;
99 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
100 bless $self, $class;
101
102 $options{options}->add_options(arguments => {
103 'filter-name:s' => { name => 'filter_name' }
104 });
105
106 return $self;
107 }
108
109 sub check_options {
110 my ($self, %options) = @_;
111 $self->SUPER::check_options(%options);
112 }
113
114 sub manage_selection {
115 my ($self, %options) = @_;
116
117 my $result = $options{custom}->request_api(
118 method => 'GET',
119 url_path => '/grid/rest/applications'
120 );
121
122 foreach my $entry (@{$result}) {
123 next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
124 && $entry->{name} !~ /$self->{option_results}->{filter_name}/);
125 $self->{applications}->{$entry->{name}} = {
126 name => $entry->{name},
127 description => $entry->{description},
128 online => ($entry->{online}) ? "true" : "false",
129 started => ($entry->{started}) ? "true" : "false",
130 state => $entry->{globalState}->{stateText}
131 }
132 }
133
134 if (scalar(keys %{$self->{applications}}) <= 0) {
135 $self->{output}->add_option_msg(short_msg => "No applications found");
136 $self->{output}->option_exit();
137 }
138
139 $self->{global}->{total} = scalar(keys %{$self->{applications}});
140 }
141
142 1;
143
144 __END__
145
146 =head1 MODE
147
148 Monitor the status of the application.
149
150 =over 8
151
152 =item B<--filter-name>
153
154 Define which applications should be monitored based on their names. This option will be treated as a regular expression.
155 Example: --filter-name='^application1$'
156
157 =item B<--warning-status>
158
159 Define the conditions to match for the status to be WARNING (default: '').
160 The condition can be written using special variables like %{state}, %{online}, %{started},
161 %{name} or %{description}. Regular expressions are supported.
162 Typical syntax: --warning-status='%{state} ne "OK"'
163
164 =item B<--critical-status>
165
166 Define the conditions to match for the status to be CRITICAL (default: '%{online} =~ /true/ && %{state} !~ /^(OK)/i').
167 The condition can be written using special variables like %{state}, %{online}, %{started},
168 %{name} or %{description}. Regular expressions are supported.
169 Typical syntax: --critical-status='%{started} ne "true"'
170
171 =item B<--warning-total>
172
173 Define the warning threshold for the total number of applications.
174
175 =item B<--critical-total>
176
177 Define the critical threshold for the total number of applications.
178
179 =back
180
181 =cut