blib/lib/Langertha/Holmgang/Sim/Linux/Monitoring.pm

filter: Statementstmt 90.2% 479 / 531 Branchbran 63.4% 212 / 334 Conditioncond 48.6% 148 / 304 MC/DCmcdc 16.9% 27 / 159 Subroutinesub 100% 39 / 39 Podpod 100% 7 / 7 totaltotal 66.3% 912 / 1374 CC 327 SCAR 40.7
CC
327
Cov
72%
http
174.3
amtool
93.1
_check_rules
72.8
CRAP 58.5
« blib/lib/Langertha/Holmgang/Lint.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Logrotate.pm »
1 package Langertha::Holmgang::Sim::Linux::Monitoring;
2 # ABSTRACT: Monitoring on a simulated Linux server — checks Prometheus/Alertmanager, promtool, amtool
3  
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Text::ParseWords ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 our $VERSION = '0.001';
14  
15  
16 4 our @GAPS;
17  
18 120 ▶sub _file_text {
Subroutine _file_text: called CC=1 SCAR=0.0
19 120 my ( $dev, $p ) = @_;
20 120 require Langertha::Holmgang::Sim::Linux;
21 120 return Langertha::Holmgang::Sim::Linux::_file_text( $dev, $p );
22 }
23  
24 36 ▶sub _glob_files {
Subroutine _glob_files: called CC=3 SCAR=11.2
25 36 my ( $dev, $pat ) = @_;
26 36 ( my $re = quotemeta $pat ) =~ s/\\\*/[^\/]*/g;
27 36 $re =~ s/\\\?/[^\/]/g;
28 36 ▶ return sort grep { /\A$re\z/ && defined _file_text( $dev, $_ ) } keys %{ $dev->{files} || {} };
Condition60%3/5
/\A$re\z/ && defined _file_text($dev, $_)
!ll&&!rl&&r
252036
$$dev{'files'} || {}
l!l
360
MC/DC50%1/2
/\A$re\z/ && defined _file_text($dev, $_)
/\A$re\z/ defined _file_text($dev, $_)
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table66%2/3
A && B
A= /\A$re\z/B= defined _file_text($dev, $_)
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
29 }
30  
31 # YAML laden: ( daten ) oder ( undef, "yaml: line N: …" )
32 90 ▶sub _yaml {
Subroutine _yaml: called CC=5 SCAR=25.2
33 90 my ($text) = @_;
34 90 ▶ my $d = eval { YAML::XS::Load( utf8::is_utf8($text) ? Encode::encode( q{UTF-8}, $text ) : $text ) };
Branch: 1 branch
BranchTrueFalseTotal
utf8::is_utf8($text) ? : 0 90 90
35 90 ▶ return ($d) unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 90 0 90
36 0 my $e = "$@";
37 0 my ($line) = $e =~ /line:\s*(\d+)/;
38 0 my ($what) = $e =~ /YAML::XS::Load Error: The problem:\s*\n?\s*(.+?)(?:\n|$)/;
39 0 ▶ $what //= 'did not find expected key';
Condition0%0/2
$what //= "did not find expected key"
l!l
00
MC/DC0%0/1
$what //= "did not find expected key"
$what
Truth table0%0/2
A
A= $what
Aresult
11
00
40 0 $what =~ s/\s+\z//;
41 0 ▶ return ( undef, 'yaml: line ' . ( $line // 1 ) . ": $what" );
Condition0%0/2
$line // 1
l!l
00
MC/DC0%0/1
$line // 1
$line
Truth table0%0/2
A
A= $line
Aresult
11
00
42 }
43  
44 # Prometheus-Dauer ("90s", "1m30s", "2h") in Sekunden, undef wenn ungueltig
45 79 ▶sub _dur {
Subroutine _dur: called CC=4 SCAR=14.3
46 79 my ($s) = @_;
47 79 ▶ return undef unless defined $s && $s =~ /\A(?:\d+(?:ms|s|m|h|d|w|y))+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and $s =~ /\A(?:\d+(?:ms|s|m|h|d|w|y))+\z/ 0 79 79
Condition33%1/3
defined $s and $s =~ /\A(?:\d+(?:ms|s|m|h|d|w|y))+\z/
!ll&&!rl&&r
0079
MC/DC0%0/2
defined $s and $s =~ /\A(?:\d+(?:ms|s|m|h|d|w|y))+\z/
defined $s $s =~ /\A(?:\d+(?:ms|s|m|h|d|w|y))+\z/
Truth table33%1/3
A and B
A= defined $sB= $s =~ /\A(?:\d+(?:ms|s|m|h|d|w|y))+\z/
ABresult
0X0
100
111
48 79 my %f = ( ms => 0.001, s => 1, m => 60, h => 3600, d => 86400, w => 604800, y => 31536000 );
49 79 my $t = 0;
50 79 ▶ $t += $1 * $f{$2} while $s =~ /(\d+)(ms|s|m|h|d|w|y)/g;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /(\d+)(ms|s|m|h|d|w|y)/g and do { $t += $1 * $f{$2} } 79 79 158
51 79 return $t;
52 }
53  
54 4 our %RULE_KEYS =map { $_ => 1 } qw( alert record expr for labels annotations keep_firing_for );
55  
56 # Regeldatei pruefen: ( zahl der regeln ) oder ( undef, [ fehler ] )
57 39 ▶sub _check_rules {
Subroutine _check_rules: called CC=27 SCAR=42.9
58 39 my ( $path, $text ) = @_;
59 39 my ( $d, $ye ) = _yaml($text);
60 39 ▶ return ( undef, ["$path: $ye"] ) if $ye;
Branch: 1 branch
BranchTrueFalseTotal
if $ye 0 39 39
61 39 ▶ return ( undef, ["$path: yaml: unmarshal errors: groups missing"] ) unless ref $d eq 'HASH' && ref $d->{groups} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $d eq "HASH" and ref $$d{"groups"} eq "ARRAY" 0 39 39
Condition33%1/3
ref $d eq "HASH" and ref $$d{"groups"} eq "ARRAY"
!ll&&!rl&&r
0039
MC/DC0%0/2
ref $d eq "HASH" and ref $$d{"groups"} eq "ARRAY"
ref $d eq "HASH" ref $$d{"groups"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $d eq "HASH"B= ref $$d{"groups"} eq "ARRAY"
ABresult
0X0
100
111
62 39 my ( $n, @e, %gn ) = (0);
63 39 for my $g ( @{ $d->{groups} } ) {
64 39 ▶ push @e, "$path: group name must not be empty" unless ref $g eq 'HASH' && defined $g->{name} && length $g->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $g eq "HASH" and defined $$g{"name"} and length $$g{"name"} 0 39 39
Condition33%2/6
ref $g eq "HASH" and defined $$g{"name"} and length $$g{"name"}
!ll&&!rl&&r
0039
ref $g eq "HASH" and defined $$g{"name"}
!ll&&!rl&&r
0039
MC/DC0%0/3
ref $g eq "HASH" and defined $$g{"name"} and length $$g{"name"}
ref $g eq "HASH" defined $$g{"name"} length $$g{"name"}
Truth table25%1/4
A and B and C
A= ref $g eq "HASH"B= defined $$g{"name"}C= length $$g{"name"}
ABCresult
0XX0
10X0
1100
1111
65 39 ▶ next unless ref $g eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $g eq "HASH" 0 39 39
66 39 ▶ push @e, "$path: $g->{name}: repeated in the same file" if defined $g->{name} && $gn{ $g->{name} }++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$g{"name"} and $gn{$$g{"name"}}++ 0 39 39
Condition33%1/3
defined $$g{"name"} and $gn{$$g{"name"}}++
!ll&&!rl&&r
0390
MC/DC0%0/2
defined $$g{"name"} and $gn{$$g{"name"}}++
defined $$g{"name"} $gn{$$g{"name"}}++
Truth table33%1/3
A and B
A= defined $$g{"name"}B= $gn{$$g{"name"}}++
ABresult
0X0
100
111
67 39 ▶ for my $r ( @{ $g->{rules} || [] } ) {
Condition50%1/2
$$g{'rules'} || []
l!l
390
MC/DC0%0/1
$$g{'rules'} || []
$$g{'rules'}
Truth table50%1/2
A
A= $$g{'rules'}
Aresult
11
00
68 0 ▶ if ( ref $r ne 'HASH' ) { push @e, "$path: rule is not a map"; next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $r ne "HASH") 0 39 39
69 39 ▶ for my $k ( sort keys %$r ) { push @e, "$path: field $k not found in type rulefmt.RuleNode" unless $RULE_KEYS{$k} }
Branch: 1 branch
BranchTrueFalseTotal
unless $Langertha::Holmgang::Sim::Linux::Monitoring::RULE_KEYS{$k} 3 114 117
70 39 ▶ push @e, "$path: group \"$g->{name}\", rule $n: one of 'record' or 'alert' must be set" unless defined $r->{alert} || defined $r->{record};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$r{"alert"} or defined $$r{"record"} 0 39 39
Condition33%1/3
defined $$r{"alert"} or defined $$r{"record"}
l!l&&r!l&&!r
3900
MC/DC0%0/2
defined $$r{"alert"} or defined $$r{"record"}
defined $$r{"alert"} defined $$r{"record"}
Truth table33%1/3
A or B
A= defined $$r{"alert"}B= defined $$r{"record"}
ABresult
1X1
011
000
71 39 ▶ push @e, "$path: group \"$g->{name}\", rule $n: field 'expr' must be set in rule" unless defined $r->{expr} && length $r->{expr};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$r{"expr"} and length $$r{"expr"} 0 39 39
Condition33%1/3
defined $$r{"expr"} and length $$r{"expr"}
!ll&&!rl&&r
0039
MC/DC0%0/2
defined $$r{"expr"} and length $$r{"expr"}
defined $$r{"expr"} length $$r{"expr"}
Truth table33%1/3
A and B
A= defined $$r{"expr"}B= length $$r{"expr"}
ABresult
0X0
100
111
72 39 ▶ if ( defined $r->{expr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$r{"expr"}) 39 0 39
73 39 my $x = $r->{expr};
74 39 my $open = () = $x =~ /\(/g;
75 39 my $close = () = $x =~ /\)/g;
76 39 ▶ push @e, "$path: group \"$g->{name}\", rule $n, \"" . ( $r->{alert} // $r->{record} // '' ) . "\": could not parse expression: 1:1: parse error: unclosed left parenthesis"
Branch: 1 branch
BranchTrueFalseTotal
if $open != $close 0 39 39
Condition0%0/5
($$r{"alert"} // $$r{"record"}) // ""
l!l
00
$$r{"alert"} // $$r{"record"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($$r{"alert"} // $$r{"record"}) // ""
$$r{"alert"} $$r{"record"}
Truth table0%0/3
A // B
A= $$r{"alert"}B= $$r{"record"}
ABresult
1X1
011
000
77 if $open != $close;
78 }
79 39 ▶ if ( defined $r->{for} && $r->{for} !~ /\A\d+(?:ms|s|m|h|d|w|y)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$r{"for"} and not $$r{"for"} =~ /\A\d+(?:ms|s|m|h|d|w|y)\z/) 0 39 39
Condition66%2/3
defined $$r{"for"} and not $$r{"for"} =~ /\A\d+(?:ms|s|m|h|d|w|y)\z/
!ll&&!rl&&r
3360
MC/DC0%0/2
defined $$r{"for"} and not $$r{"for"} =~ /\A\d+(?:ms|s|m|h|d|w|y)\z/
defined $$r{"for"} not $$r{"for"} =~ /\A\d+(?:ms|s|m|h|d|w|y)\z/
Truth table66%2/3
A and not(B)
A= defined $$r{"for"}B= not $$r{"for"} =~ /\A\d+(?:ms|s|m|h|d|w|y)\z/
ABresult
0X0
100
111
80 0 push @e, "$path: group \"$g->{name}\", rule $n: not a valid duration string: \"$r->{for}\"";
81 }
82 39 $n++;
83 }
84 }
85 39 ▶ return ( undef, \@e ) if @e;
Branch: 1 branch
BranchTrueFalseTotal
if @e 3 36 39
86 36 return ($n);
87 }
88  
89  
90 36 ▶sub check_prometheus {
Subroutine check_prometheus: called CC=35 SCAR=39.3
Pod documented
91 36 my ( $dev, $path ) = @_;
92 36 my $text = _file_text( $dev, $path );
93 36 ▶ return ( ["open $path: no such file or directory"], {} ) unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 36 36
94 36 my ( $d, $ye ) = _yaml($text);
95 36 ▶ return ( ["parsing YAML file $path: $ye"], {} ) if $ye;
Branch: 1 branch
BranchTrueFalseTotal
if $ye 0 36 36
96 36 ▶ return ( ["parsing YAML file $path: yaml: unmarshal errors: config is not a map"], {} ) unless ref $d eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $d eq "HASH" 0 36 36
97 36 my @e;
98 36 my %known = map { $_ => 1 } qw( global scrape_configs rule_files alerting remote_write remote_read storage tracing scrape_config_files );
99 36 push @e, "parsing YAML file $path: yaml: unmarshal errors: field $_ not found in type config.plain" for grep { !$known{$_} } sort keys %$d;
100 36 my %jobs;
101 36 ▶ my $g = ref $d->{global} eq 'HASH' ? $d->{global} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$d{'global'} eq 'HASH' ? : 36 0 36
102 36 ▶ my $gi = _dur( $g->{scrape_interval} // '1m' );
Condition50%1/2
$$g{"scrape_interval"} // "1m"
l!l
360
MC/DC0%0/1
$$g{"scrape_interval"} // "1m"
$$g{"scrape_interval"}
Truth table50%1/2
A
A= $$g{"scrape_interval"}
Aresult
11
00
103 36 ▶ my $gt = _dur( $g->{scrape_timeout} // '10s' );
Condition50%1/2
$$g{"scrape_timeout"} // "10s"
l!l
036
MC/DC0%0/1
$$g{"scrape_timeout"} // "10s"
$$g{"scrape_timeout"}
Truth table50%1/2
A
A= $$g{"scrape_timeout"}
Aresult
11
00
104 36 ▶ for my $sc ( @{ $d->{scrape_configs} || [] } ) {
Condition50%1/2
$$d{'scrape_configs'} || []
l!l
360
MC/DC0%0/1
$$d{'scrape_configs'} || []
$$d{'scrape_configs'}
Truth table50%1/2
A
A= $$d{'scrape_configs'}
Aresult
11
00
105 37 ▶ my $j = ref $sc eq 'HASH' ? $sc->{job_name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $sc eq 'HASH' ? : 37 0 37
106 0 ▶ if ( !defined $j || !length $j ) { push @e, "parsing YAML file $path: job_name is empty"; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $j and length $j) 0 37 37
Condition33%1/3
defined $j and length $j
!ll&&!rl&&r
0037
MC/DC0%0/2
defined $j and length $j
defined $j length $j
Truth table33%1/3
A and B
A= defined $jB= length $j
ABresult
0X0
100
111
107 37 ▶ push @e, "parsing YAML file $path: found multiple scrape configs with job name \"$j\"" if $jobs{$j}++;
Branch: 1 branch
BranchTrueFalseTotal
if $jobs{$j}++ 1 36 37
108 37 ▶ my $iv = defined $sc->{scrape_interval} ? _dur( $sc->{scrape_interval} ) : $gi;
Branch: 1 branch
BranchTrueFalseTotal
defined $$sc{'scrape_interval'} ? : 1 36 37
109 37 ▶ my $to = defined $sc->{scrape_timeout} ? _dur( $sc->{scrape_timeout} ) : ( $gt > $iv ? $iv : $gt );
Branch: 2 branches
BranchTrueFalseTotal
defined $$sc{'scrape_timeout'} ? : 2 35 37
$gt > $iv ? : 0 35 35
110 37 for my $k (qw( scrape_interval scrape_timeout )) {
111 74 ▶ push @e, "parsing YAML file $path: not a valid duration string: \"$sc->{$k}\"" if defined $sc->{$k} && !defined _dur( $sc->{$k} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $$sc{$k} and not defined _dur($$sc{$k}) 0 74 74
Condition66%2/3
defined $$sc{$k} and not defined _dur($$sc{$k})
!ll&&!rl&&r
7130
MC/DC0%0/2
defined $$sc{$k} and not defined _dur($$sc{$k})
defined $$sc{$k} not defined _dur($$sc{$k})
Truth table66%2/3
A and not(B)
A= defined $$sc{$k}B= not defined _dur($$sc{$k})
ABresult
0X0
100
111
112 }
113 37 ▶ push @e, "parsing YAML file $path: scrape timeout greater than scrape interval for scrape config with job name \"$j\""
Branch: 1 branch
BranchTrueFalseTotal
if defined $iv and defined $to and $to > $iv 1 36 37
Condition50%3/6
defined $iv and defined $to and $to > $iv
!ll&&!rl&&r
0361
defined $iv and defined $to
!ll&&!rl&&r
0037
MC/DC33%1/3
defined $iv and defined $to and $to > $iv
defined $iv defined $to $to > $iv
Truth table50%2/4
A and B and C
A= defined $ivB= defined $toC= $to > $iv
ABCresult
0XX0
10X0
1100
1111
114 if defined $iv && defined $to && $to > $iv;
115 37 ▶ for my $s ( @{ $sc->{static_configs} || [] } ) {
Condition100%2/2
$$sc{'static_configs'} || []
l!l
361
MC/DC100%1/1
$$sc{'static_configs'} || []
$$sc{'static_configs'}
Truth table100%2/2
A
A= $$sc{'static_configs'}
Aresult
11
00
116 36 ▶ for my $t ( @{ ( ref $s eq 'HASH' ? $s->{targets} : undef ) || [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $s eq 'HASH' ? : 36 0 36
Condition50%1/2
(ref $s eq 'HASH' ? $$s{'targets'} : undef) || []
l!l
360
MC/DC0%0/1
(ref $s eq 'HASH' ? $$s{'targets'} : undef) || []
(ref $s eq 'HASH' ? $$s{'targets'} : undef)
Truth table50%1/2
A
A= (ref $s eq 'HASH' ? $$s{'targets'} : undef)
Aresult
11
00
117 36 ▶ push @e, "parsing YAML file $path: \"$t\" is not a valid hostname" unless defined $t && $t =~ /\A[\w.\-\[\]:]+:\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t and $t =~ /\A[\w.\-\[\]:]+:\d+\z/ 0 36 36
Condition33%1/3
defined $t and $t =~ /\A[\w.\-\[\]:]+:\d+\z/
!ll&&!rl&&r
0036
MC/DC0%0/2
defined $t and $t =~ /\A[\w.\-\[\]:]+:\d+\z/
defined $t $t =~ /\A[\w.\-\[\]:]+:\d+\z/
Truth table33%1/3
A and B
A= defined $tB= $t =~ /\A[\w.\-\[\]:]+:\d+\z/
ABresult
0X0
100
111
118 }
119 }
120 }
121 36 my ( %rules, $nr );
122 36 ▶ for my $pat ( @{ $d->{rule_files} || [] } ) {
Condition50%1/2
$$d{'rule_files'} || []
l!l
360
MC/DC0%0/1
$$d{'rule_files'} || []
$$d{'rule_files'}
Truth table50%1/2
A
A= $$d{'rule_files'}
Aresult
11
00
123 36 ( my $p = $pat ) =~ s{\A(?!/)}{ ( $path =~ m{\A(.*)/} )[0] . '/' }e;
124 36 for my $f ( _glob_files( $dev, $p ) ) {
125 36 my $t = _file_text( $dev, $f );
126 36 my ( $n, $re ) = _check_rules( $f, $t );
127 36 ▶ if ($re) { push @e, map {"loading groups failed: $_"} @$re; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($re) 2 34 36
128 34 $rules{$f} = $t;
129 34 $nr += $n;
130 }
131 }
132 36 ▶ return ( \@e, \%rules, $nr // 0 );
Condition100%2/2
$nr // 0
l!l
342
MC/DC100%1/1
$nr // 0
$nr
Truth table100%2/2
A
A= $nr
Aresult
11
00
133 }
134  
135  
136 2 ▶sub check_alertmanager {
Subroutine check_alertmanager: called CC=2 SCAR=7.0
Pod documented
137 2 my ( $dev, $path ) = @_;
138 2 my $text = _file_text( $dev, $path );
139 2 ▶ return ["open $path: no such file or directory"] unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 2 2
140 2 return _am_check_text($text);
141 }
142  
143 8 ▶sub _am_check_text {
Subroutine _am_check_text: called CC=7 SCAR=20.9
144 8 my ($text) = @_;
145 8 my ( $d, $ye ) = _yaml($text);
146 8 ▶ return [$ye] if $ye;
Branch: 1 branch
BranchTrueFalseTotal
if $ye 0 8 8
147 8 ▶ return ['no route provided in config'] unless ref $d eq 'HASH' && ref $d->{route} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $d eq "HASH" and ref $$d{"route"} eq "HASH" 0 8 8
Condition33%1/3
ref $d eq "HASH" and ref $$d{"route"} eq "HASH"
!ll&&!rl&&r
008
MC/DC0%0/2
ref $d eq "HASH" and ref $$d{"route"} eq "HASH"
ref $d eq "HASH" ref $$d{"route"} eq "HASH"
Truth table33%1/3
A and B
A= ref $d eq "HASH"B= ref $$d{"route"} eq "HASH"
ABresult
0X0
100
111
148 8 ▶ my %recv = map { ( ref $_ eq 'HASH' ? $_->{name} // '' : '' ) => 1 } @{ $d->{receivers} || [] };
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 25 0 25
Condition50%2/4
$$_{"name"} // ""
l!l
250
$$d{'receivers'} || []
l!l
80
MC/DC0%0/1
$$_{"name"} // ""
$$_{"name"}
MC/DC0%0/1
$$d{'receivers'} || []
$$d{'receivers'}
Truth table50%1/2
A
A= $$_{"name"}
Aresult
11
00
Truth table50%1/2
A
A= $$d{'receivers'}
Aresult
11
00
149 8 my @e;
150 my $walk;
151 27 ▶ $walk = sub {
Subroutine __ANON__: called CC=6 SCAR=19.0
152 27 my ( $r, $top ) = @_;
153 27 ▶ if ( defined $r->{receiver} ) { push @e, "undefined receiver \"$r->{receiver}\" used in route" unless $recv{ $r->{receiver} } }
Branch: 3 branches
BranchTrueFalseTotal
if (defined $$r{'receiver'}) { } 27 0 27
elsif ($top) { } 0 0 0
unless $recv{$$r{"receiver"}} 2 25 27
154 0 elsif ($top) { push @e, 'root route must specify a default receiver' }
155 27 ▶ $walk->( $_, 0 ) for grep { ref $_ eq 'HASH' } @{ $r->{routes} || [] };
Condition100%2/2
$$r{'routes'} || []
l!l
819
MC/DC100%1/1
$$r{'routes'} || []
$$r{'routes'}
Truth table100%2/2
A
A= $$r{'routes'}
Aresult
11
00
156 8 };
157 8 $walk->( $d->{route}, 1 );
158 8 return \@e;
159 }
160  
161  
162 33 ▶sub service_check {
Subroutine service_check: called CC=7 SCAR=20.1
Pod documented
163 33 my ( $dev, $svc, $kind ) = @_;
164 33 ▶ my $main = $svc->{config_main} // ( ref $svc->{config} ? $svc->{config}[0] : $svc->{config} );
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'config'} ? : 1 0 1
Condition66%2/3
$$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
l!l&&r!l&&!r
3210
MC/DC0%0/2
$$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
$$svc{"config_main"} (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
Truth table66%2/3
A // B
A= $$svc{"config_main"}B= (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
ABresult
1X1
011
000
165 33 my $ts = 'ts=2026-10-24T09:12:03.000Z';
166 33 ▶ if ( $kind eq 'prometheus' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "prometheus") 32 1 33
167 32 my ( $e, $rules ) = check_prometheus( $dev, $main );
168 32 ▶ return ( [ map {qq{$ts caller=main.go:1150 level=error msg="Error reloading config" err="couldn't load configuration (--config.file=\\"$main\\"): $_"}} @$e ], {} ) if @$e;
Branch: 1 branch
BranchTrueFalseTotal
if @$e 2 30 32
169 30 return ( [], $rules );
170 }
171 1 ▶ if ( $kind eq 'alertmanager' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "alertmanager") 1 0 1
172 1 my $e = check_alertmanager( $dev, $main );
173 0 ▶ return ( [ map {qq{$ts caller=coordinator.go:118 level=error component=configuration msg="Loading configuration file failed" file=$main err="$_"}} @$e ], {} ) if @$e;
Branch: 1 branch
BranchTrueFalseTotal
if @$e 0 1 1
174 1 $svc->{_routes} = _am_routes( _file_text( $dev, $main ) );
175 1 return ( [], {} );
176 }
177 0 return ( [], {} );
178 }
179  
180  
181 10 ▶sub http {
Subroutine http: called CC=46 SCAR=51.6
Pod documented
182 10 my ( $dev, $method, $port, $path, $run ) = @_;
183 10 ▶ my $kind = $port == 9090 ? 'prometheus' : $port == 9093 ? 'alertmanager' : return;
Branch: 2 branches
BranchTrueFalseTotal
$port == 9090 ? : 10 0 10
$port == 9093 ? : 0 0 0
184 10 my ( $name, $svc ) = map { ( $_, $dev->{services}{$_} ) }
185 10 ▶ grep { ( $dev->{services}{$_}{config_check} // '' ) eq $kind } sort keys %{ $dev->{services} || {} };
Condition75%3/4
$$dev{"services"}{$_}{"config_check"} // ""
l!l
1010
$$dev{'services'} || {}
l!l
100
MC/DC100%1/1
$$dev{"services"}{$_}{"config_check"} // ""
$$dev{"services"}{$_}{"config_check"}
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table100%2/2
A
A= $$dev{"services"}{$_}{"config_check"}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
186 10 ▶ return ( '', 0 ) unless $svc && $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $svc and $$svc{"active"} 1 9 10
Condition66%2/3
$svc and $$svc{"active"}
!ll&&!rl&&r
019
MC/DC50%1/2
$svc and $$svc{"active"}
$svc $$svc{"active"}
Truth table66%2/3
A and B
A= $svcB= $$svc{"active"}
ABresult
0X0
100
111
187 9 ▶ my $run_cfg = ref $svc->{running} eq 'HASH' ? $svc->{running} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 9 0 9
188 9 ▶ my $main = $svc->{config_main} // ( ref $svc->{config} ? $svc->{config}[0] : $svc->{config} );
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'config'} ? : 0 0 0
Condition33%1/3
$$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
l!l&&r!l&&!r
900
MC/DC0%0/2
$$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
$$svc{"config_main"} (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
Truth table33%1/3
A // B
A= $$svc{"config_main"}B= (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
ABresult
1X1
011
000
189 9 $path =~ s/\?.*//;
190 9 ▶ my $js = sub { JSON::MaybeXS->new( canonical => 1 )->encode( { status => 'success', data => $_[0] } ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
191 9 ▶ if ( $kind eq 'prometheus' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "prometheus") 9 0 9
192 9 ▶ return ( 'Prometheus Server is Healthy.', 200 ) if $path eq '/-/healthy';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/-/healthy" 1 8 9
193 8 ▶ return ( 'Prometheus Server is Ready.', 200 ) if $path eq '/-/ready';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/-/ready" 0 8 8
194 8 ▶ if ( $path eq '/-/reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/-/reload") 2 6 8
195 2 ▶ return ( 'Only POST or PUT requests allowed', 405 ) if $method ne 'POST';
Branch: 1 branch
BranchTrueFalseTotal
if $method ne "POST" 0 2 2
196 2 ▶ my $args = join ' ', map { $run_cfg->{$_} // '' } grep { m{\A/etc/default/} } keys %$run_cfg;
Condition50%1/2
$$run_cfg{$_} // ""
l!l
20
MC/DC0%0/1
$$run_cfg{$_} // ""
$$run_cfg{$_}
Truth table50%1/2
A
A= $$run_cfg{$_}
Aresult
11
00
197 2 ▶ return ( 'Lifecycle API is not enabled.', 403 ) unless $args =~ /--web\.enable-lifecycle/;
Branch: 1 branch
BranchTrueFalseTotal
unless $args =~ /--web\.enable-lifecycle/ 1 1 2
198 1 my ( $o, $ok ) = $run->("systemctl reload $name");
199 1 ▶ return ( $ok ? '' : "failed to reload config: $o", $ok ? 200 : 500 );
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 1 0 1
$ok ? : 1 0 1
200 }
201 6 ▶ return ( $js->( { yaml => $run_cfg->{$main} // '' } ), 200 ) if $path eq '/api/v1/status/config';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/api/v1/status/config" 1 5 6
Condition50%1/2
$$run_cfg{$main} // ""
l!l
10
MC/DC0%0/1
$$run_cfg{$main} // ""
$$run_cfg{$main}
Truth table50%1/2
A
A= $$run_cfg{$main}
Aresult
11
00
202 5 ▶ return ( $js->( _prom_flags($run_cfg) ), 200 ) if $path eq '/api/v1/status/flags';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/api/v1/status/flags" 3 2 5
203 2 ▶ return ( $js->( { alerts => [] } ), 200 ) if $path eq '/api/v1/alerts'; # Regeln stehen auf inactive
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/api/v1/alerts" 1 1 2
204 1 ▶ if ( $path eq '/api/v1/rules' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/api/v1/rules") 1 0 1
205 1 my @groups;
206 1 ▶ for my $f ( sort grep { $_ ne $main && !m{\A/etc/default/} } keys %$run_cfg ) {
Condition100%3/3
$_ ne $main && !m[\A/etc/default/]
!ll&&!rl&&r
111
MC/DC100%2/2
$_ ne $main && !m[\A/etc/default/]
$_ ne $main !m[\A/etc/default/]
Truth table100%3/3
A && not(B)
A= $_ ne $mainB= !m[\A/etc/default/]
ABresult
0X0
100
111
207 1 my ($d) = _yaml( $run_cfg->{$f} );
208 1 ▶ for my $g ( @{ ( ref $d eq 'HASH' ? $d->{groups} : undef ) || [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $d eq 'HASH' ? : 1 0 1
Condition50%1/2
(ref $d eq 'HASH' ? $$d{'groups'} : undef) || []
l!l
10
MC/DC0%0/1
(ref $d eq 'HASH' ? $$d{'groups'} : undef) || []
(ref $d eq 'HASH' ? $$d{'groups'} : undef)
Truth table50%1/2
A
A= (ref $d eq 'HASH' ? $$d{'groups'} : undef)
Aresult
11
00
209 1 my @r;
210 1 ▶ for my $x ( grep { ref $_ eq 'HASH' } @{ $g->{rules} || [] } ) {
Condition50%1/2
$$g{'rules'} || []
l!l
10
MC/DC0%0/1
$$g{'rules'} || []
$$g{'rules'}
Truth table50%1/2
A
A= $$g{'rules'}
Aresult
11
00
211 my %r = ( name => $x->{alert} // $x->{record}, query => $x->{expr}, health => 'ok',
212 1 ▶ type => defined $x->{alert} ? 'alerting' : 'recording' );
Branch: 1 branch
BranchTrueFalseTotal
defined $$x{'alert'} ? : 1 0 1
Condition33%1/3
$$x{"alert"} // $$x{"record"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$$x{"alert"} // $$x{"record"}
$$x{"alert"} $$x{"record"}
Truth table33%1/3
A // B
A= $$x{"alert"}B= $$x{"record"}
ABresult
1X1
011
000
213 %r = ( %r, duration => _dur( $x->{for} // '0s' ) // 0, labels => $x->{labels} // {},
214 1 ▶ annotations => $x->{annotations} // {}, state => 'inactive', alerts => [] ) if defined $x->{alert};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$x{"alert"} 1 0 1
Condition50%4/8
_dur($$x{"for"} // "0s") // 0
l!l
10
$$x{"for"} // "0s"
l!l
10
$$x{"labels"} // {}
l!l
01
$$x{"annotations"} // {}
l!l
01
MC/DC0%0/1
_dur($$x{"for"} // "0s") // 0
_dur($$x{"for"} // "0s")
MC/DC0%0/1
$$x{"for"} // "0s"
$$x{"for"}
MC/DC0%0/1
$$x{"labels"} // {}
$$x{"labels"}
MC/DC0%0/1
$$x{"annotations"} // {}
$$x{"annotations"}
Truth table50%1/2
A
A= _dur($$x{"for"} // "0s")
Aresult
11
00
Truth table50%1/2
A
A= $$x{"for"}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"labels"}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"annotations"}
Aresult
11
00
215 1 push @r, \%r;
216 }
217 1 push @groups, { name => $g->{name}, file => $f, interval => 15, rules => \@r };
218 }
219 }
220 1 return ( $js->( { groups => \@groups } ), 200 );
221 }
222 0 return;
223 }
224 0 ▶ return ( 'OK', 200 ) if $path eq '/-/healthy' || $path eq '/-/ready';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/-/healthy" or $path eq "/-/ready" 0 0 0
Condition0%0/3
$path eq "/-/healthy" or $path eq "/-/ready"
l!l&&r!l&&!r
000
MC/DC0%0/2
$path eq "/-/healthy" or $path eq "/-/ready"
$path eq "/-/healthy" $path eq "/-/ready"
Truth table0%0/3
A or B
A= $path eq "/-/healthy"B= $path eq "/-/ready"
ABresult
1X1
011
000
225 0 ▶ if ( $path eq '/-/reload' ) { # bei Alertmanager immer offen
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/-/reload") 0 0 0
226 0 ▶ return ( 'Only POST requests allowed', 405 ) if $method ne 'POST';
Branch: 1 branch
BranchTrueFalseTotal
if $method ne "POST" 0 0 0
227 0 my ( $o, $ok ) = $run->("systemctl reload $name");
228 0 ▶ return ( $ok ? '' : "failed to reload config: $o", $ok ? 200 : 500 );
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 0 0 0
$ok ? : 0 0 0
229 }
230 0 ▶ if ( $path eq '/api/v2/status' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/api/v2/status") 0 0 0
231 0 ▶ return ( JSON::MaybeXS->new( canonical => 1 )->encode( { config => { original => $run_cfg->{$main} // '' }, cluster => { status => 'disabled' } } ), 200 );
Condition0%0/2
$$run_cfg{$main} // ""
l!l
00
MC/DC0%0/1
$$run_cfg{$main} // ""
$$run_cfg{$main}
Truth table0%0/2
A
A= $$run_cfg{$main}
Aresult
11
00
232 }
233 0 return;
234 }
235  
236 # Startoptionen, mit denen Prometheus laeuft (ARGS aus /etc/default/*), ueber den
237 # Standardwerten von Prometheus 2.x (Debian-Pfade). Werte sind Strings wie in der API.
238 4 my %PROM_FLAG_DEFAULT = (
239 'config.file' => '/etc/prometheus/prometheus.yml',
240 'storage.tsdb.path' => '/var/lib/prometheus/metrics2/',
241 'storage.tsdb.retention.time' => '0s',
242 'storage.tsdb.retention.size' => '0B',
243 'web.listen-address' => '0.0.0.0:9090',
244 'web.external-url' => '',
245 'web.enable-lifecycle' => 'false',
246 'web.enable-admin-api' => 'false',
247 'log.level' => 'info',
248 );
249  
250 3 ▶sub _prom_flags {
Subroutine _prom_flags: called CC=13 SCAR=29.3
251 3 my ($run_cfg) = @_;
252 3 my %f = %PROM_FLAG_DEFAULT;
253 3 for my $file ( sort grep { m{\A/etc/default/} } keys %$run_cfg ) {
254 3 ▶ for my $line ( split /\n/, $run_cfg->{$file} // '' ) {
Condition50%1/2
$$run_cfg{$file} // ""
l!l
30
MC/DC0%0/1
$$run_cfg{$file} // ""
$$run_cfg{$file}
Truth table50%1/2
A
A= $$run_cfg{$file}
Aresult
11
00
255 3 ▶ next unless $line =~ /\A\s*ARGS=(.*)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\A\s*ARGS=(.*)\z/ 0 3 3
256 3 my $args = $1; # Kopie: shellwords bekaeme $1 als Alias
257 # die Shell entquotet ARGS="…", systemd teilt $ARGS an Leerraum
258 3 my @w = split q{ }, join q{ }, Text::ParseWords::shellwords($args);
259 3 ▶ while ( defined( my $w = shift @w ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $w = shift @w)) 4 3 7
260 4 ▶ next unless $w =~ /\A--?(?:no-)?([\w.\-]+)(?:=(.*))?\z/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $w =~ /\A--?(?:no-)?([\w.\-]+)(?:=(.*))?\z/s 0 4 4
261 4 my ( $k, $v ) = ( $1, $2 );
262 0 ▶ if ( $w =~ /\A--?no-/ ) { $f{$k} = 'false'; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($w =~ /\A--?no-/) 0 4 4
263 4 ▶ $v //= @w && $w[0] !~ /\A-/ && ( $f{$k} // '' ) !~ /\A(?:true|false)\z/ ? shift @w : 'true';
Branch: 1 branch
BranchTrueFalseTotal
@w && !($w[0] =~ /\A-/) && !(($f{$k} // '') =~ /\A(?:true|false)\z/) ? : 0 3 3
Condition45%5/11
$v //= @w && !($w[0] =~ /\A-/) && !(($f{$k} // "") =~ /\A(?:true|false)\z/) ? shift @w : "true"
l!l&&r!l&&!r
130
@w and not $w[0] =~ /\A-/ and not +($f{$k} // "") =~ /\A(?:true|false)\z/
!ll&&!rl&&r
300
@w and not $w[0] =~ /\A-/
!ll&&!rl&&r
210
$f{$k} // ""
l!l
00
MC/DC0%0/4
$v //= @w && !($w[0] =~ /\A-/) && !(($f{$k} // "") =~ /\A(?:true|false)\z/) ? shift @w : "true"
$v @w not $w[0] =~ /\A-/ $f{$k}
Truth table0%0/5
A //= B and not(C) and not(D)
A= $vB= @wC= not $w[0] =~ /\A-/D= $f{$k}
ABCDresult
1XXX1
01101
00XX0
010X0
01110
264 4 $f{$k} = $v;
265 }
266 }
267 }
268 3 return \%f;
269 }
270  
271  
272 5 ▶sub promtool {
Subroutine promtool: called CC=13 SCAR=27.4
Pod documented
273 5 my ( $dev, $av ) = @_;
274 5 my @a = grep { !/\A--/ } @$av;
275 5 my ( $cmd, $what, @files ) = @a;
276 0 ▶ if ( ( $cmd // '' ) ne 'check' || ( $what // '' ) !~ /\A(?:config|rules)\z/ ) { push @GAPS, join( ' ', 'promtool', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (($cmd // "") ne "check" or not +($what // "") =~ /\A(?:config|rules)\z/) 0 5 5
Condition42%3/7
($cmd // "") ne "check" or not +($what // "") =~ /\A(?:config|rules)\z/
l!l&&r!l&&!r
005
$cmd // ""
l!l
50
$what // ""
l!l
50
MC/DC0%0/2
($cmd // "") ne "check" or not +($what // "") =~ /\A(?:config|rules)\z/
$cmd $what
Truth table0%0/3
A or not(B)
A= $cmdB= $what
ABresult
1X1
001
010
277 5 my ( @out, $ok );
278 5 $ok = 1;
279 5 for my $f (@files) {
280 5 push @out, "Checking $f";
281 5 ▶ if ( $what eq 'config' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq 'config') { } 4 1 5
282 4 my ( $e, $rules, $n ) = check_prometheus( $dev, $f );
283 4 ▶ if (@$e) { push @out, map {" FAILED: $_"} @$e; $ok = 0; push @out, ''; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@$e) 2 2 4
284 2 push @out, ' SUCCESS: ' . scalar( keys %$rules ) . ' rule files found', " SUCCESS: $f is valid prometheus config file syntax", '';
285 2 for my $r ( sort keys %$rules ) { push @out, "Checking $r", " SUCCESS: " . ( _check_rules( $r, $rules->{$r} ) )[0] . ' rules found', '' }
286 }
287 else {
288 1 my $t = _file_text( $dev, $f );
289 0 ▶ if ( !defined $t ) { push @out, " FAILED:", "open $f: no such file or directory", ''; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 1 1
290 1 my ( $n, $e ) = _check_rules( $f, $t );
291 1 ▶ if ($e) { push @out, ' FAILED:', @$e, ''; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($e) 1 0 1
292 0 push @out, " SUCCESS: $n rules found", '';
293 }
294 }
295 5 ▶ pop @out while @out && $out[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
@out and $out[-1] eq "" and do { pop @out } 5 5 10
Condition66%2/3
@out and $out[-1] eq ""
!ll&&!rl&&r
055
MC/DC50%1/2
@out and $out[-1] eq ""
@out $out[-1] eq ""
Truth table66%2/3
A and B
A= @outB= $out[-1] eq ""
ABresult
0X0
100
111
296 5 return ( join( "\n", @out ), $ok );
297 }
298  
299  
300 # Wirksame Einstellungen je Empfaenger: { empfaenger => { repeat_interval, group_wait,
301 # group_interval, group_by } } — Unterrouten erben, was sie nicht selbst setzen (erste Route je Empfaenger)
302 4 our %AM_ROUTE_DEFAULT = ( group_wait => '30s', group_interval => '5m', repeat_interval => '4h' );
303  
304 1 ▶sub _am_routes {
Subroutine _am_routes: called CC=2 SCAR=7.1
305 1 my ($text) = @_;
306 1 my ($d) = _yaml($text);
307 1 my %out;
308 my $walk;
309 3 ▶ $walk = sub {
Subroutine __ANON__: called CC=9 SCAR=22.9
310 3 my ( $r, $parent ) = @_;
311 3 ▶ return unless ref $r eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $r eq "HASH" 0 3 3
312 3 my %eff = %$parent;
313 3 ▶ for my $k (qw( receiver repeat_interval group_wait group_interval )) { $eff{$k} = $r->{$k} if defined $r->{$k} }
Branch: 1 branch
BranchTrueFalseTotal
if defined $$r{$k} 5 7 12
314 0 ▶ $eff{group_by} = join( ',', @{ $r->{group_by} } ) if ref $r->{group_by} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $$r{"group_by"} eq "ARRAY" 0 3 3
315 3 my %copy = %eff;
316 3 ▶ $out{ $eff{receiver} } //= \%copy if defined $eff{receiver};
Branch: 1 branch
BranchTrueFalseTotal
if defined $eff{"receiver"} 3 0 3
Condition50%1/2
$out{$eff{"receiver"}} //= \%copy
l!l
03
MC/DC0%0/1
$out{$eff{"receiver"}} //= \%copy
$out{$eff{"receiver"}}
Truth table50%1/2
A
A= $out{$eff{"receiver"}}
Aresult
11
00
317 3 ▶ $walk->( $_, \%eff ) for @{ $r->{routes} || [] };
Condition100%2/2
$$r{'routes'} || []
l!l
12
MC/DC100%1/1
$$r{'routes'} || []
$$r{'routes'}
Truth table100%2/2
A
A= $$r{'routes'}
Aresult
11
00
318 1 };
319 1 ▶ $walk->( ref $d eq 'HASH' ? $d->{route} : undef, {%AM_ROUTE_DEFAULT} );
Branch: 1 branch
BranchTrueFalseTotal
ref $d eq 'HASH' ? : 1 0 1
320 1 return \%out;
321 }
322  
323 # Zeit: Uhr des Geraets (clock "Oct 24 09:12", Jahr 2026, Zone tz, Vorgabe +02:00) als Epoche
324 4 our %MON = ( Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4, Jun => 5, Jul => 6, Aug => 7, Sep => 8, Oct => 9, Nov => 10, Dec => 11 );
325  
326  
327 25 ▶sub now_epoch {
Subroutine now_epoch: called CC=3 SCAR=11.4
Pod documented
328 25 my ($dev) = @_;
329 25 require Time::Local;
330 25 ▶ my ( $mon, $day, $h, $mi ) = ( $dev->{clock} // 'Oct 20 09:12' ) =~ /\A(\w{3})\s+(\d+)\s+(\d+):(\d+)/;
Condition50%1/2
$$dev{"clock"} // "Oct 20 09:12"
l!l
250
MC/DC0%0/1
$$dev{"clock"} // "Oct 20 09:12"
$$dev{"clock"}
Truth table50%1/2
A
A= $$dev{"clock"}
Aresult
11
00
331 25 ▶ return Time::Local::timegm( 0, $mi, $h, $day, $MON{$mon} // 9, 2026 ) - _tz_secs($dev);
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::Monitoring::MON{$mon} // 9
l!l
250
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::Monitoring::MON{$mon} // 9
$Langertha::Holmgang::Sim::Linux::Monitoring::MON{$mon}
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::Monitoring::MON{$mon}
Aresult
11
00
332 }
333  
334 25 ▶sub _tz_secs {
Subroutine _tz_secs: called CC=4 SCAR=14.3
335 25 my ($dev) = @_;
336 25 ▶ my ( $sg, $h, $m ) = ( $dev->{tz} // '+02:00' ) =~ /\A([+-])(\d\d):?(\d\d)\z/ or return 0;
Branch: 1 branch
BranchTrueFalseTotal
() = ($$dev{"tz"} // "+02:00") =~ /\A([+-])(\d\d):?(\d\d)\z/ or return 0 25 0 25
Condition100%2/2
$$dev{"tz"} // "+02:00"
l!l
1213
MC/DC100%1/1
$$dev{"tz"} // "+02:00"
$$dev{"tz"}
Truth table100%2/2
A
A= $$dev{"tz"}
Aresult
11
00
337 25 ▶ return ( $sg eq '-' ? -1 : 1 ) * ( $h * 3600 + $m * 60 );
Branch: 1 branch
BranchTrueFalseTotal
$sg eq '-' ? : 0 25 25
338 }
339  
340 # RFC 3339 -> Epoche; undef wenn nicht lesbar
341 2 ▶sub _rfc3339 {
Subroutine _rfc3339: called CC=5 SCAR=16.8
342 2 my ($t) = @_;
343 2 require Time::Local;
344 2 ▶ my ( $Y, $M, $D, $h, $m, $s, $z ) = ( $t // '' ) =~ /\A(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(Z|[+-]\d\d:\d\d)\z/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = ($t // "") =~ /\A(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d+)?(Z|[+-]\d\d:\d\d)\z/ or return undef 2 0 2
Condition50%1/2
$t // ""
l!l
20
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
345 2 my $e = Time::Local::timegm( $s, $m, $h, $D, $M - 1, $Y );
346 2 ▶ if ( $z ne 'Z' ) { my ( $sg, $zh, $zm ) = $z =~ /([+-])(\d\d):(\d\d)/; $e -= ( $sg eq '-' ? -1 : 1 ) * ( $zh * 3600 + $zm * 60 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($z ne "Z") 2 0 2
$sg eq '-' ? : 0 2 2
347 2 return $e;
348 }
349  
350 22 ▶sub _iso { my @t = gmtime $_[0]; return sprintf '%04d-%02d-%02dT%02d:%02d:%02dZ', $t[5] + 1900, $t[4] + 1, @t[ 3, 2, 1, 0 ] }
Subroutine _iso: called CC=1 SCAR=0.0
351  
352 # Go-Dauer: 2h, 90m, 1h30m, 45s
353 1 ▶sub _godur {
Subroutine _godur: called CC=4 SCAR=14.3
354 1 my ($d) = @_;
355 1 ▶ return undef unless defined $d && $d =~ /\A(?:\d+(?:\.\d+)?(?:h|m|s|ms))+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d and $d =~ /\A(?:\d+(?:\.\d+)?(?:h|m|s|ms))+\z/ 0 1 1
Condition33%1/3
defined $d and $d =~ /\A(?:\d+(?:\.\d+)?(?:h|m|s|ms))+\z/
!ll&&!rl&&r
001
MC/DC0%0/2
defined $d and $d =~ /\A(?:\d+(?:\.\d+)?(?:h|m|s|ms))+\z/
defined $d $d =~ /\A(?:\d+(?:\.\d+)?(?:h|m|s|ms))+\z/
Truth table33%1/3
A and B
A= defined $dB= $d =~ /\A(?:\d+(?:\.\d+)?(?:h|m|s|ms))+\z/
ABresult
0X0
100
111
356 1 my $t = 0;
357 1 ▶ while ( $d =~ /(\d+(?:\.\d+)?)(ms|h|m|s)/g ) { $t += $1 * { h => 3600, m => 60, s => 1, ms => 0.001 }->{$2} }
Branch: 1 branch
BranchTrueFalseTotal
if ($d =~ /(\d+(?:\.\d+)?)(ms|h|m|s)/g) 1 1 2
358 1 return int $t;
359 }
360  
361 # Matcher: name=wert, name!=wert, name=~re, name!~re (Wert ggf. in Anfuehrungszeichen)
362 19 ▶sub _am_matcher {
Subroutine _am_matcher: called CC=2 SCAR=7.0
363 19 my ($x) = @_;
364 19 ▶ my ( $n, $op, $v ) = $x =~ /\A\s*([A-Za-z_]\w*)\s*(=~|!~|!=|=)\s*(.*?)\s*\z/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = $x =~ /\A\s*([A-Za-z_]\w*)\s*(=~|!~|!=|=)\s*(.*?)\s*\z/ or return undef 19 0 19
365 19 $v =~ s/\A"(.*)"\z/$1/s;
366 19 $v =~ s/\A'(.*)'\z/$1/s;
367 19 return { name => $n, op => $op, value => $v };
368 }
369  
370 38 ▶sub _am_matches {
Subroutine _am_matches: called CC=7 SCAR=19.6
371 38 my ( $ms, $labels ) = @_;
372 38 for my $m (@$ms) {
373 37 ▶ my $have = $labels->{ $m->{name} } // '';
Condition100%2/2
$$labels{$$m{"name"}} // ""
l!l
2413
MC/DC100%1/1
$$labels{$$m{"name"}} // ""
$$labels{$$m{"name"}}
Truth table100%2/2
A
A= $$labels{$$m{"name"}}
Aresult
11
00
374 37 ▶ my $hit = $m->{op} =~ /~/ ? ( eval { $have =~ /\A(?:$m->{value})\z/ } // 0 ) : $have eq $m->{value};
Branch: 1 branch
BranchTrueFalseTotal
$$m{'op'} =~ /~/ ? : 20 17 37
Condition50%1/2
eval { do { $have =~ /\A(?:$$m{"value"})\z/ } } // 0
l!l
200
MC/DC0%0/1
eval { do { $have =~ /\A(?:$$m{"value"})\z/ } } // 0
eval { do { $have =~ /\A(?:$$m{"value"})\z/ } }
Truth table50%1/2
A
A= eval { do { $have =~ /\A(?:$$m{"value"})\z/ } }
Aresult
11
00
375 37 ▶ $hit = !$hit if $m->{op} =~ /\A!/;
Branch: 1 branch
BranchTrueFalseTotal
if $$m{"op"} =~ /\A!/ 0 37 37
376 37 ▶ return 0 unless $hit;
Branch: 1 branch
BranchTrueFalseTotal
unless $hit 24 13 37
377 }
378 14 return 1;
379 }
380  
381 # Silence mit abgeleiteten Feldern: starts/ends (UTC), state, covers (Namen aus alert_targets)
382 11 ▶sub _am_silence_view {
Subroutine _am_silence_view: called CC=5 SCAR=16.2
383 11 my ( $svc, $sil, $now ) = @_;
384 11 ▶ my $t = $svc->{alert_targets} || {};
Condition50%1/2
$$svc{'alert_targets'} || {}
l!l
110
MC/DC0%0/1
$$svc{'alert_targets'} || {}
$$svc{'alert_targets'}
Truth table50%1/2
A
A= $$svc{'alert_targets'}
Aresult
11
00
385 11 $sil->{starts} = _iso( $sil->{_start} );
386 11 $sil->{ends} = _iso( $sil->{_end} );
387 11 ▶ $sil->{state} = $sil->{_expired} || $sil->{_end} <= $now ? 'expired' : $sil->{_start} > $now ? 'pending' : 'active';
Branch: 2 branches
BranchTrueFalseTotal
$$sil{'_expired'} || $$sil{'_end'} <= $now ? : 2 9 11
$$sil{'_start'} > $now ? : 6 3 9
Condition66%2/3
$$sil{"_expired"} or $$sil{"_end"} <= $now
l!l&&r!l&&!r
209
MC/DC50%1/2
$$sil{"_expired"} or $$sil{"_end"} <= $now
$$sil{"_expired"} $$sil{"_end"} <= $now
Truth table66%2/3
A or B
A= $$sil{"_expired"}B= $$sil{"_end"} <= $now
ABresult
1X1
011
000
388 11 $sil->{covers} = [ sort grep { _am_matches( $sil->{_matchers}, $t->{$_} ) } keys %$t ];
389 11 return $sil;
390 }
391  
392 7 ▶sub _am_svc {
Subroutine _am_svc: called CC=4 SCAR=14.6
393 7 my ($dev) = @_;
394 7 ▶ my ($n) = grep { ( $dev->{services}{$_}{config_check} // '' ) eq 'alertmanager' } sort keys %{ $dev->{services} || {} };
Condition50%2/4
$$dev{"services"}{$_}{"config_check"} // ""
l!l
70
$$dev{'services'} || {}
l!l
70
MC/DC0%0/1
$$dev{"services"}{$_}{"config_check"} // ""
$$dev{"services"}{$_}{"config_check"}
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{"services"}{$_}{"config_check"}
Aresult
11
00
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
395 7 ▶ return defined $n ? $dev->{services}{$n} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 7 0 7
396 }
397  
398 6 ▶sub _amtool_silence {
Subroutine _amtool_silence: called CC=42 SCAR=42.8
399 6 my ( $dev, $sub, $av ) = @_;
400 6 my ( %opt, @pos );
401 6 my @a = @$av;
402 6 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 17 6 23
403 17 my $x = shift @a;
404 17 ▶ if ( $x =~ /\A--([\w.-]+)=(.*)\z/s ) { $opt{$1} = $2 }
Branch: 4 branches
BranchTrueFalseTotal
if ($x =~ /\A--([\w.-]+)=(.*)\z/s) { } 9 8 17
elsif ($x =~ /\A--([\w.-]+)\z/ and not $1 =~ /\A(?:quiet|expired|extended)\z/) { } 0 8 8
elsif ($x =~ /\A-([acdq])\z/) { } 2 6 8
elsif ($x =~ /\A--(quiet|expired|extended)\z/) { } 0 6 6
405 0 ▶ elsif ( $x =~ /\A--([\w.-]+)\z/ && $1 !~ /\A(?:quiet|expired|extended)\z/ ) { $opt{$1} = shift @a }
Condition33%1/3
$x =~ /\A--([\w.-]+)\z/ and not $1 =~ /\A(?:quiet|expired|extended)\z/
!ll&&!rl&&r
800
MC/DC0%0/2
$x =~ /\A--([\w.-]+)\z/ and not $1 =~ /\A(?:quiet|expired|extended)\z/
$x =~ /\A--([\w.-]+)\z/ not $1 =~ /\A(?:quiet|expired|extended)\z/
Truth table33%1/3
A and not(B)
A= $x =~ /\A--([\w.-]+)\z/B= not $1 =~ /\A(?:quiet|expired|extended)\z/
ABresult
0X0
100
111
406 2 ▶ elsif ( $x =~ /\A-([acdq])\z/ ) { $opt{ { a => 'author', c => 'comment', d => 'duration', q => 'quiet' }->{$1} } = $1 eq 'q' ? 1 : shift @a }
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'q' ? : 0 2 2
407 0 elsif ( $x =~ /\A--(quiet|expired|extended)\z/ ) { $opt{$1} = 1 }
408 6 else { push @pos, $x }
409 }
410 6 my $url = $opt{'alertmanager.url'};
411 6 ▶ if ( !defined $url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $url) 1 5 6
412 1 ▶ my $cf = _file_text( $dev, '/etc/amtool/config.yml' ) // _file_text( $dev, '/root/.config/amtool/config.yml' ) // '';
Condition40%2/5
(_file_text($dev, "/etc/amtool/config.yml") // _file_text($dev, "/root/.config/amtool/config.yml")) // ""
l!l
01
_file_text($dev, "/etc/amtool/config.yml") // _file_text($dev, "/root/.config/amtool/config.yml")
l!l&&r!l&&!r
001
MC/DC0%0/2
(_file_text($dev, "/etc/amtool/config.yml") // _file_text($dev, "/root/.config/amtool/config.yml")) // ""
_file_text($dev, "/etc/amtool/config.yml") _file_text($dev, "/root/.config/amtool/config.yml")
Truth table33%1/3
A // B
A= _file_text($dev, "/etc/amtool/config.yml")B= _file_text($dev, "/root/.config/amtool/config.yml")
ABresult
1X1
011
000
413 1 ($url) = $cf =~ /^\s*alertmanager\.url:\s*"?([^"\s]+)/m;
414 }
415 6 ▶ return ( 'amtool: error: required flag --alertmanager.url not provided', 0 ) unless defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 1 5 6
416 5 my $svc = _am_svc($dev);
417 return ( qq{Post "$url/api/v2/silences": dial tcp: connect: connection refused}, 0 )
418 5 ▶ unless $svc && $svc->{active} && $url =~ m{\Ahttps?://(?:localhost|127\.0\.0\.1|\[::1\])?(?::9093)?/?\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $svc and $$svc{"active"} and $url =~ m(\Ahttps?://(?:localhost|127\.0\.0\.1|\[::1\])?(?::9093)?/?\z) 0 5 5
Condition33%2/6
$svc and $$svc{"active"} and $url =~ m(\Ahttps?://(?:localhost|127\.0\.0\.1|\[::1\])?(?::9093)?/?\z)
!ll&&!rl&&r
005
$svc and $$svc{"active"}
!ll&&!rl&&r
005
MC/DC0%0/3
$svc and $$svc{"active"} and $url =~ m(\Ahttps?://(?:localhost|127\.0\.0\.1|\[::1\])?(?::9093)?/?\z)
$svc $$svc{"active"} $url =~ m(\Ahttps?://(?:localhost|127\.0\.0\.1|\[::1\])?(?::9093)?/?\z)
Truth table25%1/4
A and B and C
A= $svcB= $$svc{"active"}C= $url =~ m(\Ahttps?://(?:localhost|127\.0\.0\.1|\[::1\])?(?::9093)?/?\z)
ABCresult
0XX0
10X0
1100
1111
419 5 my $now = now_epoch($dev);
420 5 ▶ my $sil = $svc->{silences} //= [];
Condition100%2/2
$$svc{"silences"} //= []
l!l
41
MC/DC100%1/1
$$svc{"silences"} //= []
$$svc{"silences"}
Truth table100%2/2
A
A= $$svc{"silences"}
Aresult
11
00
421 5 $_ = _am_silence_view( $svc, $_, $now ) for @$sil;
422 5 ▶ if ( $sub eq 'add' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "add") 3 2 5
423 3 my @m;
424 3 for my $p (@pos) {
425 4 ▶ my $m = _am_matcher($p) // ( $p =~ /\A[\w:.-]+\z/ ? { name => 'alertname', op => '=', value => $p } : undef );
Branch: 1 branch
BranchTrueFalseTotal
$p =~ /\A[\w:.-]+\z/ ? : 0 0 0
Condition50%1/2
_am_matcher($p) // ($p =~ /\A[\w:.-]+\z/ ? {"name", "alertname", "op", "=", "value", $p} : undef)
l!l
40
MC/DC0%0/1
_am_matcher($p) // ($p =~ /\A[\w:.-]+\z/ ? {"name", "alertname", "op", "=", "value", $p} : undef)
_am_matcher($p)
Truth table50%1/2
A
A= _am_matcher($p)
Aresult
11
00
426 4 ▶ return ( qq{amtool: error: bad matcher format: $p}, 0 ) unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 0 4 4
427 4 push @m, $m;
428 }
429 3 ▶ return ( 'amtool: error: no matchers specified', 0 ) unless @m;
Branch: 1 branch
BranchTrueFalseTotal
unless @m 0 3 3
430 3 ▶ return ( 'amtool: error: comment required by config', 0 ) unless defined $opt{comment} && length $opt{comment};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt{"comment"} and length $opt{"comment"} 1 2 3
Condition66%2/3
defined $opt{"comment"} and length $opt{"comment"}
!ll&&!rl&&r
102
MC/DC50%1/2
defined $opt{"comment"} and length $opt{"comment"}
defined $opt{"comment"} length $opt{"comment"}
Truth table66%2/3
A and B
A= defined $opt{"comment"}B= length $opt{"comment"}
ABresult
0X0
100
111
431 2 ▶ my $start = defined $opt{start} ? _rfc3339( $opt{start} ) : $now;
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'start'} ? : 1 1 2
432 2 ▶ return ( qq{amtool: error: parsing time "$opt{start}" as "2006-01-02T15:04:05Z07:00": cannot parse}, 0 ) unless defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 2 2
433 2 my $end;
434 2 ▶ if ( defined $opt{end} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{'end'}) { } 1 1 2
435 1 ▶ $end = _rfc3339( $opt{end} ) // return ( qq{amtool: error: parsing time "$opt{end}" as "2006-01-02T15:04:05Z07:00": cannot parse}, 0 );
Condition50%1/2
_rfc3339($opt{"end"}) // (return qq[amtool: error: parsing time "$opt{"end"}" as "2006-01-02T15:04:05Z07:00": cannot parse], 0)
l!l
10
MC/DC0%0/1
_rfc3339($opt{"end"}) // (return qq[amtool: error: parsing time "$opt{"end"}" as "2006-01-02T15:04:05Z07:00": cannot parse], 0)
_rfc3339($opt{"end"})
Truth table50%1/2
A
A= _rfc3339($opt{"end"})
Aresult
11
00
436 }
437 else {
438 1 ▶ my $d = _godur( $opt{duration} // '1h' ) // return ( qq{amtool: error: time: invalid duration "$opt{duration}"}, 0 );
Condition50%2/4
_godur($opt{"duration"} // "1h") // (return qq[amtool: error: time: invalid duration "$opt{"duration"}"], 0)
l!l
10
$opt{"duration"} // "1h"
l!l
10
MC/DC0%0/1
_godur($opt{"duration"} // "1h") // (return qq[amtool: error: time: invalid duration "$opt{"duration"}"], 0)
_godur($opt{"duration"} // "1h")
MC/DC0%0/1
$opt{"duration"} // "1h"
$opt{"duration"}
Truth table50%1/2
A
A= _godur($opt{"duration"} // "1h")
Aresult
11
00
Truth table50%1/2
A
A= $opt{"duration"}
Aresult
11
00
439 1 $end = $start + $d;
440 }
441 2 ▶ return ( 'amtool: error: silence cannot end before it starts', 0 ) if $end <= $start;
Branch: 1 branch
BranchTrueFalseTotal
if $end <= $start 0 2 2
442 2 ▶ return ( 'amtool: error: silence cannot end in the past', 0 ) if $end <= $now;
Branch: 1 branch
BranchTrueFalseTotal
if $end <= $now 0 2 2
443 2 my $id = sprintf '%08x-%04x-4%03x-a%03x-%012x', 0x5e1e0000 + @$sil, 0x2026, scalar @$sil, 0x124, $start;
444 3 ▶ push @$sil, _am_silence_view( $svc, { id => $id, matchers => [ map {"$_->{name}$_->{op}$_->{value}"} @m ], comment => $opt{comment},
Condition50%1/2
$opt{"author"} // "root"
l!l
02
MC/DC0%0/1
$opt{"author"} // "root"
$opt{"author"}
Truth table50%1/2
A
A= $opt{"author"}
Aresult
11
00
445 2 author => $opt{author} // 'root', _matchers => \@m, _start => $start, _end => $end }, $now );
446 2 return ( $id, 1 );
447 }
448 2 ▶ if ( $sub eq 'query' || $sub eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "query" or $sub eq "") 1 1 2
Condition66%2/3
$sub eq "query" or $sub eq ""
l!l&&r!l&&!r
101
MC/DC50%1/2
$sub eq "query" or $sub eq ""
$sub eq "query" $sub eq ""
Truth table66%2/3
A or B
A= $sub eq "query"B= $sub eq ""
ABresult
1X1
011
000
449 1 ▶ my @l = grep { $opt{expired} ? $_->{state} eq 'expired' : $_->{state} ne 'expired' } @$sil;
Branch: 1 branch
BranchTrueFalseTotal
$opt{'expired'} ? : 0 2 2
450 0 ▶ return ( join( "\n", map { $_->{id} } @l ), 1 ) if $opt{quiet};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"quiet"} 0 1 1
451 1 my $f = '%-37s %-40s %-24s %-10s %s';
452 return ( join( "\n", sprintf( $f, 'ID', 'Matchers', 'Ends At', 'Created By', 'Comment' ),
453 1 map { sprintf( $f, $_->{id}, join( ' ', @{ $_->{matchers} } ), $_->{ends} =~ s/T/ /r =~ s/Z\z/ UTC/r, $_->{author}, $_->{comment} ) } @l ), 1 );
454 }
455 1 ▶ if ( $sub eq 'expire' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "expire") 1 0 1
456 1 ▶ return ( 'amtool: error: no silence IDs specified', 0 ) unless @pos;
Branch: 1 branch
BranchTrueFalseTotal
unless @pos 0 1 1
457 1 for my $id (@pos) {
458 1 ▶ my ($s) = grep { $_->{id} eq $id } @$sil or return ( qq{silence $id not found}, 0 );
Branch: 1 branch
BranchTrueFalseTotal
my($s) = grep({$$_{"id"} eq $id;} @$sil) or return "silence $id not found", 0 1 0 1
459 1 $s->{_expired} = 1;
460 1 _am_silence_view( $svc, $s, $now );
461 }
462 1 return ( '', 1 );
463 }
464 0 push @GAPS, join( ' ', 'amtool silence', $sub, @$av );
465 0 return ( '', 0 );
466 }
467  
468 # amtool config routes [show] | config routes test [--verify.receivers=LISTE] LABEL…: Baum bzw.
469 # Empfaenger aus --config.file oder der laufenden Konfiguration (--alertmanager.url); Matcher je
470 # Route sortiert, ein Zweig nach dem ersten Treffer nur mit continue. () = Luecke
471 6 ▶sub _amtool_routes {
Subroutine _amtool_routes: called CC=34 SCAR=39.9
472 6 my ( $dev, $av ) = @_;
473 6 my ( $file, $verify, @pos );
474 6 my @a = @$av;
475 6 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 17 6 23
476 17 my $x = shift @a;
477 17 ▶ if ( $x =~ /\A--config\.file=(.*)\z/ ) { $file = $1 }
Branch: 7 branches
BranchTrueFalseTotal
if ($x =~ /\A--config\.file=(.*)\z/) { } 5 12 17
elsif ($x eq '--config.file') { } 1 11 12
elsif ($x =~ /\A--verify\.receivers=(.*)\z/) { } 1 10 11
elsif ($x eq '--verify.receivers') { } 0 10 10
elsif ($x =~ /\A--alertmanager\.url=/) { } 0 10 10
elsif ($x eq '--alertmanager.url') { } 0 10 10
elsif ($x =~ /\A-/) { } 0 10 10
478 1 ▶ elsif ( $x eq '--config.file' ) { $file = shift(@a) // return }
Condition50%1/2
shift @a // (return)
l!l
10
MC/DC0%0/1
shift @a // (return)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
479 1 elsif ( $x =~ /\A--verify\.receivers=(.*)\z/ ) { $verify = $1 }
480 0 ▶ elsif ( $x eq '--verify.receivers' ) { $verify = shift(@a) // return }
Condition0%0/2
shift @a // (return)
l!l
00
MC/DC0%0/1
shift @a // (return)
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
481 elsif ( $x =~ /\A--alertmanager\.url=/ ) { }
482 0 elsif ( $x eq '--alertmanager.url' ) { shift @a }
483 0 elsif ( $x =~ /\A-/ ) { return }
484 10 else { push @pos, $x }
485 }
486 6 ▶ my $sub = @pos && $pos[0] =~ /\A(?:show|test)\z/ ? shift @pos : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@pos && $pos[0] =~ /\A(?:show|test)\z/ ? : 5 1 6
Condition66%2/3
@pos and $pos[0] =~ /\A(?:show|test)\z/
!ll&&!rl&&r
105
MC/DC50%1/2
@pos and $pos[0] =~ /\A(?:show|test)\z/
@pos $pos[0] =~ /\A(?:show|test)\z/
Truth table66%2/3
A and B
A= @posB= $pos[0] =~ /\A(?:show|test)\z/
ABresult
0X0
100
111
487 6 ▶ return if $sub eq 'show' && @pos;
Branch: 1 branch
BranchTrueFalseTotal
if $sub eq "show" and @pos 0 6 6
Condition66%2/3
$sub eq "show" and @pos
!ll&&!rl&&r
420
MC/DC0%0/2
$sub eq "show" and @pos
$sub eq "show" @pos
Truth table66%2/3
A and B
A= $sub eq "show"B= @pos
ABresult
0X0
100
111
488 6 my $text;
489 6 ▶ if ( defined $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) { } 6 0 6
490 6 $text = _file_text( $dev, $file );
491 6 ▶ return ( "amtool: error: open $file: no such file or directory", 0 ) unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 6 6
492 }
493 else {
494 0 ▶ my $svc = _am_svc($dev) or return ( 'amtool: error: required flag --alertmanager.url not provided', 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $svc = _am_svc($dev) or return "amtool: error: required flag --alertmanager.url not provided", 0 0 0 0
495 0 ▶ return unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 0 0 0
496 0 ▶ my $main = $svc->{config_main} // ( ref $svc->{config} ? $svc->{config}[0] : $svc->{config} ) // return;
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'config'} ? : 0 0 0
Condition0%0/5
($$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})) // (return)
l!l
00
$$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
l!l&&r!l&&!r
000
MC/DC0%0/2
($$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})) // (return)
$$svc{"config_main"} (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
Truth table0%0/3
A // B
A= $$svc{"config_main"}B= (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
ABresult
1X1
011
000
497 0 ▶ $text = ( ref $svc->{running} eq 'HASH' ? $svc->{running}{$main} : undef ) // _file_text( $dev, $main ) // return;
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 0 0 0
Condition0%0/5
((ref $$svc{"running"} eq "HASH" ? $$svc{"running"}{$main} : undef) // _file_text($dev, $main)) // (return)
l!l
00
(ref $$svc{"running"} eq "HASH" ? $$svc{"running"}{$main} : undef) // _file_text($dev, $main)
l!l&&r!l&&!r
000
MC/DC0%0/2
((ref $$svc{"running"} eq "HASH" ? $$svc{"running"}{$main} : undef) // _file_text($dev, $main)) // (return)
(ref $$svc{"running"} eq "HASH" ? $$svc{"running"}{$main} : undef) _file_text($dev, $main)
Truth table0%0/3
A // B
A= (ref $$svc{"running"} eq "HASH" ? $$svc{"running"}{$main} : undef)B= _file_text($dev, $main)
ABresult
1X1
011
000
498 }
499 6 my $e = _am_check_text($text);
500 6 ▶ return ( "amtool: error: $e->[0]", 0 ) if @$e;
Branch: 1 branch
BranchTrueFalseTotal
if @$e 1 5 6
501 5 my ($d) = _yaml($text);
502 5 ▶ my $q = sub { my $v = shift; $v =~ s/(["\\])/\\$1/g; qq{"$v"} };
Subroutine __ANON__: called CC=1 SCAR=0.0
503 5 my $route;
504 20 ▶ $route = sub {
Subroutine __ANON__: called CC=13 SCAR=26.7
505 20 my ( $r, $parent ) = @_;
506 20 my @m;
507 20 ▶ for my $s ( @{ ref $r->{matchers} eq 'ARRAY' ? $r->{matchers} : [] } ) { push @m, _am_matcher($s) // return }
Branch: 1 branch
BranchTrueFalseTotal
ref $$r{'matchers'} eq 'ARRAY' ? : 5 15 20
Condition50%1/2
_am_matcher($s) // (return)
l!l
100
MC/DC0%0/1
_am_matcher($s) // (return)
_am_matcher($s)
Truth table50%1/2
A
A= _am_matcher($s)
Aresult
11
00
508 20 ▶ push @m, map { { name => $_, op => '=', value => $r->{match}{$_} } } sort keys %{ ref $r->{match} eq 'HASH' ? $r->{match} : {} };
Branch: 1 branch
BranchTrueFalseTotal
ref $$r{'match'} eq 'HASH' ? : 5 15 20
509 20 ▶ push @m, map { { name => $_, op => '=~', value => $r->{match_re}{$_} } } sort keys %{ ref $r->{match_re} eq 'HASH' ? $r->{match_re} : {} };
Branch: 1 branch
BranchTrueFalseTotal
ref $$r{'match_re'} eq 'HASH' ? : 5 15 20
510 20 ▶ @m = sort { $a->{name} cmp $b->{name} || $a->{value} cmp $b->{value} || $a->{op} cmp $b->{op} } @m;
Condition33%2/6
$$a{'name'} cmp $$b{'name'} || $$a{'value'} cmp $$b{'value'} || $$a{'op'} cmp $$b{'op'}
l!l&&r!l&&!r
500
$$a{"name"} cmp $$b{"name"} or $$a{"value"} cmp $$b{"value"}
l!l&&r!l&&!r
500
MC/DC0%0/3
$$a{'name'} cmp $$b{'name'} || $$a{'value'} cmp $$b{'value'} || $$a{'op'} cmp $$b{'op'}
$$a{"name"} cmp $$b{"name"} $$a{"value"} cmp $$b{"value"} $$a{'op'} cmp $$b{'op'}
Truth table25%1/4
A or B || C
A= $$a{"name"} cmp $$b{"name"}B= $$a{"value"} cmp $$b{"value"}C= $$a{'op'} cmp $$b{'op'}
ABCresult
1XX1
01X1
0011
0000
511 20 ▶ my $node = { m => \@m, receiver => $r->{receiver} // $parent->{receiver}, continue => $r->{continue} && "$r->{continue}" =~ /\A(?:1|true)\z/ };
Condition50%3/6
$$r{"receiver"} // $$parent{"receiver"}
l!l&&r!l&&!r
2000
$$r{'continue'} && "$$r{'continue'}" =~ /\A(?:1|true)\z/
!ll&&!rl&&r
1505
MC/DC0%0/2
$$r{"receiver"} // $$parent{"receiver"}
$$r{"receiver"} $$parent{"receiver"}
MC/DC50%1/2
$$r{'continue'} && "$$r{'continue'}" =~ /\A(?:1|true)\z/
$$r{'continue'} "$$r{'continue'}" =~ /\A(?:1|true)\z/
Truth table33%1/3
A // B
A= $$r{"receiver"}B= $$parent{"receiver"}
ABresult
1X1
011
000
Truth table66%2/3
A && B
A= $$r{'continue'}B= "$$r{'continue'}" =~ /\A(?:1|true)\z/
ABresult
0X0
100
111
512 20 ▶ for my $c ( grep { ref $_ eq 'HASH' } @{ $r->{routes} || [] } ) { push @{ $node->{kids} }, $route->( $c, $node ) // return }
Condition75%3/4
$$r{'routes'} || []
l!l
515
&$route($c, $node) // (return)
l!l
150
MC/DC100%1/1
$$r{'routes'} || []
$$r{'routes'}
MC/DC0%0/1
&$route($c, $node) // (return)
&$route($c, $node)
Truth table100%2/2
A
A= $$r{'routes'}
Aresult
11
00
Truth table50%1/2
A
A= &$route($c, $node)
Aresult
11
00
513 20 return $node;
514 5 };
515 5 ▶ my $root = $route->( $d->{route}, {} ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $root = &$route($$d{"route"}, scalar {}) or return 5 0 5
516 5 ▶ if ( $sub eq 'show' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "show") 1 4 5
517 1 my @l = ( 'Routing tree:', '.' );
518 1 my $tree;
519 4 ▶ $tree = sub {
Subroutine __ANON__: called CC=8 SCAR=20.9
520 4 my ( $n, $pre, $last ) = @_;
521 4 ▶ my $slug = @{ $n->{m} } ? '{' . join( ',', map { $_->{name} . $_->{op} . $q->( $_->{value} ) } @{ $n->{m} } ) . '}' : 'default-route';
Branch: 1 branch
BranchTrueFalseTotal
@{$$n{'m'};} ? : 3 1 4
522 4 ▶ $slug .= ', continue: true' if $n->{continue};
Branch: 1 branch
BranchTrueFalseTotal
if $$n{"continue"} 1 3 4
523 4 ▶ push @l, $pre . ( $last ? '└── ' : '├── ' ) . "$slug receiver: " . ( $n->{receiver} // '' );
Branch: 1 branch
BranchTrueFalseTotal
$last ? : 2 2 4
Condition50%1/2
$$n{"receiver"} // ""
l!l
40
MC/DC0%0/1
$$n{"receiver"} // ""
$$n{"receiver"}
Truth table50%1/2
A
A= $$n{"receiver"}
Aresult
11
00
524 4 ▶ my @k = @{ $n->{kids} || [] };
Condition100%2/2
$$n{'kids'} || []
l!l
13
MC/DC100%1/1
$$n{'kids'} || []
$$n{'kids'}
Truth table100%2/2
A
A= $$n{'kids'}
Aresult
11
00
525 4 ▶ $tree->( $k[$_], $pre . ( $last ? ' ' : '│ ' ), $_ == $#k ) for 0 .. $#k;
Branch: 1 branch
BranchTrueFalseTotal
$last ? : 3 0 3
526 1 };
527 1 $tree->( $root, '', 1 );
528 1 return ( join( "\n", @l ), 1 );
529 }
530 4 my %lab;
531 4 ▶ for (@pos) { my $m = _am_matcher($_) or return ( "amtool: error: bad matcher format: $_", 0 ); $lab{ $m->{name} } = $m->{value} }
Branch: 1 branch
BranchTrueFalseTotal
my $m = _am_matcher($_) or return "amtool: error: bad matcher format: $_", 0 5 0 5
532 4 my $match;
533 14 ▶ $match = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
534 14 my ($n) = @_;
535 14 ▶ return () unless _am_matches( $n->{m}, \%lab );
Branch: 1 branch
BranchTrueFalseTotal
unless _am_matches($$n{"m"}, \%lab) 7 7 14
536 7 my @all;
537 7 ▶ for my $c ( @{ $n->{kids} || [] } ) {
Condition100%2/2
$$n{'kids'} || []
l!l
43
MC/DC100%1/1
$$n{'kids'} || []
$$n{'kids'}
Truth table100%2/2
A
A= $$n{'kids'}
Aresult
11
00
538 10 my @hit = $match->($c);
539 10 push @all, @hit;
540 10 ▶ last if @hit && !$c->{continue};
Branch: 1 branch
BranchTrueFalseTotal
if @hit and not $$c{"continue"} 2 8 10
Condition100%3/3
@hit and not $$c{"continue"}
!ll&&!rl&&r
712
MC/DC100%2/2
@hit and not $$c{"continue"}
@hit not $$c{"continue"}
Truth table100%3/3
A and not(B)
A= @hitB= not $$c{"continue"}
ABresult
0X0
100
111
541 }
542 7 ▶ return @all ? @all : ($n);
Branch: 1 branch
BranchTrueFalseTotal
@all ? : 2 5 7
543 4 };
544 4 ▶ my $slug = join ',', map { $_->{receiver} // '' } $match->($root);
Condition50%1/2
$$_{"receiver"} // ""
l!l
50
MC/DC0%0/1
$$_{"receiver"} // ""
$$_{"receiver"}
Truth table50%1/2
A
A= $$_{"receiver"}
Aresult
11
00
545 4 ▶ return ( "$slug\nWARNING: Expected receivers did not match resolved receivers.", 0 ) if defined $verify && length $verify && $verify ne $slug;
Branch: 1 branch
BranchTrueFalseTotal
if defined $verify and length $verify and $verify ne $slug 1 3 4
Condition66%4/6
defined $verify and length $verify and $verify ne $slug
!ll&&!rl&&r
301
defined $verify and length $verify
!ll&&!rl&&r
301
MC/DC33%1/3
defined $verify and length $verify and $verify ne $slug
defined $verify length $verify $verify ne $slug
Truth table50%2/4
A and B and C
A= defined $verifyB= length $verifyC= $verify ne $slug
ABCresult
0XX0
10X0
1100
1111
546 3 return ( $slug, 1 );
547 }
548  
549 15 ▶sub amtool {
Subroutine amtool: called CC=37 SCAR=45.3
Pod documented
550 15 my ( $dev, $av ) = @_;
551 15 my @all = @$av;
552 15 ▶ if ( ( $all[0] // '' ) eq 'config' && ( $all[1] // '' ) eq 'routes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($all[0] // "") eq "config" and ($all[1] // "") eq "routes") 6 9 15
Condition57%4/7
($all[0] // "") eq "config" and ($all[1] // "") eq "routes"
!ll&&!rl&&r
906
$all[0] // ""
l!l
150
$all[1] // ""
l!l
60
MC/DC0%0/2
($all[0] // "") eq "config" and ($all[1] // "") eq "routes"
$all[0] $all[1]
Truth table33%1/3
A and B
A= $all[0]B= $all[1]
ABresult
0X0
100
111
553 6 my @r = _amtool_routes( $dev, [ @all[ 2 .. $#all ] ] );
554 6 ▶ return @r if @r;
Branch: 1 branch
BranchTrueFalseTotal
if @r 6 0 6
555 0 push @GAPS, join( ' ', 'amtool', @$av );
556 0 return ( '', 0 );
557 }
558 9 ▶ if ( ( $all[0] // '' ) eq 'silence' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($all[0] // "") eq "silence") 6 3 9
Condition50%1/2
$all[0] // ""
l!l
90
MC/DC0%0/1
$all[0] // ""
$all[0]
Truth table50%1/2
A
A= $all[0]
Aresult
11
00
559 6 ▶ my $sub = defined $all[1] && $all[1] !~ /\A-/ ? $all[1] : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $all[1] && !($all[1] =~ /\A-/) ? : 6 0 6
Condition33%1/3
defined $all[1] and not $all[1] =~ /\A-/
!ll&&!rl&&r
006
MC/DC0%0/2
defined $all[1] and not $all[1] =~ /\A-/
defined $all[1] not $all[1] =~ /\A-/
Truth table33%1/3
A and not(B)
A= defined $all[1]B= not $all[1] =~ /\A-/
ABresult
0X0
100
111
560 6 ▶ return _amtool_silence( $dev, $sub, [ @all[ ( $sub eq '' ? 1 : 2 ) .. $#all ] ] );
Branch: 1 branch
BranchTrueFalseTotal
$sub eq '' ? : 0 6 6
561 }
562 3 ▶ if ( ( $all[0] // '' ) eq 'alert' && ( ( $all[1] // 'query' ) eq 'query' || $all[1] =~ /\A-/ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($all[0] // "") eq "alert" and ($all[1] // "query") eq "query" || $all[1] =~ /\A-/) 2 1 3
Condition50%5/10
($all[0] // "") eq "alert" and ($all[1] // "query") eq "query" || $all[1] =~ /\A-/
!ll&&!rl&&r
102
$all[0] // ""
l!l
30
($all[1] // "query") eq "query" or $all[1] =~ /\A-/
l!l&&r!l&&!r
200
$all[1] // "query"
l!l
20
MC/DC0%0/3
($all[0] // "") eq "alert" and ($all[1] // "query") eq "query" || $all[1] =~ /\A-/
$all[0] $all[1] $all[1] =~ /\A-/
Truth table25%1/4
A and B or C
A= $all[0]B= $all[1]C= $all[1] =~ /\A-/
ABCresult
0XX0
1000
11X1
1011
563 2 ▶ my $svc = _am_svc($dev) or return ( 'amtool: error: required flag --alertmanager.url not provided', 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $svc = _am_svc($dev) or return "amtool: error: required flag --alertmanager.url not provided", 0 2 0 2
564 2 my $now = now_epoch($dev);
565 2 ▶ my $sil = $svc->{silences} || [];
Condition50%1/2
$$svc{'silences'} || []
l!l
20
MC/DC0%0/1
$$svc{'silences'} || []
$$svc{'silences'}
Truth table50%1/2
A
A= $$svc{'silences'}
Aresult
11
00
566 2 $_ = _am_silence_view( $svc, $_, $now ) for @$sil;
567 2 ▶ my $t = $svc->{alert_targets} || {};
Condition50%1/2
$$svc{'alert_targets'} || {}
l!l
20
MC/DC0%0/1
$$svc{'alert_targets'} || {}
$$svc{'alert_targets'}
Truth table50%1/2
A
A= $$svc{'alert_targets'}
Aresult
11
00
568 2 my @rows;
569 2 ▶ for my $a ( @{ $svc->{alerts} || [] } ) {
Condition50%1/2
$$svc{'alerts'} || []
l!l
20
MC/DC0%0/1
$$svc{'alerts'} || []
$$svc{'alerts'}
Truth table50%1/2
A
A= $$svc{'alerts'}
Aresult
11
00
570 4 ▶ my $lab = { %{ $t->{ $a->{target} // '' } || {} }, alertname => $a->{alertname} };
Condition50%2/4
$$t{$$a{'target'} // ''} || {}
l!l
40
$$a{"target"} // ""
l!l
40
MC/DC0%0/1
$$t{$$a{'target'} // ''} || {}
$$t{$$a{'target'} // ''}
MC/DC0%0/1
$$a{"target"} // ""
$$a{"target"}
Truth table50%1/2
A
A= $$t{$$a{'target'} // ''}
Aresult
11
00
Truth table50%1/2
A
A= $$a{"target"}
Aresult
11
00
571 4 ▶ next if grep { $_->{state} eq 'active' && _am_matches( $_->{_matchers}, $lab ) } @$sil;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$$_{"state"} eq "active" and _am_matches($$_{"_matchers"}, $lab);} @$sil 1 3 4
Condition100%3/3
$$_{'state'} eq 'active' && _am_matches($$_{'_matchers'}, $lab)
!ll&&!rl&&r
411
MC/DC100%2/2
$$_{'state'} eq 'active' && _am_matches($$_{'_matchers'}, $lab)
$$_{'state'} eq 'active' _am_matches($$_{'_matchers'}, $lab)
Truth table100%3/3
A && B
A= $$_{'state'} eq 'active'B= _am_matches($$_{'_matchers'}, $lab)
ABresult
0X0
100
111
572 3 ▶ push @rows, sprintf( '%-22s %-26s %s', $a->{alertname}, $a->{since} // '2026-10-24 06:58:12 UTC', $a->{summary} // '' );
Condition50%2/4
$$a{"since"} // "2026-10-24 06:58:12 UTC"
l!l
03
$$a{"summary"} // ""
l!l
30
MC/DC0%0/1
$$a{"since"} // "2026-10-24 06:58:12 UTC"
$$a{"since"}
MC/DC0%0/1
$$a{"summary"} // ""
$$a{"summary"}
Truth table50%1/2
A
A= $$a{"since"}
Aresult
11
00
Truth table50%1/2
A
A= $$a{"summary"}
Aresult
11
00
573 }
574 2 return ( join( "\n", sprintf( '%-22s %-26s %s', 'Alertname', 'Starts At', 'Summary' ), @rows ), 1 );
575 }
576 1 my @a = grep { !/\A--/ } @$av;
577 1 my ( $cmd, @files ) = @a;
578 0 ▶ if ( ( $cmd // '' ) ne 'check-config' ) { push @GAPS, join( ' ', 'amtool', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (($cmd // "") ne "check-config") 0 1 1
Condition50%1/2
$cmd // ""
l!l
10
MC/DC0%0/1
$cmd // ""
$cmd
Truth table50%1/2
A
A= $cmd
Aresult
11
00
579 1 my ( @out, $ok );
580 1 $ok = 1;
581 1 for my $f (@files) {
582 1 push @out, "Checking '$f'";
583 1 my $e = check_alertmanager( $dev, $f );
584 1 ▶ if (@$e) { push @out, " FAILED: $_" for @$e; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@$e) 1 0 1
585 0 my ($d) = _yaml( _file_text( $dev, $f ) );
586 0 ▶ push @out, ' SUCCESS', 'Found:', ' - global config', ' - route', ' - ' . scalar( @{ $d->{inhibit_rules} || [] } ) . ' inhibit rules',
Condition0%0/2
$$d{'inhibit_rules'} || []
l!l
00
MC/DC0%0/1
$$d{'inhibit_rules'} || []
$$d{'inhibit_rules'}
Truth table0%0/2
A
A= $$d{'inhibit_rules'}
Aresult
11
00
587 0 ▶ ' - ' . scalar( @{ $d->{receivers} || [] } ) . ' receivers', ' - 0 templates', '';
Condition0%0/2
$$d{'receivers'} || []
l!l
00
MC/DC0%0/1
$$d{'receivers'} || []
$$d{'receivers'}
Truth table0%0/2
A
A= $$d{'receivers'}
Aresult
11
00
588 }
589 1 ▶ pop @out while @out && $out[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
@out and $out[-1] eq "" and do { pop @out } 0 1 1
Condition33%1/3
@out and $out[-1] eq ""
!ll&&!rl&&r
010
MC/DC0%0/2
@out and $out[-1] eq ""
@out $out[-1] eq ""
Truth table33%1/3
A and B
A= @outB= $out[-1] eq ""
ABresult
0X0
100
111
590 1 return ( join( "\n", @out ), $ok );
591 }
592  
593 4 1;
594  
595 __END__
« blib/lib/Langertha/Holmgang/Lint.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Logrotate.pm »