Debian Codegraph @

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