File Coverage

blib/lib/Siebel/Srvrmgr/ListParser/Output/Tabular/ListServers.pm
Criterion Covered Total %
statement 35 37 94.5
branch 3 6 50.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 46 51 90.2


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::ListParser::Output::Tabular::ListServers;
2              
3 4     4   32485 use Moose 2.0401;
  4         100  
  4         38  
4 4     4   32434 use namespace::autoclean 0.13;
  4         136  
  4         45  
5 4     4   2455 use Siebel::Srvrmgr::ListParser::Output::ListServers::Server;
  4         1977  
  4         1851  
6             our $VERSION = '0.29'; # VERSION
7              
8             =pod
9              
10             =head1 NAME
11              
12             Siebel::Srvrmgr::ListParser::Output::Tabular::ListServers - subclass to parse list servers command
13              
14             =cut
15              
16             extends 'Siebel::Srvrmgr::ListParser::Output::Tabular';
17             with 'Siebel::Srvrmgr::ListParser::Output::Tabular::ByServer';
18              
19             =pod
20              
21             =head1 SYNOPSIS
22              
23             See L<Siebel::Srvrmgr::ListParser::Output::Tabular> for examples.
24              
25             =head1 DESCRIPTION
26              
27             This subclass of L<Siebel::Srvrmgr::ListParser::Output::Tabular> parses the output of the command C<list servers>.
28              
29             This is probably the default configuration you have:
30              
31             srvrmgr> configure list servers
32             SBLSRVR_NAME (31): Siebel Server name
33             SBLSRVR_GROUP_NAME (46): Siebel server Group name
34             HOST_NAME (31): Host name of server machine
35             INSTALL_DIR (256): Server install directory name
36             SBLMGR_PID (16): O/S process/thread ID of Siebel Server Manager
37             SV_DISP_STATE (61): Server state (started, stopped, etc.)
38             SBLSRVR_STATE (31): Server state internal (started, stopped, etc.)
39             START_TIME (21): Time the server was started
40             END_TIME (21): Time the server was stopped
41             SBLSRVR_STATUS (101): Server status
42              
43             This class expectes the following order and configuration of fields from C<list servers> command:
44              
45             srvrmgr> configure list server
46             SBLSRVR_NAME (31): Siebel Server name
47             SBLSRVR_GROUP_NAME (46): Siebel server Group name
48             HOST_NAME (31): Host name of server machine
49             INSTALL_DIR (256): Server install directory name
50             SBLMGR_PID (16): O/S process/thread ID of Siebel Server Manager
51             SV_DISP_STATE (61): Server state (started, stopped, etc.)
52             SBLSRVR_STATE (31): Server state internal (started, stopped, etc.)
53             START_TIME (21): Time the server was started
54             END_TIME (21): Time the server was stopped
55             SBLSRVR_STATUS (101): Server status
56             SV_SRVRID (9): Server ID
57              
58             Anything different from that will generate exceptions when parsing. Using the following command to configure it properly:
59              
60             configure list server show SBLSRVR_NAME(31), SBLSRVR_GROUP_NAME(46),HOST_NAME(31),INSTALL_DIR(256),SBLMGR_PID(16),SV_DISP_STATE(61),SBLSRVR_STATE(31),START_TIME(21),END_TIME(21),SBLSRVR_STATUS(101), SV_SRVRID(9)
61              
62             =head1 ATTRIBUTES
63              
64             All from parent class.
65              
66             =head1 METHODS
67              
68             All methods from superclass plus some additional ones described below.
69              
70             =head2 get_data_parsed
71              
72             The hash reference returned by C<get_data_parsed> will look like that:
73              
74             siebfoobar' => HASH
75             'END_TIME' => ''
76             'HOST_NAME' => 'siebfoobar'
77             'INSTALL_DIR' => '/app/siebel/siebsrvr'
78             'SBLMGR_PID' => 20452
79             'SBLSRVR_GROUP_NAME' => ''
80             'SBLSRVR_STATE' => 'Running'
81             'SBLSRVR_STATUS' => '8.1.1.7 [21238] LANG_INDEPENDENT'
82             'START_TIME' => '2013-04-22 15:32:25'
83             'SV_DISP_STATE' => 'Running'
84              
85             where the keys are the Siebel servers names, each one holding a reference to another hash with the keys shown above.
86              
87             =cut
88              
89             sub _build_expected {
90 8     8   30 my $self = shift;
91 8         466 $self->_set_expected_fields(
92             [
93             'SBLSRVR_NAME', 'SBLSRVR_GROUP_NAME',
94             'HOST_NAME', 'INSTALL_DIR',
95             'SBLMGR_PID', 'SV_DISP_STATE',
96             'SBLSRVR_STATE', 'START_TIME',
97             'END_TIME', 'SBLSRVR_STATUS',
98             'SV_SRVRID'
99             ]
100             );
101             }
102              
103             =head2 get_servers_iter
104              
105             Returns a iterator in a form of a sub reference.
106              
107             Which dereference of anonymous sub reference will return a L<Siebel::Srvrmgr::ListParser::Output::ListServers::Server> object
108             until the list of servers is exausted. In this case the sub reference will return C<undef>.
109              
110             =cut
111              
112             sub get_servers_iter {
113 4     4 1 27 my $self = shift;
114 4         9 my $counter = 0;
115 4         167 my $servers_ref = $self->get_data_parsed;
116 4         26 my @servers = $self->get_servers;
117 4         12 my $total = scalar(@servers) - 1;
118              
119             return sub {
120              
121 4 50   4   1056 if ( $counter <= $total ) {
122 4         19 my $name = $servers[$counter];
123 4         15 my $server_ref = $servers_ref->{$name};
124 4         9 $counter++;
125             my %attribs = (
126             name => $name,
127             group => $server_ref->{SBLSRVR_GROUP_NAME},
128             host => $server_ref->{HOST_NAME},
129             install_dir => $server_ref->{INSTALL_DIR},
130             disp_state => $server_ref->{SV_DISP_STATE},
131             state => $server_ref->{SBLSRVR_STATE},
132             start_datetime => $server_ref->{START_TIME},
133             end_datetime => $server_ref->{END_TIME},
134             status => $server_ref->{SBLSRVR_STATUS},
135             id => $server_ref->{SV_SRVRID}
136 4         77 );
137              
138             # the server can be stopped, so no PID associated with it
139 4 50       23 if ( defined( $server_ref->{SBLMGR_PID} ) ) {
140 4         17 $attribs{pid} = $server_ref->{SBLMGR_PID};
141             }
142              
143 4         235 return Siebel::Srvrmgr::ListParser::Output::ListServers::Server
144             ->new( \%attribs );
145             }
146             else {
147 0         0 return;
148             }
149              
150             } # end of sub block
151 4         59 }
152              
153             sub _consume_data {
154 52     52   146 my ( $self, $fields_ref, $parsed_ref ) = @_;
155 52         101 my $list_len = scalar( @{$fields_ref} );
  52         113  
156 52         128 my $server_name = $fields_ref->[0];
157 52         2377 my $columns_ref = $self->get_expected_fields;
158              
159 52 50       115 if ( @{$fields_ref} ) {
  52         149  
160              
161 52         167 for ( my $i = 1 ; $i < $list_len ; $i++ ) {
162 520         1788 $parsed_ref->{$server_name}->{ $columns_ref->[$i] } =
163             $fields_ref->[$i];
164             }
165              
166 52         339 return 1;
167             }
168             else {
169 0           return 0;
170             }
171             }
172              
173             =pod
174              
175             =head1 SEE ALSO
176              
177             =over
178              
179             =item *
180              
181             L<Siebel::Srvrmgr::ListParser::Output::ListServers::Server>
182              
183             =item *
184              
185             L<Siebel::Srvrmgr::ListParser::Output::Tabular>
186              
187             =item *
188              
189             L<Moose>
190              
191             =back
192              
193             =head1 AUTHOR
194              
195             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
196              
197             =head1 COPYRIGHT AND LICENSE
198              
199             This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
200              
201             This file is part of Siebel Monitoring Tools.
202              
203             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
204             it under the terms of the GNU General Public License as published by
205             the Free Software Foundation, either version 3 of the License, or
206             (at your option) any later version.
207              
208             Siebel Monitoring Tools is distributed in the hope that it will be useful,
209             but WITHOUT ANY WARRANTY; without even the implied warranty of
210             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
211             GNU General Public License for more details.
212              
213             You should have received a copy of the GNU General Public License
214             along with Siebel Monitoring Tools. If not, see L<http://www.gnu.org/licenses/>.
215              
216             =cut
217              
218             __PACKAGE__->meta->make_immutable;
219             1;