line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::JBoss; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
393
|
use 5.010; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
497
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
714003
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
17
|
use Scalar::Util qw(looks_like_number); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
100
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
7
|
1
|
|
|
1
|
|
467
|
use Moo::Role; |
|
1
|
|
|
|
|
13832
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Net::JBoss - Bindings for JBoss Management API |
12
|
|
|
|
|
|
|
Tested on JBoss EAP v6.3.x |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.01 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Net::JBoss::Management; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my %con = ( |
28
|
|
|
|
|
|
|
username => 'admin', |
29
|
|
|
|
|
|
|
password => 'password', |
30
|
|
|
|
|
|
|
server => 'jboss1.example.com', |
31
|
|
|
|
|
|
|
port => 9990, #optional |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $jboss = Net::JBoss::Management->new(%con); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $state = $jboss->get_state(); |
37
|
|
|
|
|
|
|
my $jvm_usage = $jboss->get_jvm_usage(); |
38
|
|
|
|
|
|
|
my $runtime_stats = $jboss->get_runtime_stats(); |
39
|
|
|
|
|
|
|
my $runtime_details = $jboss->get_runtime_details(); |
40
|
|
|
|
|
|
|
my $server_env = $jboss->get_server_env(); |
41
|
|
|
|
|
|
|
my $datasources = $jboss->get_datasources(); |
42
|
|
|
|
|
|
|
my $app_status = $jboss->get_app_status('hawtio.war'); |
43
|
|
|
|
|
|
|
my $active_session = $jboss->get_active_sessions('hawtio.war'); |
44
|
|
|
|
|
|
|
my $pool_stats = $jboss->get_ds_pool_stats('java:jboss/datasources/jboss_Pool'); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 Attributes |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
notes : |
49
|
|
|
|
|
|
|
ro = read only, can be specified during initialization |
50
|
|
|
|
|
|
|
rw = read write, user can set this attribute |
51
|
|
|
|
|
|
|
rwp = read write protected, for internal class |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
username = (ro, required) store management user username |
54
|
|
|
|
|
|
|
password = (ro, required) store management user password |
55
|
|
|
|
|
|
|
server = (ro, required) store managemenet address, ip address / hostname only |
56
|
|
|
|
|
|
|
port = (ro) store Ovirt Manager's port (must be number) |
57
|
|
|
|
|
|
|
log_severity = (ro) store log severity level, valid value ERROR|OFF|FATAL|INFO|DEBUG|TRACE|ALL|WARN |
58
|
|
|
|
|
|
|
(default is INFO) |
59
|
|
|
|
|
|
|
realm = (ro) store realm, default to 'ManagementRealm' |
60
|
|
|
|
|
|
|
resource_url = (rwp) store resource url for each method |
61
|
|
|
|
|
|
|
url = (rwp) store final url to be requested |
62
|
|
|
|
|
|
|
log = (rwp) store log from log4perl |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has [qw/url log json_data resource_url/] => ( is => 'rwp' ); |
67
|
|
|
|
|
|
|
has [qw/username password/] => ( is => 'ro', required => 1 ); |
68
|
|
|
|
|
|
|
has [qw/server/] => ( is => 'ro', |
69
|
|
|
|
|
|
|
isa => sub { |
70
|
|
|
|
|
|
|
croak "server can't contain http protocol, use ip / hostname only" |
71
|
|
|
|
|
|
|
if $_[0] =~ /http/i; |
72
|
|
|
|
|
|
|
}, |
73
|
|
|
|
|
|
|
required => 1 ) |
74
|
|
|
|
|
|
|
; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
has 'port' => ( is => 'ro', default => 9990, |
77
|
|
|
|
|
|
|
isa => |
78
|
|
|
|
|
|
|
sub { |
79
|
|
|
|
|
|
|
croak "$_[0] is not a number!" unless looks_like_number $_[0]; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
has 'log_severity' => ( is => 'ro', |
84
|
|
|
|
|
|
|
isa => sub { croak "log severity value not valid\n" |
85
|
|
|
|
|
|
|
unless $_[0] =~ /(ERROR|OFF|FATAL|INFO|DEBUG|TRACE|ALL|WARN)/; |
86
|
|
|
|
|
|
|
}, |
87
|
|
|
|
|
|
|
default => 'INFO' |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
has 'realm' => ( is => 'ro', default => 'ManagementRealm' ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
You may want to check : |
95
|
|
|
|
|
|
|
- perldoc Net::JBoss::Management |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 BUILD |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The Constructor, build logging, call pass_log_obj method |
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub BUILD { |
103
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->pass_log_obj(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 pass_log_obj |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
it will build the log which stored to $self->log |
111
|
|
|
|
|
|
|
you can assign the severity level by assigning the log_severity |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# output to console / screen |
114
|
|
|
|
|
|
|
# format : |
115
|
|
|
|
|
|
|
# %d = current date with yyyy/MM/dd hh:mm:ss format |
116
|
|
|
|
|
|
|
# %p = Log Severity |
117
|
|
|
|
|
|
|
# %P = pid of the current process |
118
|
|
|
|
|
|
|
# %L = Line number within the file where the log statement was issued |
119
|
|
|
|
|
|
|
# %M = Method or function where the logging request was issued |
120
|
|
|
|
|
|
|
# %m = The message to be logged |
121
|
|
|
|
|
|
|
# %n = Newline (OS-independent) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub pass_log_obj { |
126
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# skip if already set |
129
|
0
|
0
|
|
|
|
|
return if $self->log; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $severity = $self->log_severity; |
132
|
0
|
|
|
|
|
|
my $log_conf = |
133
|
|
|
|
|
|
|
qq / |
134
|
|
|
|
|
|
|
log4perl.logger = $severity, Screen |
135
|
|
|
|
|
|
|
log4perl.appender.Screen = Log::Log4perl::Appender::Screen |
136
|
|
|
|
|
|
|
log4perl.appender.Screen.stderr = 0 |
137
|
|
|
|
|
|
|
log4perl.appender.Screen.layout = PatternLayout |
138
|
|
|
|
|
|
|
log4perl.appender.Screen.layout.ConversionPattern = %d || %p || %P || %L || %M || %m%n |
139
|
|
|
|
|
|
|
/; |
140
|
|
|
|
|
|
|
|
141
|
1
|
|
|
1
|
|
1252
|
use Log::Log4perl; |
|
1
|
|
|
|
|
32360
|
|
|
1
|
|
|
|
|
6
|
|
142
|
0
|
|
|
|
|
|
Log::Log4perl::init(\$log_conf); |
143
|
0
|
|
|
|
|
|
my $log = Log::Log4perl->get_logger(); |
144
|
0
|
|
|
|
|
|
$self->_set_log($log); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 base_url |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
return the base url |
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub base_url { |
153
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
my $url = $self->server; |
156
|
|
|
|
|
|
|
|
157
|
0
|
0
|
|
|
|
|
if ($self->port) { |
158
|
0
|
|
|
|
|
|
$url = $self->server . ":" . $self->port; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# handle only http |
162
|
0
|
|
|
|
|
|
$url = "http://" . $url; |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$self->log->debug($url); |
165
|
0
|
|
|
|
|
|
return $url; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 get_api_response |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
return http api response |
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub get_api_response { |
174
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
175
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
croak "url required" unless $self->url; |
177
|
0
|
0
|
|
|
|
|
croak "resource url required" unless $self->resource_url; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# set final url |
180
|
0
|
|
|
|
|
|
$self->_set_url($self->url . $self->resource_url); |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
$self->log->debug($self->url); |
183
|
0
|
|
|
|
|
|
$self->log->debug("username = " . $self->username); |
184
|
0
|
|
|
|
|
|
$self->log->debug("password = " . $self->password); |
185
|
0
|
|
|
|
|
|
$self->log->debug("port = " . $self->port); |
186
|
0
|
|
|
|
|
|
$self->log->debug("realm = " . $self->realm); |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
189
|
0
|
|
|
|
|
|
$ua->credentials( $self->server . ":" . $self->port, |
190
|
|
|
|
|
|
|
$self->realm , |
191
|
|
|
|
|
|
|
$self->username , |
192
|
|
|
|
|
|
|
$self->password , |
193
|
|
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
my $res = $ua->get($self->url); |
196
|
|
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
|
if ($res->is_success) { |
198
|
0
|
|
|
|
|
|
$self->log->debug($res->decoded_content); |
199
|
0
|
|
|
|
|
|
return $res->decoded_content; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
else { |
202
|
0
|
|
|
|
|
|
my $err = $res->status_line; |
203
|
0
|
|
|
|
|
|
$self->log->debug("LWP Error : " . $err); |
204
|
0
|
|
|
|
|
|
return $res->decoded_content; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 trim |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
trim function to remove whitespace from the start and end of the string |
211
|
|
|
|
|
|
|
=cut |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub trim() |
214
|
|
|
|
|
|
|
{ |
215
|
0
|
|
|
0
|
1
|
|
my ($self, $string) = @_; |
216
|
0
|
|
|
|
|
|
$string =~ s/^\s+|\s+$//g; |
217
|
0
|
|
|
|
|
|
return $string; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 AUTHOR |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
"Heince Kurniawan", C<< <"heince at gmail.com"> >> |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 BUGS |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
227
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
228
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 SUPPORT |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
perldoc Net::JBoss |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
You can also look for information at: |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=over 4 |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
L |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
L |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item * CPAN Ratings |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
L |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item * Search CPAN |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
L |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=back |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Copyright 2015 "Heince Kurniawan". |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
269
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
270
|
|
|
|
|
|
|
copy of the full license at: |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
L |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
275
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
276
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
277
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
280
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
281
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
284
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
287
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
288
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
289
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
290
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
291
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
292
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
293
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
296
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
297
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
298
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
299
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
300
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
301
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
302
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=cut |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
1; # End of JBoss |