line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Siebel::Srvrmgr::Daemon::Action::CheckTasks; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Siebel::Srvrmgr::Daemon::Action::CheckTasks - subclass of Siebel::Srvrmgr::Daemon::Action to verify components tasks status |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Siebel::Srvrmgr::Daemon::Action::CheckTasks; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $return_data = Siebel::Srvrmgr::Daemon::ActionStash->instance(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $comps = [ {name => 'SynchMgr', ok_status => 'Running'}, { name => 'WfProcMgr', ok_status => 'Running'} ]; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $action = Siebel::Srvrmgr::Daemon::Action::CheckTasks->new( |
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
parser => Siebel::Srvrmgr::ListParser->new(), |
20
|
|
|
|
|
|
|
params => [ $server1, $server2 ] |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$action->do(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# do something with $return_data |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
4111
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
31
|
1
|
|
|
1
|
|
4632
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
32
|
1
|
|
|
1
|
|
51
|
use Moose::Util qw(does_role); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
33
|
1
|
|
|
1
|
|
145
|
use Siebel::Srvrmgr::Daemon::ActionStash; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
34
|
1
|
|
|
1
|
|
4
|
use Siebel::Srvrmgr; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
636
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
extends 'Siebel::Srvrmgr::Daemon::Action'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This subclass of L<Siebel::Srvrmgr::Daemon::Action> will try to find a L<Siebel::Srvrmgr::ListParser::Output::Tabular::ListTask> object in the given array reference |
43
|
|
|
|
|
|
|
given as parameter to the C<do> method and compares the status of the components with the array reference given as parameter. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
The C<do> method of C<Siebel::Srvrmgr::Daemon::Action::CheckTasks> uses L<Siebel::Srvrmgr::Daemon::ActionStash> to enable the program that created the object |
46
|
|
|
|
|
|
|
instance to be able to fetch the information returned. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This module was created to work close with Nagios plug-in concepts, especially regarding threshold levels (see C<new> method for more details). |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 METHODS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 new |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
The new method returns a instance of L<Siebel::Srvrmgr::Daemon::Action::CheckTasks>. The parameter expected are the same ones of any subclass of |
55
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::Daemon::Action>, but the C<params> attribute has a important difference: it expects an array reference with instances of classes |
56
|
|
|
|
|
|
|
that have the role L<Siebel::Srvrmgr::Daemon::Action::Check::Server>. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
See the examples directory of this distribution to check a XML file used for configuration for more details. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 BUILD |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Validates if the C<params> attribute has objects with the L<Siebel::Srvrmgr::Daemon::Action::Check::Server> role |
63
|
|
|
|
|
|
|
applied. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub BUILD { |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $role = 'Siebel::Srvrmgr::Daemon::Action::Check::Server'; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
foreach my $object ( @{ $self->get_params() } ) { |
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
confess "all params items must be classes with $role role applied" |
76
|
|
|
|
|
|
|
unless ( does_role( $object, $role ) ); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
override '_build_exp_output' => sub { |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return 'Siebel::Srvrmgr::ListParser::Output::Tabular::ListTasks'; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 do_parsed |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Expects as parameter a instance of L<Siebel::Srvrmgr::ListParser::Output::Tabular::ListTasks> class, otherwise |
91
|
|
|
|
|
|
|
this method will raise an exception. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
It will check the output from C<srvrmgr> program parsed by |
94
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::ListParser::Output::Tabular::ListTask> object and compare each task recovered status |
95
|
|
|
|
|
|
|
with the C<taskOKStatus> attribute of each instance of L<Siebel::Srvrmgr::Daemon::Action::Check::Component> |
96
|
|
|
|
|
|
|
available in C<params> attribute during object creation. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
It will return 1 if this operation was executed successfuly and request a instance of |
99
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::Daemon::ActionStash>, calling it's method C<instance> and then |
100
|
|
|
|
|
|
|
C<set_stash> with a hash reference as it's content. Otherwise, the method will return 0 and no data will be |
101
|
|
|
|
|
|
|
set to the ActionStash object. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The hash reference stored in the ActionStash object will have the following structure: |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$VAR1 = { |
106
|
|
|
|
|
|
|
'foobar_server' => { |
107
|
|
|
|
|
|
|
'CompAlias1' => 0, |
108
|
|
|
|
|
|
|
'CompAlias2' => 1 |
109
|
|
|
|
|
|
|
}, |
110
|
|
|
|
|
|
|
'foobar2_server' => { |
111
|
|
|
|
|
|
|
'CompAlias1' => 1, |
112
|
|
|
|
|
|
|
'CompAlias2' => 1 |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
If the servername passed during the object creation (as C<params> attribute of C<new> method) cannot be found in the |
117
|
|
|
|
|
|
|
the object passed as parameter to this method, the methodreturned by will raise an exception. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Beware that this Action subclass can deal with multiple servers, as long as the buffer output is from a |
120
|
|
|
|
|
|
|
C<list tasks>, dealing with all server tasks that are part of the Siebel Enterprise. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
override 'do_parsed' => sub { |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $self = shift; |
127
|
|
|
|
|
|
|
my $obj = shift; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $logger = Siebel::Srvrmgr->gimme_logger('Siebel::Srvrmgr::Daemon'); |
130
|
|
|
|
|
|
|
$logger->info('Starting run method'); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $servers = $self->get_params(); # array reference |
133
|
|
|
|
|
|
|
my %servers; # to locate the expected servers easier |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
foreach my $server ( @{$servers} ) { |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$servers{ $server->get_name() } = $server; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my %checked_tasks; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
if ( $obj->isa( $self->get_exp_output ) ) { |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my @output_servers = |
146
|
|
|
|
|
|
|
$obj->get_servers(); # servers retrieved from output of srvrmgr |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$logger->die( 'Could not fetch servers from the ' |
149
|
|
|
|
|
|
|
. $self->get_exp_output |
150
|
|
|
|
|
|
|
. 'object returned by the parser' ) |
151
|
|
|
|
|
|
|
unless ( scalar(@output_servers) > 0 ); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
foreach my $output_server (@output_servers) { |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
if ( exists( $servers{$output_server} ) ) { |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $exp_srv = |
158
|
|
|
|
|
|
|
$servers{$output_server}; # the expected server reference |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my %exp_status; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
foreach my $exp_comp ( @{ $exp_srv->get_components() } ) { |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$exp_status{ $exp_comp->get_alias } = |
165
|
|
|
|
|
|
|
[ ( split( /\|/, $exp_comp->get_taskOKStatus ) ) ]; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
my $iterator = $obj->get_tasks($output_server); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
while ( my $task = $iterator->() ) { |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $comp_alias = $task->get_comp_alias; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
if ( exists( $exp_status{$comp_alias} ) ) { |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $is_ok = 0; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
foreach |
180
|
|
|
|
|
|
|
my $valid_status ( @{ $exp_status{$comp_alias} } ) |
181
|
|
|
|
|
|
|
{ |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
if ( $valid_status eq $task->get_run_state ) { |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
$is_ok = 1; |
186
|
|
|
|
|
|
|
last; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
if ($is_ok) { |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
$checked_tasks{$output_server}->{$comp_alias} = 1; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
else { |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
$checked_tasks{$output_server}->{$comp_alias} = 0; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
$logger->warn( 'invalid status got for ' |
202
|
|
|
|
|
|
|
. $comp_alias . ' "' |
203
|
|
|
|
|
|
|
. $task->get_status |
204
|
|
|
|
|
|
|
. '" instead of "' |
205
|
|
|
|
|
|
|
. join( ',', $exp_status{$comp_alias} ) |
206
|
|
|
|
|
|
|
. '"' ) |
207
|
|
|
|
|
|
|
if ( $logger->is_warn() ); |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
else { |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
$logger->warn( |
215
|
|
|
|
|
|
|
'Could not find any component with name [', |
216
|
|
|
|
|
|
|
$comp_alias . ']' ) |
217
|
|
|
|
|
|
|
if ( $logger->is_warn() ); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
} # end of foreach comp |
224
|
|
|
|
|
|
|
else { |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
$logger->logdie( |
227
|
|
|
|
|
|
|
"Unexpected servername [$output_server] retrieved from buffer.\n Expected servers names are " |
228
|
|
|
|
|
|
|
. join( ', ', |
229
|
|
|
|
|
|
|
map { '[' . $_->get_name() . ']' } @{$servers} ) |
230
|
|
|
|
|
|
|
); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
} # end of foreach server |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
else { |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
$logger->debug( 'object received ISA not' . $self->get_exp_output() ) |
238
|
|
|
|
|
|
|
if ( $logger->is_debug() ); |
239
|
|
|
|
|
|
|
return 0; |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# found some servers |
244
|
|
|
|
|
|
|
if ( keys(%checked_tasks) ) { |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
my $stash = Siebel::Srvrmgr::Daemon::ActionStash->instance(); |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
# :TODO :24/07/2013 12:32:51:: it should set the stash with more than just the ok/not ok status from the components |
249
|
|
|
|
|
|
|
$stash->set_stash( [ \%checked_tasks ] ); |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
return 1; |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
else { |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
return 0; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
}; |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=pod |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head1 SEE ALSO |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=over |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=item * |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::ListParser::Output::ListComp> |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=item * |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::ListParser::Output::ListComp::Server> |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=item * |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::Daemon::Action> |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=item * |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::Daemon::Action::Stash> |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=item * |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
L<Nagios::Plugin> |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=back |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head1 AUTHOR |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt> |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt> |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
This file is part of Siebel Monitoring Tools. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
Siebel Monitoring Tools is free software: you can redistribute it and/or modify |
301
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
302
|
|
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or |
303
|
|
|
|
|
|
|
(at your option) any later version. |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
Siebel Monitoring Tools is distributed in the hope that it will be useful, |
306
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
307
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
308
|
|
|
|
|
|
|
GNU General Public License for more details. |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
311
|
|
|
|
|
|
|
along with Siebel Monitoring Tools. If not, see <http://www.gnu.org/licenses/>. |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=cut |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |