| 1 | package JMX::Jmx4Perl::Nagios::SingleCheck; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use JMX::Jmx4Perl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use JMX::Jmx4Perl::Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use JMX::Jmx4Perl::Response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use JMX::Jmx4Perl::Alias; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Monitoring::Plugin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Monitoring::Plugin::Functions qw(:codes %STATUS_TEXT); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Text::ParseWords; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | JMX::Jmx4Perl::Nagios::SingleCheck - A single nagios check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | This is an package used internally by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | L<JMX::Jmx4Perl::Nagios::CheckJmx4Perl>. It encapsulates the configuration for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | single checks, which can be combined to a bulk JMX-Request so only a single | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | server turnaround is used to obtain multiple checks results at once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =item $single_check = new $JMX::Jmx4Perl::Nagios::SingleCheck($nagios_plugin,$check_config) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | Construct a new single check from a given L<Monitoring::Plugin> object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | C<$nagios_plugin> and a parsed check configuration $check_config, which is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | my $np = shift || die "No Nagios Plugin given"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || die('No Nagios Plugin given')
MC/DC0%0/1
shift() || die('No Nagios Plugin given')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my $config = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | np => $np, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | config => $config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | bless $self,(ref($class) || $class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | =item $requests = $single_check->get_requests($jmx,$args) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | Called to obtain an arrayref of L<JMX::Jmx4Perl::Request> objects which should | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | be send to the server agent. C<$jmx> ist the L<JMX::Jmx4Perl> agent, C<$args> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | are additonal arguments used for exec-operations, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | Multiple request object are returned e.g. if a relative check has to be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | performed in order to get the base value as well. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | The returned array can contain coderefs which should be executed directly and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | its return value should be used in order to perfoorm the check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub get_requests { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_requests: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $jmx = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # If a script is given, extract a subref and return it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return [ $self->_extract_script_as_subref($jmx) ] if $self->script; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $do_read = $self->attribute || $self->value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->attribute || $self->value
MC/DC0%0/2
$self->attribute || $self->value
$self->attribute
$self->value
Truth table0%0/3
A || B
A= $self->attributeB= $self->value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $do_exec = $self->operation; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($self->alias) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $alias = JMX::Jmx4Perl::Alias->by_name($self->alias); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | die "No alias '",$self->alias," known" unless $alias; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $do_read = $alias->type eq "attribute"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my @requests = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($do_read) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $request = JMX::Jmx4Perl::Request->new(READ,$self->_prepare_read_args($jmx)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } elsif ($do_exec) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $request = JMX::Jmx4Perl::Request->new(EXEC,$self->_prepare_exec_args($jmx,@$args)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | die "Neither an attribute/value, an operation or a script given"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $method = $self->{np}->opts->{method} || $self->{config}->{method}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'np'}->opts->{'method'} || $self->{'config'}{'method'}
MC/DC0%0/2
$self->{'np'}->opts->{'method'} || $self->{'config'}{'method'}
$self->{'np'}->opts->{'method'}
$self->{'config'}{'method'}
Truth table0%0/3
A || B
A= $self->{'np'}->opts->{'method'}B= $self->{'config'}{'method'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ($method) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $request->method($method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | push @requests,$request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($self->base || $self->base_mbean) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->base or $self->base_mbean
MC/DC0%0/2
$self->base or $self->base_mbean
$self->base
$self->base_mbean
Truth table0%0/3
A or B
A= $self->baseB= $self->base_mbean
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if (!looks_like_number($self->base)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # It looks like a number, so we will use the base literally | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($self->base) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $alias = JMX::Jmx4Perl::Alias->by_name($self->base); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($alias) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | push @requests,new JMX::Jmx4Perl::Request(READ,$jmx->resolve_alias($self->base)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my ($mbean,$attr,$path) = $self->base_mbean ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ($self->base_mbean, $self->base_attribute, $self->base_path) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $self->_split_attr_spec($self->base); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | die "No MBean given in base name ",$self->base unless $mbean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | die "No Attribute given in base name ",$self->base unless $attr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $mbean = URI::Escape::uri_unescape($mbean); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $attr = URI::Escape::uri_unescape($attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $path = URI::Escape::uri_unescape($path) if $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | push @requests,new JMX::Jmx4Perl::Request(READ,$mbean,$attr,$path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return \@requests; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # Create a subref where all params from the outside are available as closures. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub _extract_script_as_subref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_script_as_subref: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $jmx = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | my $script = $self->script || die "No script given"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->script || die('No script given')
MC/DC0%0/1
$self->script || die('No script given')
$self->script
Truth table0%0/2
A
A= $self->script
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $full_script = <<"EOT"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | my \$j4p = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | $script | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | EOT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | #print $full_script,"\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $sub = eval $full_script; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | die "Cannot eval script for check ",$self->name,": $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return &$sub($jmx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | =item $single_check->exract_responses($responses,$requests,$target) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | Extract L<JMX::Jmx4Perl::Response> objects and add the deducted results to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | the nagios plugin (which was given at construction time). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | C<$responses> is an arrayref to the returned responses, C<$requests> is an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | arrayref to the original requests. Any response consumed from C<$requests> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | should be removed from the array, as well as the corresponding request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | The requests/responses for this single request are always a the beginning of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | the arrays. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | C<$target> is an optional target configuration if the request was used in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | target proxy mode. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub extract_responses { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_responses: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $responses = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $requests = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $opts = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $np = $self->{np}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $msg_handler = $np->{msg_handler} || $np; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$np->{'msg_handler'} || $np
MC/DC0%0/2
$np->{'msg_handler'} || $np
$np->{'msg_handler'}
$np
Truth table0%0/3
A || B
A= $np->{'msg_handler'}B= $np
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # Get response/request pair | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $resp = shift @{$responses}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $request = shift @{$requests}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | #print Dumper($resp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my @extra_requests = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $script_mode = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if (ref($request) eq "CODE") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # It's a script, so the 'response' is already the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $script_mode = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $value = $resp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $self->_verify_response($request,$resp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $value = $self->_extract_value($request,$resp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # Delta handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $delta = $self->delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if (defined($delta) && !$script_mode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $delta and not $script_mode
MC/DC0%0/2
defined $delta and not $script_mode
defined $delta
not $script_mode
Truth table0%0/3
A and not(B)
A= defined $deltaB= not $script_mode
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $value = $self->_delta_value($request,$resp,$delta); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | unless (defined($value)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | push @extra_requests,$self->_switch_on_history($request,$opts->{target}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $value = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # Normalize value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my ($value_conv,$unit) = $self->_normalize_value($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my $label = $self->_get_name(cleanup => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ( ($self->base || $self->base_mbean) && !$script_mode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->base || $self->base_mbean and not $script_mode
$self->base or $self->base_mbean
MC/DC0%0/3
$self->base || $self->base_mbean and not $script_mode
$self->base
$self->base_mbean
not $script_mode
Truth table0%0/5
A or B and not(C)
A= $self->baseB= $self->base_mbeanC= not $script_mode
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # Calc relative value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $base_value = $self->_base_value($self->base,$responses,$requests); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | my $rel_value = sprintf "%2.2f",$base_value ? (int((($value / $base_value) * 10000) + 0.5) / 100) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # Performance data. Convert to absolute values before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ($self->_include_perf_data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ($self->perfdata && $self->perfdata =~ /^\s*\%\s*/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->perfdata and $self->perfdata =~ /^\s*\%\s*/
MC/DC0%0/2
$self->perfdata and $self->perfdata =~ /^\s*\%\s*/
$self->perfdata
$self->perfdata =~ /^\s*\%\s*/
Truth table0%0/3
A and B
A= $self->perfdataB= $self->perfdata =~ /^\s*\%\s*/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $np->add_perfdata(label => $label, value => $rel_value, uom => '%', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | critical => $self->critical, warning => $self->warning); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my ($critical,$warning) = $self->_convert_relative_to_absolute($base_value,$self->critical,$self->warning); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | $np->add_perfdata(label => $label,value => $value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | critical => $critical,warning => $warning, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | min => 0,max => $base_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | $self->unit ? (uom => $self->unit) : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # Do the real check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my ($code,$mode) = $self->_check_threshold($rel_value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # For Multichecks, we remember the label of a currently failed check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | $self->update_error_stats($opts->{error_stat},$code) unless $code == OK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my ($base_conv,$base_unit) = $self->_normalize_value($base_value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | $msg_handler->add_message($code,$self->_exit_message(code => $code,mode => $mode,rel_value => $rel_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | value => $value_conv, unit => $unit, base => $base_conv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | base_unit => $base_unit, prefix => $opts->{prefix})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Performance data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $value = $self->_sanitize_value($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($self->_include_perf_data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | $np->add_perfdata(label => $label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | critical => $self->critical, warning => $self->warning, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | value => $value,$self->unit ? (uom => $self->unit) : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # Do the real check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my ($code,$mode) = $self->_check_threshold($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | $self->update_error_stats($opts->{error_stat},$code) unless $code == OK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | $msg_handler->add_message($code,$self->_exit_message(code => $code,mode => $mode,value => $value_conv, unit => $unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | prefix => $opts->{prefix})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | return @extra_requests; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | sub _include_perf_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_include_perf_data: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # No perf dara for string based checks by default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $default = not defined($self->string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # If 'PerfData' is set explicitely to false/off/no/0 then no perfdata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # will be included | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | return $default unless defined($self->perfdata); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return $self->perfdata !~ /^\s*(false|off|no|0)\s*$/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub update_error_stats { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_error_stats: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | my $error_stat = shift || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $label = $self->{config}->{name} || $self->{config}->{key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'config'}{'name'} || $self->{'config'}{'key'}
MC/DC0%0/2
$self->{'config'}{'name'} || $self->{'config'}{'key'}
$self->{'config'}{'name'}
$self->{'config'}{'key'}
Truth table0%0/3
A || B
A= $self->{'config'}{'name'}B= $self->{'config'}{'key'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($label) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | my $arr = $error_stat->{$code} || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$error_stat->{$code} || []
MC/DC0%0/1
$error_stat->{$code} || []
$error_stat->{$code}
Truth table0%0/2
A
A= $error_stat->{$code}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | push @$arr,$label; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $error_stat->{$code} = $arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Extract a single value, which is different, if the request was a pattern read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub _extract_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_value: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $req = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $resp = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if ($req->get('type') eq READ && $req->is_mbean_pattern) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$req->get("type") eq "read" and $req->is_mbean_pattern
MC/DC0%0/2
$req->get("type") eq "read" and $req->is_mbean_pattern
$req->get("type") eq "read"
$req->is_mbean_pattern
Truth table0%0/3
A and B
A= $req->get("type") eq "read"B= $req->is_mbean_pattern
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | return $self->_extract_value_from_pattern_request($resp->value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | return $self->_null_safe_value($resp->value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | sub _null_safe_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_null_safe_value: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if (defined($value)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if (JSON::is_bool($value)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | return $value ? "true" : "false"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ▶ | } elsif (ref($value) && $self->string) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $value and $self->string
MC/DC0%0/2
ref $value and $self->string
ref $value
$self->string
Truth table0%0/3
A and B
A= ref $valueB= $self->string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # We can deal with complex values withing string comparison | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if (ref($value) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | return join ",",@{$value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return Dumper($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Our null value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | return defined($self->null) ? $self->null : "null"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub _extract_value_from_pattern_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_value_from_pattern_request: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | my $np = $self->{np}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | $self->_die("Pattern request does not result in a proper return format: " . Dumper($val)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | if (ref($val) ne "HASH"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | $self->_die("More than one MBean found for a pattern request: " . Dumper([keys %$val])) if keys %$val != 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $attr_val = (values(%$val))[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | $self->_die("Invalid response for pattern match: " . Dumper($attr_val)) unless ref($attr_val) eq "HASH"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | $self->_die("Only a single attribute can be used. Given: " . Dumper([keys %$attr_val])) if keys %$attr_val != 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | return $self->_null_safe_value((values(%$attr_val))[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub _delta_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_delta_value: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my ($self,$req,$resp,$delta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $history = $resp->history; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if (!$history) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # No delta on the first run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $hist_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if ($req->is_mbean_pattern) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $hist_val = $self->_extract_value_from_pattern_request($history); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $hist_val = $history; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if (!@$hist_val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # Can happen in some scenarios when requesting the first history entry, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # we return 0 here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $old_value = $hist_val->[0]->{value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my $old_time = $hist_val->[0]->{timestamp}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $value = $self->_extract_value($req,$resp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if ($delta) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # Time average | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $time_delta = $resp->timestamp - $old_time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | return (($value - $old_value) / ($time_delta ? $time_delta : 1)) * $delta; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return $value - $old_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | sub _switch_on_history { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_switch_on_history: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my ($self,$orig_request,$target) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my ($mbean,$operation) = ("jolokia:type=Config","setHistoryEntriesForAttribute"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # Set history to 1 (we need only the last) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | return new JMX::Jmx4Perl::Request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | (EXEC,$mbean,$operation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | $orig_request->get("mbean"),$orig_request->get("attribute"),$orig_request->get("path"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | $target ? $target->{url} : undef,1,{target => undef}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | sub _base_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_base_value: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $np = $self->{np}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my $responses = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $requests = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if (looks_like_number($name)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # It looks like a number, so we suppose its the base value itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my $resp = shift @{$responses}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $req = shift @{$requests}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | $self->_die($resp->{error}) if $resp->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | #print Dumper($req,$resp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | return $self->_extract_value($req,$resp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # Normalize value if a unit-of-measurement is given. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # Units and how to convert from one level to the next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | my @UNITS = ([ qw(ns us ms s m h d) ],[qw(B KB MB GB TB)]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | my %UNITS = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ns => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | us => 10**3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | ms => 10**3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | s => 10**3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | m => 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | h => 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | d => 24, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | B => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | KB => 2**10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | MB => 2**10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | GB => 2**10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | TB => 2**10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 13 | ▶ | sub _normalize_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_value: called CC=13 SCAR=25.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 13 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 13 | ▶ | my $unit = shift || $self->unit || return ($value,undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
shift() || $self->unit || (return $value, undef)
shift() or $self->unit
MC/DC0%0/2
shift() || $self->unit || (return $value, undef)
shift()
$self->unit
Truth table33%1/3
A or B
A= shift()B= $self->unit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 13 | for my $units (@UNITS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 17 | for my $i (0 .. $#{$units}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 72 | ▶ | next unless $units->[$i] eq $unit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 13 | my $ret = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 13 | my $u = $unit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 13 | ▶ | if (abs($ret) > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # Go up the scale ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 8 | ▶ | return ($value,$unit) if $i == $#{$units}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 6 | for my $j ($i+1 .. $#{$units}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 12 | ▶ | if (abs($ret / $UNITS{$units->[$j]}) >= 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 6 | $ret /= $UNITS{$units->[$j]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 6 | $u = $units->[$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 6 | return ($ret,$u); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # Go down the scale ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 5 | ▶ | return ($value,$unit) if $i == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 5 | for my $j (reverse(0 .. $i-1)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 8 | ▶ | if ($ret < 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 5 | $ret *= $UNITS{$units->[$j+1]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 5 | $u = $units->[$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 3 | return ($ret,$u); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 2 | return ($ret,$u); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | die "Unknown unit '$unit' for value $value"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | sub _sanitize_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sanitize_value: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my ($self,$value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | if ($value =~ /\de/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $value = sprintf("%f", $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | sub _verify_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify_response: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my ($self,$req,$resp) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my $np = $self->{np}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if ($resp->is_error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my $extra = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if ($np->opts->{verbose}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $stacktrace = $resp->stacktrace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | $extra = ref($stacktrace) eq "ARRAY" ? join "\n",@$stacktrace : $stacktrace if $stacktrace; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $self->_die("Error: ".$resp->status." ".$resp->error_text.$extra); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | if (!$req->is_mbean_pattern && (ref($resp->value) && !$self->string) && !JSON::is_bool($resp->value)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
not $req->is_mbean_pattern and (ref $resp->value and not $self->string) and not &JSON::is_bool(scalar $resp->value)
not $req->is_mbean_pattern and (ref $resp->value and not $self->string)
ref $resp->value and not $self->string
MC/DC0%0/4
not $req->is_mbean_pattern and (ref $resp->value and not $self->string) and not &JSON::is_bool(scalar $resp->value)
not $req->is_mbean_pattern
ref $resp->value
not $self->string
not &JSON::is_bool(scalar $resp->value)
Truth table0%0/5
not(A) and B and not(C) and not(D)
A= not $req->is_mbean_patternB= ref $resp->valueC= not $self->stringD= not &JSON::is_bool(scalar $resp->value)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $self->_die("Response value is a " . ref($resp->value) . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | ", not a plain value. Did you forget a --path parameter ?". " Value: " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | Dumper($resp->value)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | ▶ | sub _get_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_name: called CC=10 SCAR=37.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 1 | my $args = { @_ }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 1 | my $name = $args->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 1 | ▶ | if (!$name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 1 | ▶ | if ($self->name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 1 | $name = $self->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # Default name, tried to be generated from various parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if ($self->alias) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | $name = "[".$self->alias.($self->path ? "," . $self->path : "") ."]"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | my $val = $self->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | if ($val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $name = "[" . $val . "]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | my $a_or_o = $self->attribute || $self->operation || ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$self->attribute || $self->operation || ''
$self->attribute or $self->operation
MC/DC0%0/2
$self->attribute || $self->operation || ''
$self->attribute
$self->operation
Truth table0%0/3
A or B
A= $self->attributeB= $self->operation
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | my $p = $self->path ? "," . $self->path : ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | $name = "[" . $self->mbean . "," . $a_or_o . $p . "]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | ▶ | if ($args->{cleanup}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # Enable this when '=' gets forbidden | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | $name =~ s/=/#/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | # Prepare label for usage with Monitoring::Plugin, which will blindly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # add quotes if a space is contained in the label. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # We are doing the escape of quotes ourself here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | $name =~ s/'/''/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | sub _prepare_read_args { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepare_read_args: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | my $np = $self->{np}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | my $jmx = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | if ($self->alias) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | my @req_args = $jmx->resolve_alias($self->alias); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | $self->_die("Cannot resolve attribute alias ",$self->alias()) unless @req_args > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | if ($self->path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | @req_args == 2 ? $req_args[2] = $self->path : $req_args[2] .= "/" . $self->path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | return @req_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } elsif ($self->value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return $self->_split_attr_spec($self->value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | return ($self->mbean,$self->attribute,$self->path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | sub _prepare_exec_args { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepare_exec_args: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | my $np = $self->{np}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | my $jmx = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | #print Dumper($self->{config}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # Merge CLI arguments and arguments from the configuration, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # with CLI arguments taking precedence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | my @cli_args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my $config_args = $self->{config}->{argument}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | $config_args = [ $config_args ] if defined($config_args) && ref($config_args) ne "ARRAY"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $config_args and ref $config_args ne "ARRAY"
MC/DC0%0/2
defined $config_args and ref $config_args ne "ARRAY"
defined $config_args
ref $config_args ne "ARRAY"
Truth table0%0/3
A and B
A= defined $config_argsB= ref $config_args ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my @args = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | if ($config_args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my @c_args = (@$config_args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | while (@cli_args || @c_args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@cli_args or @c_args
MC/DC0%0/2
@cli_args or @c_args
@cli_args
@c_args
Truth table0%0/3
A or B
A= @cli_argsB= @c_args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my $cli_arg = shift @cli_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | my $config_arg = shift @c_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | push @args, defined($cli_arg) ? $cli_arg : $config_arg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | @args = @cli_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | if ($self->alias) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | my @req_args = $jmx->resolve_alias($self->alias); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | $self->_die("Cannot resolve operation alias ",$self->alias()) unless @req_args >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | return (@req_args,@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | return ($self->mbean,$self->operation,@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | sub _split_attr_spec { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_attr_spec: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | my @ret = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | # Text:ParseWords is used for split on "/" taking into account | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # quoting and escaping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | for my $p (parse_line("/",1,$name)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | # We need to 'unescape' things ourselves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | # since we want quotes to remain in the names (using '0' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # above would kill those quotes, too). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | $p =~ s|\\(.)|$1|sg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | push @ret,$p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | return (shift(@ret),shift(@ret),@ret ? join("/",@ret) : undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | sub _check_threshold { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_threshold: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | my $np = $self->{np}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | my $numeric_check; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | if ($self->numeric || $self->string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->numeric or $self->string
MC/DC0%0/2
$self->numeric or $self->string
$self->numeric
$self->string
Truth table0%0/3
A or B
A= $self->numericB= $self->string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | $numeric_check = $self->numeric ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | $numeric_check = looks_like_number($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | if ($numeric_check) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # Verify numeric thresholds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | my @ths = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | defined($self->critical) ? (critical => $self->critical) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | defined($self->warning) ? (warning => $self->warning) : () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | #print Dumper({check => $value,@ths}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | return (@ths ? $np->check_threshold(check => $value,@ths) : OK,"numeric"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | ($self->_check_string_threshold($value,CRITICAL,$self->critical) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$self->_check_string_threshold($value, 2, $self->critical) || $self->_check_string_threshold($value, 1, $self->warning) || 0
$self->_check_string_threshold($value, 2, $self->critical) or $self->_check_string_threshold($value, 1, $self->warning)
MC/DC0%0/2
$self->_check_string_threshold($value, 2, $self->critical) || $self->_check_string_threshold($value, 1, $self->warning) || 0
$self->_check_string_threshold($value, 2, $self->critical)
$self->_check_string_threshold($value, 1, $self->warning)
Truth table0%0/3
A or B
A= $self->_check_string_threshold($value, 2, $self->critical)B= $self->_check_string_threshold($value, 1, $self->warning)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | $self->_check_string_threshold($value,WARNING,$self->warning) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | $value =~ /^true|false$/i ? "boolean" : "string"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | sub _check_string_threshold { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_string_threshold: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | my ($value,$level,$check_value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | return undef unless $check_value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | if ($check_value =~ m|^\s*qr(.)(.*)\1\s*$|) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | return $value =~ m/$2/ ? $level : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | ▶ | if ($check_value =~ s/^\!//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | return $value ne $check_value ? $level : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | return $value eq $check_value ? $level : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | sub _convert_relative_to_absolute { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_convert_relative_to_absolute: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | my ($base_value,@to_convert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | my @ret = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | for my $v (@to_convert) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | $v =~ s|([\d\.]+)|($1 / 100) * $base_value|eg if $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | push @ret,$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | return @ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # Prepare an exit message depending on the result of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | # the check itself. Quite evolved, you can overwrite this always via '--label'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 1 | ▶ | sub _exit_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exit_message: called CC=10 SCAR=34.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 1 | my $args = { @_ }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | # Custom label has precedence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 1 | ▶ | return $self->_format_label($self->label,$args) if $self->label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 1 | my $code = $args->{code}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 1 | my $mode = $args->{mode}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | ▶ | if ($code == CRITICAL || $code == WARNING) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$code == 2 or $code == 1
MC/DC0%0/2
$code == 2 or $code == 1
$code == 2
$code == 1
Truth table33%1/3
A or B
A= $code == 2B= $code == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | if ($self->base || $self->base_mbean) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->base or $self->base_mbean
MC/DC0%0/2
$self->base or $self->base_mbean
$self->base
$self->base_mbean
Truth table0%0/3
A or B
A= $self->baseB= $self->base_mbean
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | return $self->_format_label | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | ('%n : Threshold \'%t\' failed for value %.2r% ('. &_placeholder($args,"v") .' %u / '. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | &_placeholder($args,"b") . ' %u)',$args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | if ($mode ne "numeric") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | return $self->_format_label('%n : \'%v\' matches threshold \'%t\'',$args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | return $self->_format_label | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | ('%n : Threshold \'%t\' failed for value '.&_placeholder($args,"v").' %u',$args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 1 | ▶ | if ($self->base || $self->base_mbean) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->base or $self->base_mbean
MC/DC0%0/2
$self->base or $self->base_mbean
$self->base
$self->base_mbean
Truth table33%1/3
A or B
A= $self->baseB= $self->base_mbean
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | return $self->_format_label('%n : In range %.2r% ('. &_placeholder($args,"v") .' %u / '. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | &_placeholder($args,"b") . ' %w)',$args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | ▶ | if ($mode ne "numeric") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | return $self->_format_label('%n : \'%v\' as expected',$args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 1 | return $self->_format_label('%n : Value '.&_placeholder($args,"v").' %u in range',$args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | ▶ | sub _placeholder { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_placeholder: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 1 | my ($args,$c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 1 | ▶ | if ($c eq "v") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 1 | $val = $args->{value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | $val = $args->{base}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | ▶ | return ($val =~ /\./ ? "%.2" : "%") . $c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 1 | ▶ | sub _format_label { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_label: called CC=25 SCAR=49.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 1 | my $label = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 1 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | # %r : relative value (as percent) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | # %q : relative value (as floating point) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | # %v : value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | # %f : value as floating point | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # %u : unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # %b : base value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # %w : base unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # %t : threshold failed ("" for OK or UNKNOWN) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | # %c : code ("OK", "WARNING", "CRITICAL", "UNKNOWN") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | # %d : delta | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 1 | my @parts = split /(\%[\w\.\-]*\w)/,$label; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 1 | my $ret = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 1 | foreach my $p (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 7 | ▶ | if ($p =~ /^(\%[\w\.\-]*)(\w)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 3 | my ($format,$what) = ($1,$2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 3 | ▶ | if ($what eq "r" || $what eq "q") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
Condition33%1/3
$what eq "r" or $what eq "q"
MC/DC0%0/2
$what eq "r" or $what eq "q"
$what eq "r"
$what eq "q"
Truth table33%1/3
A or B
A= $what eq "r"B= $what eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | my $val = $args->{rel_value} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'rel_value'} || 0
MC/DC0%0/1
$args->{'rel_value'} || 0
$args->{'rel_value'}
Truth table0%0/2
A
A= $args->{'rel_value'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | $val = $what eq "r" ? $val : $val / 100; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | $ret .= sprintf $format . "f",$val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | } elsif ($what eq "b") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | $ret .= sprintf $format . &_format_char($args->{base}),($args->{base} || 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'base'} || 0
MC/DC0%0/1
$args->{'base'} || 0
$args->{'base'}
Truth table0%0/2
A
A= $args->{'base'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | ▶ | } elsif ($what eq "u" || $what eq "w") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$what eq "u" or $what eq "w"
MC/DC50%1/2
$what eq "u" or $what eq "w"
$what eq "u"
$what eq "w"
Truth table66%2/3
A or B
A= $what eq "u"B= $what eq "w"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 1 | ▶ | $ret .= sprintf $format . "s",($what eq "u" ? $args->{unit} : $args->{base_unit}) || ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
($what eq 'u' ? $args->{'unit'} : $args->{'base_unit'}) || ''
MC/DC0%0/1
($what eq 'u' ? $args->{'unit'} : $args->{'base_unit'}) || ''
($what eq 'u' ? $args->{'unit'} : $args->{'base_unit'})
Truth table50%1/2
A
A= ($what eq 'u' ? $args->{'unit'} : $args->{'base_unit'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 1 | $ret =~ s/\s$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } elsif ($what eq "f") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | $ret .= sprintf $format . "f",$args->{value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } elsif ($what eq "v") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 1 | $ret .= &_format_value($format,$args->{mode},$args->{value}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } elsif ($what eq "t") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | my $code = $args->{code}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | my $val = $code == CRITICAL ? $self->critical : ($code == WARNING ? $self->warning : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | $ret .= sprintf $format . "s",defined($val) ? $val : ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } elsif ($what eq "c") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | $ret .= sprintf $format . "s",$STATUS_TEXT{$args->{code}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | } elsif ($what eq "n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 1 | $ret .= sprintf $format . "s",$self->_get_name(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } elsif ($what eq "d") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | $ret .= sprintf $format . "d",$self->delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } elsif ($what eq "y") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | $ret .= &_format_value($format,$args->{mode},$self->warning); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | } elsif ($what eq "z") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | $ret .= &_format_value($format,$args->{mode},$self->critical); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 4 | $ret .= $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 1 | ▶ | if ($args->{prefix}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | my $prefix = $args->{prefix}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | $prefix =~ s/\%c/$STATUS_TEXT{$args->{code}}/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | return $prefix . $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 1 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 1 | ▶ | sub _format_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_value: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 1 | my $format = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 1 | my $mode = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 1 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 1 | ▶ | if ($mode ne "numeric") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | return sprintf $format . "s",$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 1 | return sprintf $format . &_format_char($value),$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 1 | ▶ | sub _format_char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_char: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 1 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 1 | ▶ | $val =~ /\./ ? "f" : "d"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | ▶ | sub _die { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_die: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | my $msg = join("",@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | die $msg,"\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 1 | my $CHECK_CONFIG_KEYS = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | "critical" => "critical", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | "warning" => "warning", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | "mbean" => "mbean", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | "attribute" => "attribute", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | "operation" => "operation", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | "alias" => "alias", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | "path" => "path", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | "delta" => "delta", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | "name" => "name", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | "base" => "base", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | "base-mbean" => "basembean", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | "base-attribute" => "baseattribute", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | "base-path" => "basepath", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | "unit" => "unit", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | "numeric" => "numeric", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | "string" => "string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | "label" => "label", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | "perfdata" => "perfdata", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | "value" => "value", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | "null" => "null", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | "script" => "script" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | # Get the proper configuration values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 9 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=14.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 9 | my $np = $self->{np}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 9 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 9 | $name =~ s/.*://; # strip fully-qualified portion | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 9 | $name =~ s/_/-/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 9 | ▶ | if ($CHECK_CONFIG_KEYS->{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 9 | ▶ | return $np->opts->{$name} if defined($np->opts->{$name}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 3 | ▶ | if ($self->{config}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | return $self->{config}->{$CHECK_CONFIG_KEYS->{$name}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | $self->_die("No config attribute \"" . $name . "\" known"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # To keep autoload happy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | This file is part of jmx4perl. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | Jmx4perl is free software: you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | the Free Software Foundation, either version 2 of the License, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | jmx4perl is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | GNU General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | along with jmx4perl. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | roland@cpan.org | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||