| 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::servicestatus; |
| 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_threshold { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $status = catalog_status_threshold_ng($self, %options); |
| 33 |
$self->{instance_mode}->{last_status} = $status; |
| 34 |
return $status; |
| 35 |
} |
| 36 |
|
| 37 |
sub custom_status_output { |
| 38 |
my ($self, %options) = @_; |
| 39 |
|
| 40 |
my $msg = "status is '" . $self->{result_values}->{status} . "'"; |
| 41 |
if (!$self->{output}->is_status(value => $self->{instance_mode}->{last_status}, compare => 'ok', litteral => 1)) { |
| 42 |
$msg .= sprintf( |
| 43 |
' [issue: %s %s %s]', |
| 44 |
$self->{result_values}->{issue_startDateTime}, |
| 45 |
$self->{result_values}->{issue_title}, |
| 46 |
$self->{result_values}->{classification} |
| 47 |
); |
| 48 |
} |
| 49 |
return $msg; |
| 50 |
} |
| 51 |
|
| 52 |
sub prefix_service_output { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
return "Service '" . $options{instance_value}->{service_name} . "' "; |
| 56 |
} |
| 57 |
|
| 58 |
sub set_counters { |
| 59 |
my ($self, %options) = @_; |
| 60 |
|
| 61 |
$self->{maps_counters_type} = [ |
| 62 |
{ name => 'services', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'All services are ok' } |
| 63 |
]; |
| 64 |
|
| 65 |
$self->{maps_counters}->{services} = [ |
| 66 |
{ label => 'status', type => 2, critical_default => '%{status} !~ /serviceOperational|serviceRestored/i', set => { |
| 67 |
key_values => [ |
| 68 |
{ name => 'status' }, { name => 'service_name' }, { name => 'classification' }, |
| 69 |
{ name => 'issue_startDateTime' }, { name => 'issue_title' } |
| 70 |
], |
| 71 |
closure_custom_output => $self->can('custom_status_output'), |
| 72 |
closure_custom_perfdata => sub { return 0; }, |
| 73 |
closure_custom_threshold_check => $self->can('custom_status_threshold'), |
| 74 |
} |
| 75 |
} |
| 76 |
]; |
| 77 |
} |
| 78 |
|
| 79 |
sub new { |
| 80 |
my ($class, %options) = @_; |
| 81 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 82 |
bless $self, $class; |
| 83 |
|
| 84 |
$options{options}->add_options(arguments => { |
| 85 |
'filter-service-name:s' => { name => 'filter_service_name' } |
| 86 |
}); |
| 87 |
|
| 88 |
return $self; |
| 89 |
} |
| 90 |
|
| 91 |
sub manage_selection { |
| 92 |
my ($self, %options) = @_; |
| 93 |
|
| 94 |
my $results = $options{custom}->get_services_health(); |
| 95 |
|
| 96 |
$self->{services} = {}; |
| 97 |
foreach my $service (@$results) { |
| 98 |
if (defined($self->{option_results}->{filter_service_name}) && $self->{option_results}->{filter_service_name} ne '' && |
| 99 |
$service->{service} !~ /$self->{option_results}->{filter_service_name}/) { |
| 100 |
$self->{output}->output_add(long_msg => "skipping '" . $service->{service} . "': no matching filter name.", debug => 1); |
| 101 |
next; |
| 102 |
} |
| 103 |
$self->{services}->{ $service->{id} }->{service_name} = $service->{service}; |
| 104 |
$self->{services}->{ $service->{id} }->{status} = $service->{status}; |
| 105 |
$self->{services}->{ $service->{id} }->{issue_startDateTime} = '-'; |
| 106 |
$self->{services}->{ $service->{id} }->{issue_title} = '-'; |
| 107 |
$self->{services}->{ $service->{id} }->{classification} = '-'; |
| 108 |
if (defined($service->{issues}) && scalar(@{$service->{issues}}) > 0) { |
| 109 |
my $issue = pop @{$service->{issues}}; |
| 110 |
$self->{services}->{ $service->{id} }->{issue_startDateTime} = $issue->{startDateTime}; |
| 111 |
$self->{services}->{ $service->{id} }->{issue_title} = $issue->{title}; |
| 112 |
$self->{services}->{ $service->{id} }->{classification} = $issue->{classification}; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
if (scalar(keys %{$self->{services}}) <= 0) { |
| 117 |
$self->{output}->add_option_msg(short_msg => 'No services found.'); |
| 118 |
$self->{output}->option_exit(); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
1; |
| 123 |
|
| 124 |
__END__ |
| 125 |
|
| 126 |
=head1 MODE |
| 127 |
|
| 128 |
Check services status. |
| 129 |
|
| 130 |
=over 8 |
| 131 |
|
| 132 |
=item B<--filter-service-name> |
| 133 |
|
| 134 |
Filter services (can be a regexp). |
| 135 |
|
| 136 |
=item B<--warning-status> |
| 137 |
|
| 138 |
Define the conditions to match for the status to be WARNING. |
| 139 |
You can use the following variables: %{service_name}, %{status}, %{classification} |
| 140 |
|
| 141 |
=item B<--critical-status> |
| 142 |
|
| 143 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /serviceOperational|serviceRestored/i'). |
| 144 |
You can use the following variables: %{service_name}, %{status}, %{classification} |
| 145 |
|
| 146 |
=back |
| 147 |
|
| 148 |
=cut |