| 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 notification::centreon::opentickets::api::mode::openservice; |
| 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 |
'rule-name:s' => { name => 'rule_name' }, |
| 35 |
'contact-name:s' => { name => 'contact_name' }, |
| 36 |
'contact-alias:s' => { name => 'contact_alias' }, |
| 37 |
'contact-email:s' => { name => 'contact_email' }, |
| 38 |
'host-id:s' => { name => 'host_id' }, |
| 39 |
'host-name:s' => { name => 'host_name' }, |
| 40 |
'host-alias:s' => { name => 'host_alias' }, |
| 41 |
'service-id:s' => { name => 'service_id' }, |
| 42 |
'service-description:s' => { name => 'service_description' }, |
| 43 |
'service-output:s' => { name => 'service_output' }, |
| 44 |
'service-state:s' => { name => 'service_state' }, |
| 45 |
'last-service-state-change:s' => { name => 'last_service_state_change' }, |
| 46 |
'extra-property:s%' => { name => 'extra_property' }, |
| 47 |
'select:s%' => { name => 'select' } |
| 48 |
}); |
| 49 |
|
| 50 |
return $self; |
| 51 |
} |
| 52 |
|
| 53 |
sub check_options { |
| 54 |
my ($self, %options) = @_; |
| 55 |
$self->SUPER::init(%options); |
| 56 |
|
| 57 |
if (!defined($self->{option_results}->{rule_name}) || $self->{option_results}->{rule_name} eq '') { |
| 58 |
$self->{output}->add_option_msg(short_msg => 'Set --rule-name option'); |
| 59 |
$self->{output}->option_exit(); |
| 60 |
} |
| 61 |
if (!defined($self->{option_results}->{host_id}) || $self->{option_results}->{host_id} eq '') { |
| 62 |
$self->{output}->add_option_msg(short_msg => 'Set --host-id option'); |
| 63 |
$self->{output}->option_exit(); |
| 64 |
} |
| 65 |
if (!defined($self->{option_results}->{service_id}) || $self->{option_results}->{service_id} eq '') { |
| 66 |
$self->{output}->add_option_msg(short_msg => 'Set --service-id option'); |
| 67 |
$self->{output}->option_exit(); |
| 68 |
} |
| 69 |
if (!defined($self->{option_results}->{service_state}) || $self->{option_results}->{service_state} eq '') { |
| 70 |
$self->{output}->add_option_msg(short_msg => 'Set --service-state option'); |
| 71 |
$self->{output}->option_exit(); |
| 72 |
} |
| 73 |
if (!defined($self->{option_results}->{service_output})) { |
| 74 |
$self->{output}->add_option_msg(short_msg => 'Set --service-output option'); |
| 75 |
$self->{output}->option_exit(); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
sub run { |
| 80 |
my ($self, %options) = @_; |
| 81 |
|
| 82 |
my $extra_properties = {}; |
| 83 |
foreach (keys %{$self->{option_results}->{extra_property}}) { |
| 84 |
$extra_properties->{$_} = $self->{option_results}->{extra_property}->{$_}; |
| 85 |
} |
| 86 |
|
| 87 |
my $select = {}; |
| 88 |
foreach (keys %{$self->{option_results}->{select}}) { |
| 89 |
$select->{$_} = $self->{option_results}->{select}->{$_}; |
| 90 |
} |
| 91 |
|
| 92 |
my $properties = {}; |
| 93 |
foreach ('contact_name', 'contact_alias', 'contact_email', 'host_name', 'host_alias', 'service_description', 'last_service_state_change') { |
| 94 |
if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') { |
| 95 |
$properties->{$_} = $self->{option_results}->{$_}; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
my $response = $options{custom}->request_api( |
| 100 |
action => 'openService', |
| 101 |
data => { |
| 102 |
rule_name => $self->{option_results}->{rule_name}, |
| 103 |
host_id => $self->{option_results}->{host_id}, |
| 104 |
service_id => $self->{option_results}->{service_id}, |
| 105 |
service_state => $self->{option_results}->{service_state}, |
| 106 |
service_output => $self->{option_results}->{service_output}, |
| 107 |
extra_properties => $extra_properties, |
| 108 |
select => $select, |
| 109 |
%$properties |
| 110 |
} |
| 111 |
); |
| 112 |
|
| 113 |
$self->{output}->output_add(short_msg => $response->{message}); |
| 114 |
$self->{output}->display(force_ignore_perfdata => 1, force_long_output => 1); |
| 115 |
$self->{output}->exit(); |
| 116 |
} |
| 117 |
|
| 118 |
1; |
| 119 |
|
| 120 |
__END__ |
| 121 |
|
| 122 |
=head1 MODE |
| 123 |
|
| 124 |
Open a service ticket. |
| 125 |
|
| 126 |
=over 8 |
| 127 |
|
| 128 |
=item B<--rule-name> |
| 129 |
|
| 130 |
Rule name used (required). |
| 131 |
|
| 132 |
=item B<--host-id> |
| 133 |
|
| 134 |
Centreon host ID (required). |
| 135 |
|
| 136 |
=item B<--service-id> |
| 137 |
|
| 138 |
Centreon service ID (required). |
| 139 |
|
| 140 |
=item B<--service-state> |
| 141 |
|
| 142 |
Service state (example: CRITICAL, UNKNOWN, WARNING, OK) (required). |
| 143 |
|
| 144 |
=item B<--service-output> |
| 145 |
|
| 146 |
Service output (required). |
| 147 |
|
| 148 |
=item B<--contact-name> |
| 149 |
|
| 150 |
Contact name (default: --api-username contact information). |
| 151 |
|
| 152 |
=item B<--contact-alias> |
| 153 |
|
| 154 |
Contact alias (default: --api-username contact information). |
| 155 |
|
| 156 |
=item B<--contact-email> |
| 157 |
|
| 158 |
Contact email (default: --api-username contact information). |
| 159 |
|
| 160 |
=item B<--host-name> |
| 161 |
|
| 162 |
Host name. |
| 163 |
|
| 164 |
=item B<--host-alias> |
| 165 |
|
| 166 |
Host alias. |
| 167 |
|
| 168 |
=item B<--service-description> |
| 169 |
|
| 170 |
Service description. |
| 171 |
|
| 172 |
=item B<--last-service-state-change> |
| 173 |
|
| 174 |
Last service state change. |
| 175 |
|
| 176 |
=item B<--extra-property> |
| 177 |
|
| 178 |
Add a extra property. |
| 179 |
Example: --extra-property='custom_message=test my message' |
| 180 |
|
| 181 |
=item B<--select> |
| 182 |
|
| 183 |
Add a select property (open-ticket list). |
| 184 |
Example: --select='list-id=value' |
| 185 |
|
| 186 |
=back |
| 187 |
|
| 188 |
=cut |