line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Siebel::Srvrmgr::Daemon::Offline; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Siebel::Srvrmgr::Daemon::Offline - subclass that reads srvrmgr output from a file |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Siebel::Srvrmgr::Daemon::Offline; |
12
|
|
|
|
|
|
|
my $daemon = Siebel::Srvrmgr::Daemon::Offline->new( |
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
output_file => File::Spec->catfile('some', 'location', 'to', 'srvrmgr', 'output', 'file'), |
15
|
|
|
|
|
|
|
field_delimiter => $field_delimiter; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
$daemon->run(); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This is a subclass of L<Siebel::Srvrmgr::Daemon> used to execute the C<srvrmgr> program in batch mode. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This class also uses the L<Siebel::Srvrmgr::Daemon::Cleanup> role. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
5429
|
use Moose 2.0401; |
|
1
|
|
|
|
|
34
|
|
|
1
|
|
|
|
|
10
|
|
30
|
1
|
|
|
1
|
|
11011
|
use namespace::autoclean 0.13; |
|
1
|
|
|
|
|
31
|
|
|
1
|
|
|
|
|
10
|
|
31
|
1
|
|
|
1
|
|
661
|
use Siebel::Srvrmgr::Daemon::ActionFactory; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
51
|
|
32
|
1
|
|
|
1
|
|
12
|
use Carp qw(longmess); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
91
|
|
33
|
1
|
|
|
1
|
|
9
|
use File::Temp 0.2304 qw(:POSIX); |
|
1
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
175
|
|
34
|
1
|
|
|
1
|
|
10
|
use Data::Dumper; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
59
|
|
35
|
1
|
|
|
1
|
|
7
|
use Siebel::Srvrmgr; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
36
|
1
|
|
|
1
|
|
471
|
use File::BOM 0.14 qw(:all); |
|
1
|
|
|
|
|
28312
|
|
|
1
|
|
|
|
|
256
|
|
37
|
1
|
|
|
1
|
|
13
|
use Try::Tiny 0.27; |
|
1
|
|
|
|
|
26
|
|
|
1
|
|
|
|
|
663
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our $VERSION = '0.29'; # VERSION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
extends 'Siebel::Srvrmgr::Daemon'; |
42
|
|
|
|
|
|
|
with 'Siebel::Srvrmgr::Daemon::Cleanup'; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 output_file |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
A string representing the full pathname to the file that contains all output from srvrmgr program to be parsed. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Required during object creation, this is a read-write attribute. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has output_file => ( |
57
|
|
|
|
|
|
|
isa => 'Str', |
58
|
|
|
|
|
|
|
is => 'rw', |
59
|
|
|
|
|
|
|
reader => 'get_output_file', |
60
|
|
|
|
|
|
|
writer => '_set_output_file', |
61
|
|
|
|
|
|
|
required => 1 |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 field_delimiter |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
An optional, read-write parameter during object creation. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
If the file defined by C<output_file> has fields separated by a delimiter, you must set this attribute or output parsing will fail. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
If setup, expects a single character. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
has field_delimiter => ( is => 'rw', isa => 'Chr', reader => 'get_field_del', writer => 'set_field_del' ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 run |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This method completely overrides the parent's L<Siebel::Srvrmgr::Daemon> method. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
It will then parse the file defined in the C<output_file> attribute, executing any action defined during object creation. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
override 'run' => sub { |
85
|
|
|
|
|
|
|
my ( $self ) = @_; |
86
|
|
|
|
|
|
|
my $logger = Siebel::Srvrmgr->gimme_logger( blessed($self) ); |
87
|
|
|
|
|
|
|
$logger->info('Starting run method'); |
88
|
|
|
|
|
|
|
my $parser = $self->create_parser($self->get_field_del); |
89
|
|
|
|
|
|
|
my $in; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
try { |
92
|
|
|
|
|
|
|
open_bom( $in, $self->get_output_file(), ':utf8' ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
catch { |
95
|
|
|
|
|
|
|
$logger->logdie( |
96
|
|
|
|
|
|
|
'Cannot read ' . $self->get_output_file() . ': ' . $_ ); |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# :TODO:22-09-2014 01:32:45:: this might be dangerous if the output is too large |
100
|
|
|
|
|
|
|
my @input_buffer = <$in>; |
101
|
|
|
|
|
|
|
close($in); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
if ( scalar(@input_buffer) >= 1 ) { |
104
|
|
|
|
|
|
|
$self->_check_error( \@input_buffer, 0 ); |
105
|
|
|
|
|
|
|
$self->normalize_eol( \@input_buffer ); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# since we should have all output, we parse everything first to call each action after |
108
|
|
|
|
|
|
|
$parser->parse( \@input_buffer ); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
if ( $parser->has_tree() ) { |
111
|
|
|
|
|
|
|
my $total = $self->cmds_vs_tree( $parser->count_parsed() ); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
if ( $logger->is_debug() ) { |
114
|
|
|
|
|
|
|
$logger->debug( 'Total number of parsed items = ' |
115
|
|
|
|
|
|
|
. $parser->count_parsed() ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$logger->logdie( |
119
|
|
|
|
|
|
|
'Number of parsed nodes is different from the number of submitted commands' |
120
|
|
|
|
|
|
|
) unless ( defined($total) ); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $parsed_ref = $parser->get_parsed_tree(); |
123
|
|
|
|
|
|
|
$parser->clear_parsed_tree(); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
for ( my $i = 0 ; $i < $total ; $i++ ) { |
126
|
|
|
|
|
|
|
my $cmd = ( @{ $self->get_commands() } )[$i]; |
127
|
|
|
|
|
|
|
my $action = Siebel::Srvrmgr::Daemon::ActionFactory->create( |
128
|
|
|
|
|
|
|
$cmd->get_action(), |
129
|
|
|
|
|
|
|
{ |
130
|
|
|
|
|
|
|
parser => $parser, |
131
|
|
|
|
|
|
|
params => $cmd->get_params() |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
$action->do_parsed( $parsed_ref->[$i] ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { |
139
|
|
|
|
|
|
|
$logger->logdie('Parser did not have a parsed tree after parsing'); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else { |
144
|
|
|
|
|
|
|
$logger->debug('buffer is empty'); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$logger->info('Exiting run sub'); |
148
|
|
|
|
|
|
|
return 1; |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
override _my_cleanup => sub { |
152
|
|
|
|
|
|
|
my $self = shift; |
153
|
|
|
|
|
|
|
return $self->_del_output_file(); |
154
|
|
|
|
|
|
|
}; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=pod |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=over |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L<Moose> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::Daemon::Command> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::Daemon::ActionFactory> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::ListParser> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::Regexes> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
L<POSIX> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
L<Siebel::Srvrmgr::Daemon::Command> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=back |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 AUTHOR |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This file is part of Siebel Monitoring Tools. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Siebel Monitoring Tools is free software: you can redistribute it and/or modify |
203
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
204
|
|
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or |
205
|
|
|
|
|
|
|
(at your option) any later version. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Siebel Monitoring Tools is distributed in the hope that it will be useful, |
208
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
209
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
210
|
|
|
|
|
|
|
GNU General Public License for more details. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
213
|
|
|
|
|
|
|
along with Siebel Monitoring Tools. If not, see L<http://www.gnu.org/licenses/>. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; |
220
|
|
|
|
|
|
|
|