line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Siebel::Srvrmgr::Daemon::Action; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Siebel::Srvrmgr::Daemon::Action - base class for Siebel::Srvrmgr::Daemon action |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
This class must be subclassed and the C<do> method overrided. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
An subclass should return true ONLY when was able to identify the type of output received. Beware that the output expected must include also |
14
|
|
|
|
|
|
|
the command executed or the L<Siebel::Srvrmgr::ListParser> object will not be able to identify the type of the output (L<Siebel::Srvrmgr::Daemon> does that). |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This can be accomplish using something like this in the C<do> method: |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub do { |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
my $buffer = shift; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->get_parser()->parse($buffer); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $tree = $self->get_parser()->get_parsed_tree(); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
foreach my $obj ( @{$tree} ) { |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if ( $obj->isa('Siebel::Srvrmgr::ListParser::Output::MyOutputSubclassName') ) { |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $data = $obj->get_data_parsed(); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# do something |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return 1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} # end of foreach block |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return 0; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Where MyOutputSubclassName is a subclass of L<Siebel::Srvrmgr::ListParser::Output>. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
If this kind of output is not identified and the proper C<return> given, L<Siebel::Srvrmgr::Daemon> can enter in a |
48
|
|
|
|
|
|
|
infinite loop. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
15
|
|
|
15
|
|
11673
|
use Moose; |
|
15
|
|
|
|
|
345
|
|
|
15
|
|
|
|
|
103
|
|
53
|
15
|
|
|
15
|
|
97310
|
use namespace::autoclean; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
117
|
|
54
|
15
|
|
|
15
|
|
1116
|
use Carp; |
|
15
|
|
|
|
|
34
|
|
|
15
|
|
|
|
|
6072
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=pod |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 parser |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
A reference to a L<Siebel::Srvrmgr::ListParser> object. This attribute is required during object creation |
63
|
|
|
|
|
|
|
and is read-only. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
has parser => ( |
68
|
|
|
|
|
|
|
isa => 'Siebel::Srvrmgr::ListParser', |
69
|
|
|
|
|
|
|
is => 'ro', |
70
|
|
|
|
|
|
|
required => 1, |
71
|
|
|
|
|
|
|
reader => 'get_parser' |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=pod |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 params |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
An array reference. C<params> is an optional attribute during the object creation and it is used to pass additional parameters. How |
79
|
|
|
|
|
|
|
those parameters are going to be used is left to who is creating subclasses of L<Siebel::Srvrmgr::Daemon::Action>. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This attribute is read-only. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# :TODO:19-01-2014:: add a method to remove the params reference when desired to release memory |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
has params => ( |
88
|
|
|
|
|
|
|
isa => 'ArrayRef', |
89
|
|
|
|
|
|
|
is => 'ro', |
90
|
|
|
|
|
|
|
reader => 'get_params', |
91
|
|
|
|
|
|
|
default => sub { [] } |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 expected_output |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
A string telling the expected output type the L<Siebel::Srvrmgr::Daemon::Action> subclass expectes to find. This is a lazy attribute since each subclass may have a |
99
|
|
|
|
|
|
|
different type of expected output. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The string must be the name of a subclass of L<Siebel::Srvrmgr::ListParser::Output> and it will be used for validation during execution of C<do_parsed> method. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
has expected_output => ( |
106
|
|
|
|
|
|
|
isa => 'Str', |
107
|
|
|
|
|
|
|
is => 'ro', |
108
|
|
|
|
|
|
|
reader => 'get_exp_output', |
109
|
|
|
|
|
|
|
writer => '_set_exp_output', |
110
|
|
|
|
|
|
|
builder => '_build_exp_output', |
111
|
|
|
|
|
|
|
lazy => 1 #some subclasses will not use it |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _build_exp_output { |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
confess blessed($self) |
119
|
|
|
|
|
|
|
. ', as a subclass of Siebel::Srvrmgr::Daemon::Action, must override the _build_exp_output method'; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=pod |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 METHODS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 get_parser |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Returns the L<Siebel::Srvrmgr::ListParser> object stored into the C<parser> attribute. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 get_params |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Returns the array reference stored in the C<params> attribute. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 do |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This method expects to receive a array reference (with the content to be parsed) as parameter and it will do something with it. Usually this should be |
138
|
|
|
|
|
|
|
identify the type of output received, giving it to the proper parse and processing it somehow. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Every C<do> method must return true (1) if output was used, otherwise false (0). |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This method does: |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item parsing of the content of the buffer with the parser returned by C<get_parser> method |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item invokes the C<do_parsed> method passing the tree returned from the parser |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item clear the parser with the C<clear_parsed_tree> method. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item returns the returned value of the C<do_parsed> method. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub do { |
159
|
|
|
|
|
|
|
|
160
|
38
|
|
|
38
|
1
|
16926
|
my $self = shift; |
161
|
38
|
|
|
|
|
101
|
my $buffer = shift; |
162
|
|
|
|
|
|
|
|
163
|
38
|
|
|
|
|
2456
|
$self->get_parser()->parse($buffer); |
164
|
|
|
|
|
|
|
|
165
|
38
|
|
|
|
|
1755
|
my $tree = $self->get_parser()->get_parsed_tree(); |
166
|
|
|
|
|
|
|
|
167
|
38
|
|
|
|
|
86
|
my $was_found = 0; |
168
|
|
|
|
|
|
|
|
169
|
38
|
|
|
|
|
79
|
foreach my $item ( @{$tree} ) { |
|
38
|
|
|
|
|
108
|
|
170
|
|
|
|
|
|
|
|
171
|
35
|
|
|
|
|
198
|
$was_found = $self->do_parsed($item); |
172
|
33
|
50
|
|
|
|
165
|
last if ($was_found); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
36
|
|
|
|
|
1828
|
$self->get_parser()->clear_parsed_tree(); |
177
|
|
|
|
|
|
|
|
178
|
36
|
|
|
|
|
1803
|
return $was_found; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=pod |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 do_parsed |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This method must be overrided by subclasses or it will C<die> with trace. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
It expects an array reference with the parsed tree given by C<get_parsed_tree> of a L<Siebel::Srvrmgr::ListParser> instance. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This method is invoked internally by C<do> method, but is also usable directly if the parsed tree is given as expected. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
If the output is used, this method must returns true, otherwise false. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub do_parsed { |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
0
|
1
|
|
confess |
199
|
|
|
|
|
|
|
'do_parsed must be overrided by subclasses of Siebel::Srvrmgr::Daemon::Action'; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=pod |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 CAVEATS |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This class may be changed to a role instead of a superclass in the future since it's methods could be used by different classes. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 SEE ALSO |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=over |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L<Moose> |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
L<Moose::Manual::MethodModifiers> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::ListParser> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::Daemon> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item * |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::ListParser::Output> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 AUTHOR |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt> |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt> |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
This file is part of Siebel Monitoring Tools. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Siebel Monitoring Tools is free software: you can redistribute it and/or modify |
246
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
247
|
|
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or |
248
|
|
|
|
|
|
|
(at your option) any later version. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Siebel Monitoring Tools is distributed in the hope that it will be useful, |
251
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
252
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
253
|
|
|
|
|
|
|
GNU General Public License for more details. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
256
|
|
|
|
|
|
|
along with Siebel Monitoring Tools. If not, see <http://www.gnu.org/licenses/>. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |