Debian Codegraph @

src/apps/sailpoint/identitynow/restapi/mode/sourcehealth.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::sailpoint::identitynow::restapi::mode::sourcehealth;
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 set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } },
34 { name => 'sources', type => 1, cb_prefix_output => 'custom_prefix_output', message_multiple => 'All sources health are ok' },
35 ];
36
37 $self->{maps_counters}->{global} = [];
38 foreach ('healthy', 'error', 'failure', 'unchecked') {
39 push @{$self->{maps_counters}->{global}}, {
40 label => 'sources-' . $_, nlabel => 'sources.status.' . $_ . '.count', set => {
41 key_values => [ { name => $_ } ],
42 output_template => $_ . ': %s',
43 perfdatas => [
44 { template => '%s' }
45 ]
46 }
47 };
48 }
49
50 $self->{maps_counters}->{sources} = [
51 { label => 'health-status', type => 2, critical_default => '%{status} ne "SOURCE_STATE_HEALTHY"', set => {
52 key_values => [ { name => 'status' }, { name => 'id' }, { name => 'name' } ],
53 output_template => "health status is '%s'",
54 closure_custom_perfdata => sub { return 0; },
55 closure_custom_threshold_check => \&catalog_status_threshold_ng
56 }
57 }
58 ];
59 }
60
61 sub prefix_global_output {
62 my ($self, %options) = @_;
63
64 return 'Number of sources ';
65 }
66
67 sub custom_prefix_output {
68 my ($self, %options) = @_;
69
70 return "Source '" . $options{instance_value}->{name} . "' ";
71 }
72
73 sub new {
74 my ($class, %options) = @_;
75 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
76 bless $self, $class;
77
78 $options{options}->add_options(arguments => {
79 'source-id:s' => { name => 'source_id' },
80 'filter-name:s' => { name => 'filter_name' },
81 'filter-type:s' => { name => 'filter_type' }
82 });
83
84 return $self;
85 }
86
87 sub set_options {
88 my ($self, %options) = @_;
89 }
90
91 sub manage_selection {
92 my ($self, %options) = @_;
93
94 $self->{global} = { healthy => 0, error => 0, failure => 0, unchecked => 0 };
95
96 my $sources = $options{custom}->get_sources(id => $self->{option_results}->{source_id});
97
98 foreach my $source (@{$sources}) {
99 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
100 $source->{name} !~ /$self->{option_results}->{filter_name}/) {
101 $self->{output}->output_add(long_msg => "skipping '" . $source->{name} . "': no matching filter name.", debug => 1);
102 next;
103 }
104 if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
105 $source->{type} !~ /$self->{option_results}->{filter_type}/) {
106 $self->{output}->output_add(long_msg => "skipping '" . $source->{type} . "': no matching filter type.", debug => 1);
107 next;
108 }
109
110 $self->{global}->{healthy}++ if ($source->{status} eq 'SOURCE_STATE_HEALTHY');
111 $self->{global}->{error}++ if ($source->{status} =~ /SOURCE_STATE_ERROR/);
112 $self->{global}->{failure}++ if ($source->{status} =~ /SOURCE_STATE_FAILURE/);
113 $self->{global}->{unchecked}++ if ($source->{status} =~ /SOURCE_STATE_UNCHECKED/);
114
115 $self->{sources}->{$source->{id}} = {
116 id => $source->{id},
117 name => $source->{name},
118 status => $source->{status}
119 };
120 }
121 }
122
123 1;
124
125 __END__
126
127 =head1 MODE
128
129 Check sources health status.
130
131 More information on 'https://developer.sailpoint.com/idn/api/v3/list-sources'.
132
133 =over 8
134
135 =item B<--source-id>
136
137 Define source ID to retrieve only one source health status (useful with service discovery).
138
139 =item B<--filter-name>
140
141 Filter source name (can be a regexp).
142
143 =item B<--filter-type>
144
145 Filter source type (can be a regexp).
146
147 =item B<--warning-health-status>
148
149 Set warning threshold for each source health status (default: none).
150
151 =item B<--critical-health-status>
152
153 Set critical threshold for each source health status (default: '%{status} ne "SOURCE_STATE_HEALTHY"').
154
155 =item B<--warning-sources-*> B<--critical-sources-*>
156
157 Set threshold for each status counter.
158 Can be: 'healthy', 'error', 'failure', 'unchecked'.
159
160 =back
161
162 =cut