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

filter: Statementstmt 92.5% 623 / 673 Branchbran 69.0% 301 / 436 Conditioncond 51.7% 191 / 369 MC/DCmcdc 18.2% 35 / 192 Subroutinesub 89.8% 44 / 49 Podpod 100% 7 / 7 totaltotal 69.5% 1201 / 1726 CC 415 SCAR 41.3
CC
415
Cov
75%
http
170.0
amtool
93.1
_check_rules
72.8
CRAP 62.3
« 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 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use Digest::MD5 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Text::ParseWords ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 7 our $VERSION = '0.002';
15  
16  
17 7 our @GAPS;
18  
19 156 ▶sub _file_text {
Subroutine _file_text: called CC=1 SCAR=0.0
20 156 my ( $dev, $p ) = @_;
21 156 require Langertha::Holmgang::Sim::Linux;
22 156 return Langertha::Holmgang::Sim::Linux::_file_text( $dev, $p );
23 }
24  
25 36 ▶sub _glob_files {
Subroutine _glob_files: called CC=3 SCAR=11.2
26 36 my ( $dev, $pat ) = @_;
27 36 ( my $re = quotemeta $pat ) =~ s/\\\*/[^\/]*/g;
28 36 $re =~ s/\\\?/[^\/]/g;
29 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
30 }
31  
32 # YAML laden: ( daten ) oder ( undef, "yaml: line N: …" )
33 137 ▶sub _yaml {
Subroutine _yaml: called CC=5 SCAR=25.2
34 137 my ($text) = @_;
35 137 ▶ 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 137 137
36 137 ▶ return ($d) unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 137 0 137
37 0 my $e = "$@";
38 0 my ($line) = $e =~ /line:\s*(\d+)/;
39 0 my ($what) = $e =~ /YAML::XS::Load Error: The problem:\s*\n?\s*(.+?)(?:\n|$)/;
40 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
41 0 $what =~ s/\s+\z//;
42 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
43 }
44  
45 # Prometheus-Dauer ("90s", "1m30s", "2h") in Sekunden, undef wenn ungueltig
46 103 ▶sub _dur {
Subroutine _dur: called CC=4 SCAR=14.3
47 103 my ($s) = @_;
48 103 ▶ 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 103 103
Condition33%1/3
defined $s and $s =~ /\A(?:\d+(?:ms|s|m|h|d|w|y))+\z/
!ll&&!rl&&r
00103
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
49 103 my %f = ( ms => 0.001, s => 1, m => 60, h => 3600, d => 86400, w => 604800, y => 31536000 );
50 103 my $t = 0;
51 103 ▶ $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} } 103 103 206
52 103 return $t;
53 }
54  
55 7 our %RULE_KEYS =map { $_ => 1 } qw( alert record expr for labels annotations keep_firing_for );
56  
57 # Regeldatei pruefen: ( zahl der regeln ) oder ( undef, [ fehler ] )
58 39 ▶sub _check_rules {
Subroutine _check_rules: called CC=27 SCAR=42.9
59 39 my ( $path, $text ) = @_;
60 39 my ( $d, $ye ) = _yaml($text);
61 39 ▶ return ( undef, ["$path: $ye"] ) if $ye;
Branch: 1 branch
BranchTrueFalseTotal
if $ye 0 39 39
62 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
63 39 my ( $n, @e, %gn ) = (0);
64 39 for my $g ( @{ $d->{groups} } ) {
65 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
66 39 ▶ next unless ref $g eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $g eq "HASH" 0 39 39
67 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
68 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
69 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
70 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
71 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
72 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
73 39 ▶ if ( defined $r->{expr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$r{"expr"}) 39 0 39
74 39 my $x = $r->{expr};
75 39 my $open = () = $x =~ /\(/g;
76 39 my $close = () = $x =~ /\)/g;
77 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
78 if $open != $close;
79 }
80 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
81 0 push @e, "$path: group \"$g->{name}\", rule $n: not a valid duration string: \"$r->{for}\"";
82 }
83 39 $n++;
84 }
85 }
86 39 ▶ return ( undef, \@e ) if @e;
Branch: 1 branch
BranchTrueFalseTotal
if @e 3 36 39
87 36 return ($n);
88 }
89  
90  
91 48 ▶sub check_prometheus {
Subroutine check_prometheus: called CC=35 SCAR=39.0
Pod documented
92 48 my ( $dev, $path ) = @_;
93 48 my $text = _file_text( $dev, $path );
94 48 ▶ return ( ["open $path: no such file or directory"], {} ) unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 48 48
95 48 my ( $d, $ye ) = _yaml($text);
96 48 ▶ return ( ["parsing YAML file $path: $ye"], {} ) if $ye;
Branch: 1 branch
BranchTrueFalseTotal
if $ye 0 48 48
97 48 ▶ 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 48 48
98 48 my @e;
99 48 my %known = map { $_ => 1 } qw( global scrape_configs rule_files alerting remote_write remote_read storage tracing scrape_config_files );
100 48 push @e, "parsing YAML file $path: yaml: unmarshal errors: field $_ not found in type config.plain" for grep { !$known{$_} } sort keys %$d;
101 48 my %jobs;
102 48 ▶ my $g = ref $d->{global} eq 'HASH' ? $d->{global} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$d{'global'} eq 'HASH' ? : 48 0 48
103 48 ▶ my $gi = _dur( $g->{scrape_interval} // '1m' );
Condition50%1/2
$$g{"scrape_interval"} // "1m"
l!l
480
MC/DC0%0/1
$$g{"scrape_interval"} // "1m"
$$g{"scrape_interval"}
Truth table50%1/2
A
A= $$g{"scrape_interval"}
Aresult
11
00
104 48 ▶ my $gt = _dur( $g->{scrape_timeout} // '10s' );
Condition50%1/2
$$g{"scrape_timeout"} // "10s"
l!l
048
MC/DC0%0/1
$$g{"scrape_timeout"} // "10s"
$$g{"scrape_timeout"}
Truth table50%1/2
A
A= $$g{"scrape_timeout"}
Aresult
11
00
105 48 ▶ for my $sc ( @{ $d->{scrape_configs} || [] } ) {
Condition50%1/2
$$d{'scrape_configs'} || []
l!l
480
MC/DC0%0/1
$$d{'scrape_configs'} || []
$$d{'scrape_configs'}
Truth table50%1/2
A
A= $$d{'scrape_configs'}
Aresult
11
00
106 61 ▶ my $j = ref $sc eq 'HASH' ? $sc->{job_name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $sc eq 'HASH' ? : 61 0 61
107 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 61 61
Condition33%1/3
defined $j and length $j
!ll&&!rl&&r
0061
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
108 61 ▶ 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 60 61
109 61 ▶ my $iv = defined $sc->{scrape_interval} ? _dur( $sc->{scrape_interval} ) : $gi;
Branch: 1 branch
BranchTrueFalseTotal
defined $$sc{'scrape_interval'} ? : 1 60 61
110 61 ▶ my $to = defined $sc->{scrape_timeout} ? _dur( $sc->{scrape_timeout} ) : ( $gt > $iv ? $iv : $gt );
Branch: 2 branches
BranchTrueFalseTotal
defined $$sc{'scrape_timeout'} ? : 2 59 61
$gt > $iv ? : 0 59 59
111 61 for my $k (qw( scrape_interval scrape_timeout )) {
112 122 ▶ 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 122 122
Condition66%2/3
defined $$sc{$k} and not defined _dur($$sc{$k})
!ll&&!rl&&r
11930
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
113 }
114 61 ▶ 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 60 61
Condition50%3/6
defined $iv and defined $to and $to > $iv
!ll&&!rl&&r
0601
defined $iv and defined $to
!ll&&!rl&&r
0061
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
115 if defined $iv && defined $to && $to > $iv;
116 61 ▶ for my $s ( @{ $sc->{static_configs} || [] } ) {
Condition100%2/2
$$sc{'static_configs'} || []
l!l
601
MC/DC100%1/1
$$sc{'static_configs'} || []
$$sc{'static_configs'}
Truth table100%2/2
A
A= $$sc{'static_configs'}
Aresult
11
00
117 60 ▶ for my $t ( @{ ( ref $s eq 'HASH' ? $s->{targets} : undef ) || [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $s eq 'HASH' ? : 60 0 60
Condition50%1/2
(ref $s eq 'HASH' ? $$s{'targets'} : undef) || []
l!l
600
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
118 72 ▶ 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 72 72
Condition33%1/3
defined $t and $t =~ /\A[\w.\-\[\]:]+:\d+\z/
!ll&&!rl&&r
0072
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
119 }
120 }
121 }
122 48 my ( %rules, $nr );
123 48 ▶ for my $pat ( @{ $d->{rule_files} || [] } ) {
Condition100%2/2
$$d{'rule_files'} || []
l!l
3612
MC/DC100%1/1
$$d{'rule_files'} || []
$$d{'rule_files'}
Truth table100%2/2
A
A= $$d{'rule_files'}
Aresult
11
00
124 36 ( my $p = $pat ) =~ s{\A(?!/)}{ ( $path =~ m{\A(.*)/} )[0] . '/' }e;
125 36 for my $f ( _glob_files( $dev, $p ) ) {
126 36 my $t = _file_text( $dev, $f );
127 36 my ( $n, $re ) = _check_rules( $f, $t );
128 36 ▶ if ($re) { push @e, map {"loading groups failed: $_"} @$re; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($re) 2 34 36
129 34 $rules{$f} = $t;
130 34 $nr += $n;
131 }
132 }
133 48 ▶ return ( \@e, \%rules, $nr // 0 );
Condition100%2/2
$nr // 0
l!l
3414
MC/DC100%1/1
$nr // 0
$nr
Truth table100%2/2
A
A= $nr
Aresult
11
00
134 }
135  
136  
137 14 ▶sub check_alertmanager {
Subroutine check_alertmanager: called CC=2 SCAR=7.0
Pod documented
138 14 my ( $dev, $path ) = @_;
139 14 my $text = _file_text( $dev, $path );
140 14 ▶ return ["open $path: no such file or directory"] unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 14 14
141 14 return _am_check_text($text);
142 }
143  
144 22 ▶sub _am_check_text {
Subroutine _am_check_text: called CC=7 SCAR=20.9
145 22 my ($text) = @_;
146 22 my ( $d, $ye ) = _yaml($text);
147 22 ▶ return [$ye] if $ye;
Branch: 1 branch
BranchTrueFalseTotal
if $ye 0 22 22
148 22 ▶ 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 22 22
Condition33%1/3
ref $d eq "HASH" and ref $$d{"route"} eq "HASH"
!ll&&!rl&&r
0022
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
149 22 ▶ my %recv = map { ( ref $_ eq 'HASH' ? $_->{name} // '' : '' ) => 1 } @{ $d->{receivers} || [] };
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 53 0 53
Condition50%2/4
$$_{"name"} // ""
l!l
530
$$d{'receivers'} || []
l!l
220
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
150 22 my @e;
151 my $walk;
152 55 ▶ $walk = sub {
Subroutine __ANON__: called CC=6 SCAR=19.0
153 55 my ( $r, $top ) = @_;
154 55 ▶ 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'}) { } 55 0 55
elsif ($top) { } 0 0 0
unless $recv{$$r{"receiver"}} 2 53 55
155 0 elsif ($top) { push @e, 'root route must specify a default receiver' }
156 55 ▶ $walk->( $_, 0 ) for grep { ref $_ eq 'HASH' } @{ $r->{routes} || [] };
Condition100%2/2
$$r{'routes'} || []
l!l
2233
MC/DC100%1/1
$$r{'routes'} || []
$$r{'routes'}
Truth table100%2/2
A
A= $$r{'routes'}
Aresult
11
00
157 22 };
158 22 $walk->( $d->{route}, 1 );
159 22 return \@e;
160 }
161  
162  
163 57 ▶sub service_check {
Subroutine service_check: called CC=7 SCAR=20.1
Pod documented
164 57 my ( $dev, $svc, $kind ) = @_;
165 57 ▶ 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
5610
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
166 57 my $ts = 'ts=2026-10-24T09:12:03.000Z';
167 57 ▶ if ( $kind eq 'prometheus' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "prometheus") 44 13 57
168 44 my ( $e, $rules ) = check_prometheus( $dev, $main );
169 44 ▶ 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 42 44
170 42 return ( [], $rules );
171 }
172 13 ▶ if ( $kind eq 'alertmanager' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "alertmanager") 13 0 13
173 13 my $e = check_alertmanager( $dev, $main );
174 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 13 13
175 13 $svc->{_routes} = _am_routes( _file_text( $dev, $main ) );
176 13 return ( [], {} );
177 }
178 0 return ( [], {} );
179 }
180  
181  
182 30 ▶sub http {
Subroutine http: called CC=80 SCAR=51.4
Pod documented
183 30 my ( $dev, $method, $port, $path, $run, $probe ) = @_;
184 30 ▶ my $kind = $port == 9090 ? 'prometheus' : $port == 9093 ? 'alertmanager' : return;
Branch: 2 branches
BranchTrueFalseTotal
$port == 9090 ? : 22 8 30
$port == 9093 ? : 7 1 8
185 29 my ( $name, $svc ) = map { ( $_, $dev->{services}{$_} ) }
186 29 ▶ grep { ( $dev->{services}{$_}{config_check} // '' ) eq $kind } sort keys %{ $dev->{services} || {} };
Condition75%3/4
$$dev{"services"}{$_}{"config_check"} // ""
l!l
4810
$$dev{'services'} || {}
l!l
290
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
187 29 ▶ return ( '', 0 ) unless $svc && $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $svc and $$svc{"active"} 1 28 29
Condition66%2/3
$svc and $$svc{"active"}
!ll&&!rl&&r
0128
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
188 28 ▶ my $run_cfg = ref $svc->{running} eq 'HASH' ? $svc->{running} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 28 0 28
189 28 ▶ 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
2800
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
190 28 my %qs;
191 28 ▶ if ( $path =~ s/\?(.*)//s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ s/\?(.*)//s) 10 18 28
192 10 for my $kv ( split /&/, $1 ) {
193 10 ▶ my ( $k, $v ) = map { my $x = $_ // ''; $x =~ tr/+/ /; $x =~ s/%([0-9A-Fa-f]{2})/chr hex $1/ge; $x } split /=/, $kv, 2;
Condition50%1/2
$_ // ""
l!l
200
MC/DC0%0/1
$_ // ""
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
194 10 $qs{$k} = $v;
195 }
196 }
197 28 ▶ my $js = sub { JSON::MaybeXS->new( canonical => 1 )->encode( { status => 'success', data => $_[0] } ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
198 28 ▶ if ( $kind eq 'prometheus' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "prometheus") 21 7 28
199 21 ▶ return ( 'Prometheus Server is Healthy.', 200 ) if $path eq '/-/healthy';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/-/healthy" 1 20 21
200 20 ▶ return ( 'Prometheus Server is Ready.', 200 ) if $path eq '/-/ready';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/-/ready" 0 20 20
201 20 ▶ if ( $path eq '/api/v1/targets' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/api/v1/targets") 2 18 20
202 2 ▶ my $t = _prom_targets( $dev, $svc, $run_cfg, $main, $probe ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $t = _prom_targets($dev, $svc, $run_cfg, $main, $probe) or return 1 1 2
203 1 ▶ my @want = grep { ( $qs{state} // 'any' ) =~ /\A(?:any|active)\z/ } @$t;
Condition50%1/2
$qs{"state"} // "any"
l!l
03
MC/DC0%0/1
$qs{"state"} // "any"
$qs{"state"}
Truth table50%1/2
A
A= $qs{"state"}
Aresult
11
00
204 1 return ( $js->( { activeTargets => \@want, droppedTargets => [], droppedTargetCounts => {} } ), 200 );
205 }
206 18 ▶ if ( $path eq '/api/v1/query' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/api/v1/query") 10 8 18
207 return ( JSON::MaybeXS->new( canonical => 1 )->encode( { status => 'error', errorType => 'bad_data',
208 error => 'invalid parameter "query": 1:1: parse error: no expression found in input' } ), 400 )
209 10 ▶ unless defined $qs{query} && $qs{query} =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $qs{"query"} and $qs{"query"} =~ /\S/ 1 9 10
Condition66%2/3
defined $qs{"query"} and $qs{"query"} =~ /\S/
!ll&&!rl&&r
109
MC/DC50%1/2
defined $qs{"query"} and $qs{"query"} =~ /\S/
defined $qs{"query"} $qs{"query"} =~ /\S/
Truth table66%2/3
A and B
A= defined $qs{"query"}B= $qs{"query"} =~ /\S/
ABresult
0X0
100
111
210 9 ▶ my $r = _prom_query( $dev, $svc, $run_cfg, $main, $probe, $qs{query} ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $r = _prom_query($dev, $svc, $run_cfg, $main, $probe, $qs{"query"}) or return 6 3 9
211 6 return ( $js->( { resultType => 'vector', result => $r } ), 200 );
212 }
213 8 ▶ if ( $path eq '/-/reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/-/reload") 2 6 8
214 2 ▶ return ( 'Only POST or PUT requests allowed', 405 ) if $method ne 'POST';
Branch: 1 branch
BranchTrueFalseTotal
if $method ne "POST" 0 2 2
215 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
216 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
217 1 my ( $o, $ok ) = $run->("systemctl reload $name");
218 1 ▶ return ( $ok ? '' : "failed to reload config: $o", $ok ? 200 : 500 );
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 1 0 1
$ok ? : 1 0 1
219 }
220 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
221 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
222 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
223 1 ▶ if ( $path eq '/api/v1/rules' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/api/v1/rules") 1 0 1
224 1 my @groups;
225 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
226 1 my ($d) = _yaml( $run_cfg->{$f} );
227 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
228 1 my @r;
229 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
230 my %r = ( name => $x->{alert} // $x->{record}, query => $x->{expr}, health => 'ok',
231 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
232 %r = ( %r, duration => _dur( $x->{for} // '0s' ) // 0, labels => $x->{labels} // {},
233 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
234 1 push @r, \%r;
235 }
236 1 push @groups, { name => $g->{name}, file => $f, interval => 15, rules => \@r };
237 }
238 }
239 1 return ( $js->( { groups => \@groups } ), 200 );
240 }
241 0 return;
242 }
243 7 ▶ return ( 'OK', 200 ) if $path eq '/-/healthy' || $path eq '/-/ready';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/-/healthy" or $path eq "/-/ready" 0 7 7
Condition33%1/3
$path eq "/-/healthy" or $path eq "/-/ready"
l!l&&r!l&&!r
007
MC/DC0%0/2
$path eq "/-/healthy" or $path eq "/-/ready"
$path eq "/-/healthy" $path eq "/-/ready"
Truth table33%1/3
A or B
A= $path eq "/-/healthy"B= $path eq "/-/ready"
ABresult
1X1
011
000
244 7 ▶ if ( $path eq '/-/reload' ) { # bei Alertmanager immer offen
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/-/reload") 0 7 7
245 0 ▶ return ( 'Only POST requests allowed', 405 ) if $method ne 'POST';
Branch: 1 branch
BranchTrueFalseTotal
if $method ne "POST" 0 0 0
246 0 my ( $o, $ok ) = $run->("systemctl reload $name");
247 0 ▶ return ( $ok ? '' : "failed to reload config: $o", $ok ? 200 : 500 );
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 0 0 0
$ok ? : 0 0 0
248 }
249 7 ▶ my $raw = sub { JSON::MaybeXS->new( canonical => 1 )->encode( $_[0] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
250 7 ▶ if ( $path eq '/api/v2/status' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/api/v2/status") 0 7 7
251 0 ▶ return ( $raw->( { 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
252 }
253 7 ▶ if ( $path eq '/api/v2/receivers' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/api/v2/receivers") 2 5 7
254 2 ▶ my ($d) = _yaml( $run_cfg->{$main} // '' );
Condition50%1/2
$$run_cfg{$main} // ""
l!l
20
MC/DC0%0/1
$$run_cfg{$main} // ""
$$run_cfg{$main}
Truth table50%1/2
A
A= $$run_cfg{$main}
Aresult
11
00
255 2 ▶ return ( $raw->( [ map { { name => $_->{name} } } grep { ref $_ eq 'HASH' } @{ ( ref $d eq 'HASH' ? $d->{receivers} : undef ) || [] } ] ), 200 );
Branch: 1 branch
BranchTrueFalseTotal
ref $d eq 'HASH' ? : 2 0 2
Condition50%1/2
(ref $d eq 'HASH' ? $$d{'receivers'} : undef) || []
l!l
20
MC/DC0%0/1
(ref $d eq 'HASH' ? $$d{'receivers'} : undef) || []
(ref $d eq 'HASH' ? $$d{'receivers'} : undef)
Truth table50%1/2
A
A= (ref $d eq 'HASH' ? $$d{'receivers'} : undef)
Aresult
11
00
256 }
257 5 my $now = now_epoch($dev);
258 5 ▶ my $sil = $svc->{silences} || [];
Condition100%2/2
$$svc{'silences'} || []
l!l
32
MC/DC100%1/1
$$svc{'silences'} || []
$$svc{'silences'}
Truth table100%2/2
A
A= $$svc{'silences'}
Aresult
11
00
259 5 $_ = _am_silence_view( $svc, $_, $now ) for @$sil;
260 5 ▶ if ( $path eq '/api/v2/silences' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/api/v2/silences") 2 3 5
261 my @l = map {
262 2 my $s = $_;
263 { id => $s->{id}, createdBy => $s->{author}, comment => $s->{comment}, startsAt => $s->{starts}, endsAt => $s->{ends},
264 updatedAt => _iso( $s->{_start} ), status => { state => $s->{state} },
265 1 ▶ matchers => [ map { { name => $_->{name}, value => $_->{value}, isRegex => ( $_->{op} =~ /~/ ? \1 : \0 ), isEqual => ( $_->{op} =~ /!/ ? \0 : \1 ) } } @{ $s->{_matchers} || [] } ] }
Branch: 2 branches
BranchTrueFalseTotal
$$_{'op'} =~ /~/ ? : 0 1 1
$$_{'op'} =~ /!/ ? : 0 1 1
Condition50%1/2
$$s{'_matchers'} || []
l!l
10
MC/DC0%0/1
$$s{'_matchers'} || []
$$s{'_matchers'}
Truth table50%1/2
A
A= $$s{'_matchers'}
Aresult
11
00
266 } @$sil;
267 2 return ( $raw->( \@l ), 200 );
268 }
269 3 ▶ if ( $path eq '/api/v2/alerts' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "/api/v2/alerts") 3 0 3
270 3 ▶ my $t = $svc->{alert_targets} || {};
Condition50%1/2
$$svc{'alert_targets'} || {}
l!l
30
MC/DC0%0/1
$$svc{'alert_targets'} || {}
$$svc{'alert_targets'}
Truth table50%1/2
A
A= $$svc{'alert_targets'}
Aresult
11
00
271 3 my @l;
272 3 ▶ for my $a ( @{ $svc->{alerts} || [] } ) {
Condition50%1/2
$$svc{'alerts'} || []
l!l
30
MC/DC0%0/1
$$svc{'alerts'} || []
$$svc{'alerts'}
Truth table50%1/2
A
A= $$svc{'alerts'}
Aresult
11
00
273 3 ▶ my $lab = { %{ $t->{ $a->{target} // '' } || {} }, alertname => $a->{alertname} };
Condition50%2/4
$$t{$$a{'target'} // ''} || {}
l!l
30
$$a{"target"} // ""
l!l
30
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
274 3 ▶ my @by = map { $_->{id} } grep { $_->{state} eq 'active' && _am_matches( $_->{_matchers}, $lab ) } @$sil;
Condition33%1/3
$$_{'state'} eq 'active' && _am_matches($$_{'_matchers'}, $lab)
!ll&&!rl&&r
002
MC/DC0%0/2
$$_{'state'} eq 'active' && _am_matches($$_{'_matchers'}, $lab)
$$_{'state'} eq 'active' _am_matches($$_{'_matchers'}, $lab)
Truth table33%1/3
A && B
A= $$_{'state'} eq 'active'B= _am_matches($$_{'_matchers'}, $lab)
ABresult
0X0
100
111
275 3 ▶ next if @by && ( $qs{silenced} // 'true' ) eq 'false';
Branch: 1 branch
BranchTrueFalseTotal
if @by and ($qs{"silenced"} // "true") eq "false" 1 2 3
Condition100%5/5
@by and ($qs{"silenced"} // "true") eq "false"
!ll&&!rl&&r
111
$qs{"silenced"} // "true"
l!l
11
MC/DC100%2/2
@by and ($qs{"silenced"} // "true") eq "false"
@by $qs{"silenced"}
Truth table100%3/3
A and B
A= @byB= $qs{"silenced"}
ABresult
0X0
100
111
276 2 my ( $slug, $ok ) = _amtool_routes( $dev, [ 'test', map {"$_=$lab->{$_}"} sort keys %$lab ] );
277 2 ▶ return unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2 2
278 2 ▶ my $since = $a->{since} // '2026-10-24 06:58:12 UTC';
Condition50%1/2
$$a{"since"} // "2026-10-24 06:58:12 UTC"
l!l
02
MC/DC0%0/1
$$a{"since"} // "2026-10-24 06:58:12 UTC"
$$a{"since"}
Truth table50%1/2
A
A= $$a{"since"}
Aresult
11
00
279 2 $since =~ s/\A(\S+) (\S+) UTC\z/$1T$2Z/;
280 push @l, { labels => $lab, annotations => { defined $a->{summary} ? ( summary => $a->{summary} ) : () },
281 startsAt => $since, endsAt => _iso( $now + 240 ), updatedAt => _iso( $now - 60 ),
282 2 ▶ receivers => [ map { { name => $_ } } split /,/, $slug ],
Branch: 1 branch
BranchTrueFalseTotal
@by ? : 1 1 2
283 status => { state => @by ? 'suppressed' : 'active', silencedBy => \@by, inhibitedBy => [] },
284 2 ▶ fingerprint => substr( Digest::MD5::md5_hex( join ',', map {"$_=$lab->{$_}"} sort keys %$lab ), 0, 16 ) };
Branch: 1 branch
BranchTrueFalseTotal
defined $$a{'summary'} ? : 2 0 2
285 }
286 3 return ( $raw->( \@l ), 200 );
287 }
288 0 return;
289 }
290  
291 # Ziele der laufenden Konfiguration wie /api/v1/targets: nur static_configs; Gesundheit aus der
292 # Verbindungsprobe des Simulators ($probe->(host, port): open|refused|timeout|unreach|nohost|noname).
293 # undef, wenn ein Ziel nicht sicher zu beurteilen ist (andere Discovery, relabel, unbekannte Probe).
294 5 ▶sub _prom_targets {
Subroutine _prom_targets: called CC=31 SCAR=39.9
295 5 my ( $dev, $svc, $run_cfg, $main, $probe ) = @_;
296 5 ▶ my $known = ref $svc->{scrape_health} eq q{HASH} ? $svc->{scrape_health} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'scrape_health'} eq 'HASH' ? : 5 0 5
297 5 ▶ my ($d) = _yaml( $run_cfg->{$main} // '' );
Condition50%1/2
$$run_cfg{$main} // ""
l!l
50
MC/DC0%0/1
$$run_cfg{$main} // ""
$$run_cfg{$main}
Truth table50%1/2
A
A= $$run_cfg{$main}
Aresult
11
00
298 5 ▶ return unless ref $d eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $d eq "HASH" 0 5 5
299 5 ▶ my $g = ref $d->{global} eq 'HASH' ? $d->{global} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$d{'global'} eq 'HASH' ? : 5 0 5
300 5 my $now = now_epoch($dev);
301 5 my @t;
302 5 ▶ for my $sc ( grep { ref $_ eq 'HASH' } @{ $d->{scrape_configs} || [] } ) {
Condition50%1/2
$$d{'scrape_configs'} || []
l!l
50
MC/DC0%0/1
$$d{'scrape_configs'} || []
$$d{'scrape_configs'}
Truth table50%1/2
A
A= $$d{'scrape_configs'}
Aresult
11
00
303 9 ▶ return if grep { /_sd_configs\z|\Arelabel_configs\z/ } keys %$sc;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/_sd_configs\z|\Arelabel_configs\z/;} keys %$sc 0 9 9
304 9 ▶ my $job = $sc->{job_name} // return;
Condition50%1/2
$$sc{"job_name"} // (return)
l!l
90
MC/DC0%0/1
$$sc{"job_name"} // (return)
$$sc{"job_name"}
Truth table50%1/2
A
A= $$sc{"job_name"}
Aresult
11
00
305 9 ▶ my $scheme = $sc->{scheme} // 'http';
Condition50%1/2
$$sc{"scheme"} // "http"
l!l
09
MC/DC0%0/1
$$sc{"scheme"} // "http"
$$sc{"scheme"}
Truth table50%1/2
A
A= $$sc{"scheme"}
Aresult
11
00
306 9 ▶ my $mpath = $sc->{metrics_path} // '/metrics';
Condition50%1/2
$$sc{"metrics_path"} // "/metrics"
l!l
09
MC/DC0%0/1
$$sc{"metrics_path"} // "/metrics"
$$sc{"metrics_path"}
Truth table50%1/2
A
A= $$sc{"metrics_path"}
Aresult
11
00
307 9 ▶ my $int = $sc->{scrape_interval} // $g->{scrape_interval} // '1m';
Condition40%2/5
($$sc{"scrape_interval"} // $$g{"scrape_interval"}) // "1m"
l!l
90
$$sc{"scrape_interval"} // $$g{"scrape_interval"}
l!l&&r!l&&!r
090
MC/DC0%0/2
($$sc{"scrape_interval"} // $$g{"scrape_interval"}) // "1m"
$$sc{"scrape_interval"} $$g{"scrape_interval"}
Truth table33%1/3
A // B
A= $$sc{"scrape_interval"}B= $$g{"scrape_interval"}
ABresult
1X1
011
000
308 9 ▶ my $to = $sc->{scrape_timeout} // $g->{scrape_timeout} // '10s';
Condition40%2/5
($$sc{"scrape_timeout"} // $$g{"scrape_timeout"}) // "10s"
l!l
09
$$sc{"scrape_timeout"} // $$g{"scrape_timeout"}
l!l&&r!l&&!r
009
MC/DC0%0/2
($$sc{"scrape_timeout"} // $$g{"scrape_timeout"}) // "10s"
$$sc{"scrape_timeout"} $$g{"scrape_timeout"}
Truth table33%1/3
A // B
A= $$sc{"scrape_timeout"}B= $$g{"scrape_timeout"}
ABresult
1X1
011
000
309 9 ▶ for my $s ( grep { ref $_ eq 'HASH' } @{ $sc->{static_configs} || [] } ) {
Condition50%1/2
$$sc{'static_configs'} || []
l!l
90
MC/DC0%0/1
$$sc{'static_configs'} || []
$$sc{'static_configs'}
Truth table50%1/2
A
A= $$sc{'static_configs'}
Aresult
11
00
310 9 ▶ for my $inst ( @{ $s->{targets} || [] } ) {
Condition50%1/2
$$s{'targets'} || []
l!l
90
MC/DC0%0/1
$$s{'targets'} || []
$$s{'targets'}
Truth table50%1/2
A
A= $$s{'targets'}
Aresult
11
00
311 14 ▶ my ( $h, $p ) = $inst =~ /\A\[?([^\]\s]+?)\]?:(\d+)\z/ or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $inst =~ /\A\[?([^\]\s]+?)\]?:(\d+)\z/ or return 14 0 14
312 14 my $url = "$scheme://$inst$mpath";
313 14 ▶ my $st = exists $known->{$inst} ? ( $known->{$inst} eq q{up} ? q{open} : q{given} ) : $probe ? $probe->( $h, $p ) : undef;
Branch: 3 branches
BranchTrueFalseTotal
exists $$known{$inst} ? : 9 5 14
$$known{$inst} eq 'up' ? : 5 4 9
$probe ? : 5 0 5
314 14 ▶ return unless defined $st;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $st 1 13 14
315 my $err = $st eq q{given} ? qq{Get "$url": $known->{$inst}} : $st eq 'open' ? '' : $st eq 'timeout' ? qq{Get "$url": context deadline exceeded}
316 : $st eq 'noname' ? qq{Get "$url": dial tcp: lookup $h on 127.0.0.53:53: no such host}
317 13 ▶ : qq{Get "$url": dial tcp $inst: connect: } . { refused => 'connection refused', unreach => 'network is unreachable', nohost => 'no route to host' }->{$st};
Branch: 4 branches
BranchTrueFalseTotal
$st eq 'given' ? : 4 9 13
$st eq 'open' ? : 9 0 9
$st eq 'timeout' ? : 0 0 0
$st eq 'noname' ? : 0 0 0
318 13 ▶ my %lab = ( %{ ref $s->{labels} eq 'HASH' ? $s->{labels} : {} }, instance => $inst, job => $job );
Branch: 1 branch
BranchTrueFalseTotal
ref $$s{'labels'} eq 'HASH' ? : 0 13 13
319 13 ▶ push @t, { discoveredLabels => { __address__ => $inst, __metrics_path__ => $mpath, __scheme__ => $scheme,
Branch: 2 branches
BranchTrueFalseTotal
$st eq 'open' ? : 9 4 13
$st eq 'open' ? : 9 4 13
320 __scrape_interval__ => $int, __scrape_timeout__ => $to, job => $job },
321 labels => \%lab, scrapePool => $job, scrapeUrl => $url, globalUrl => $url, lastError => $err,
322 lastScrape => _iso( $now - 7 ), lastScrapeDuration => $st eq 'open' ? 0.004 : 0, health => $st eq 'open' ? 'up' : 'down',
323 scrapeInterval => $int, scrapeTimeout => $to };
324 }
325 }
326 }
327 4 return \@t;
328 }
329  
330 # Eine Sofortabfrage: nur ein Selektor NAME{matcher,…} mit optionalem Vergleich gegen eine Zahl.
331 # up aus den Zielen; ALERTS leer (keine Regel feuert); sonst die Reihen aus C<metrics> des Dienstes
332 # (Exposition: name{label="wert"} wert je Zeile). Ohne C<metrics>, bei anderer PromQL: undef (Luecke).
333 9 ▶sub _prom_query {
Subroutine _prom_query: called CC=25 SCAR=32.8
334 9 my ( $dev, $svc, $run_cfg, $main, $probe, $q ) = @_;
335 9 $q =~ s/\A\s+|\s+\z//g;
336 9 ▶ my ( $age, $name, $sel, $cmp, $num ) = $q =~ /\A(time\(\)\s*-\s*)?([a-zA-Z_:][\w:]*)?\s*(?:\{(.*)\})?\s*(?:(==|!=|>=|<=|>|<)\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?))?\z/s or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $q =~ /\A(time\(\)\s*-\s*)?([a-zA-Z_:][\w:]*)?\s*(?:\{(.*)\})?\s*(?:(==|!=|>=|<=|>|<)\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?))?\z/s or return 7 2 9
337 7 my @m;
338 7 ▶ if ( defined $sel ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sel) 2 5 7
339 2 my $rest = $sel;
340 2 ▶ while ( $rest =~ s/\A\s*([A-Za-z_]\w*)\s*(=~|!~|!=|=)\s*"((?:[^"\\]|\\.)*)"\s*(?:,|\z)// ) { push @m, { name => $1, op => $2, value => $3 } }
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ s/\A\s*([A-Za-z_]\w*)\s*(=~|!~|!=|=)\s*"((?:[^"\\]|\\.)*)"\s*(?:,|\z)//) 2 2 4
341 2 ▶ return if $rest =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /\S/ 0 2 2
342 }
343 7 ▶ push @m, { name => '__name__', op => '=', value => $name } if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 7 0 7
344 7 ▶ my ($nm) = map { $_->{value} } grep { $_->{name} eq '__name__' && $_->{op} eq '=' } @m;
Condition66%2/3
$$_{'name'} eq '__name__' && $$_{'op'} eq '='
!ll&&!rl&&r
207
MC/DC50%1/2
$$_{'name'} eq '__name__' && $$_{'op'} eq '='
$$_{'name'} eq '__name__' $$_{'op'} eq '='
Truth table66%2/3
A && B
A= $$_{'name'} eq '__name__'B= $$_{'op'} eq '='
ABresult
0X0
100
111
345 7 ▶ return unless defined $nm;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nm 0 7 7
346 7 my @series; # [ labels, wert ]
347 7 ▶ if ( $nm eq 'up' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nm eq 'up') { } 3 4 7
elsif ($nm =~ /\AALERTS(?:_FOR_STATE)?\z/) { } 1 3 4
348 3 ▶ my $t = _prom_targets( $dev, $svc, $run_cfg, $main, $probe ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $t = _prom_targets($dev, $svc, $run_cfg, $main, $probe) or return 3 0 3
349 3 ▶ @series = map { [ { %{ $_->{labels} }, __name__ => 'up' }, $_->{health} eq 'up' ? 1 : 0 ] } @$t;
Branch: 1 branch
BranchTrueFalseTotal
$$_{'health'} eq 'up' ? : 6 3 9
350 }
351 elsif ( $nm =~ /\AALERTS(?:_FOR_STATE)?\z/ ) { }
352 else {
353 3 ▶ return unless defined $svc->{metrics};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$svc{"metrics"} 0 3 3
354 3 for my $line ( split /\n/, $svc->{metrics} ) {
355 6 ▶ next if $line =~ /\A\s*(?:#|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A\s*(?:#|\z)/ 3 3 6
356 3 ▶ my ( $n, $l, $v ) = $line =~ /\A\s*([a-zA-Z_:][\w:]*)\s*(?:\{(.*)\})?\s+(\S+)\s*\z/ or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $line =~ /\A\s*([a-zA-Z_:][\w:]*)\s*(?:\{(.*)\})?\s+(\S+)\s*\z/ or return 3 0 3
357 3 my %lab = ( __name__ => $n );
358 3 ▶ $lab{$1} = $2 while ( $l // '' ) =~ /([A-Za-z_]\w*)\s*=\s*"((?:[^"\\]|\\.)*)"/g;
Branch: 1 branch
BranchTrueFalseTotal
($l // "") =~ /([A-Za-z_]\w*)\s*=\s*"((?:[^"\\]|\\.)*)"/g and do { $lab{$1} = $2 } 6 3 9
Condition50%1/2
$l // ""
l!l
90
MC/DC0%0/1
$l // ""
$l
Truth table50%1/2
A
A= $l
Aresult
11
00
359 3 push @series, [ \%lab, $v ];
360 }
361 3 ▶ return unless grep { $_->[0]{__name__} eq $nm } @series; # eine Reihe, die der Fall nicht nennt
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$$_[0]{"__name__"} eq $nm;} @series 1 2 3
362 }
363 6 my $now = now_epoch($dev);
364 0 ▶ my %op = ( '==' => sub { $_[0] == $_[1] }, '!=' => sub { $_[0] != $_[1] }, '>' => sub { $_[0] > $_[1] },
Subroutine __ANON__: called CC=1 SCAR=2.6
Subroutine __ANON__: not called CC=1 SCAR=2.6
Subroutine __ANON__: not called CC=1 SCAR=2.6
365 0 ▶ '<' => sub { $_[0] < $_[1] }, '>=' => sub { $_[0] >= $_[1] }, '<=' => sub { $_[0] <= $_[1] } );
Subroutine __ANON__: not called CC=1 SCAR=3.5
Subroutine __ANON__: not called CC=1 SCAR=3.5
Subroutine __ANON__: not called CC=1 SCAR=3.5
366 6 my @r;
367 6 for my $s ( sort { join( ',', map {"$_=$a->[0]{$_}"} sort keys %{ $a->[0] } ) cmp join( ',', map {"$_=$b->[0]{$_}"} sort keys %{ $b->[0] } ) } @series ) {
368 11 ▶ next unless _am_matches( \@m, $s->[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless _am_matches(\@m, $$s[0]) 2 9 11
369 9 ▶ my $v = $age ? $now - $s->[1] : $s->[1]; # time() - x: Alter, ohne Namen
Branch: 1 branch
BranchTrueFalseTotal
$age ? : 1 8 9
370 9 ▶ next if defined $cmp && !$op{$cmp}->( $v, $num );
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmp and not $op{$cmp}($v, $num) 1 8 9
Condition100%3/3
defined $cmp and not $op{$cmp}($v, $num)
!ll&&!rl&&r
711
MC/DC100%2/2
defined $cmp and not $op{$cmp}($v, $num)
defined $cmp not $op{$cmp}($v, $num)
Truth table100%3/3
A and not(B)
A= defined $cmpB= not $op{$cmp}($v, $num)
ABresult
0X0
100
111
371 8 my %lab = %{ $s->[0] };
372 8 ▶ delete $lab{__name__} if $age;
Branch: 1 branch
BranchTrueFalseTotal
if $age 1 7 8
373 8 push @r, { metric => \%lab, value => [ $now, "$v" ] };
374 }
375 6 return \@r;
376 }
377  
378 # Startoptionen, mit denen Prometheus laeuft (ARGS aus /etc/default/*), ueber den
379 # Standardwerten von Prometheus 2.x (Debian-Pfade). Werte sind Strings wie in der API.
380 7 my %PROM_FLAG_DEFAULT = (
381 'config.file' => '/etc/prometheus/prometheus.yml',
382 'storage.tsdb.path' => '/var/lib/prometheus/metrics2/',
383 'storage.tsdb.retention.time' => '0s',
384 'storage.tsdb.retention.size' => '0B',
385 'web.listen-address' => '0.0.0.0:9090',
386 'web.external-url' => '',
387 'web.enable-lifecycle' => 'false',
388 'web.enable-admin-api' => 'false',
389 'log.level' => 'info',
390 );
391  
392 3 ▶sub _prom_flags {
Subroutine _prom_flags: called CC=13 SCAR=29.3
393 3 my ($run_cfg) = @_;
394 3 my %f = %PROM_FLAG_DEFAULT;
395 3 for my $file ( sort grep { m{\A/etc/default/} } keys %$run_cfg ) {
396 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
397 3 ▶ next unless $line =~ /\A\s*ARGS=(.*)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\A\s*ARGS=(.*)\z/ 0 3 3
398 3 my $args = $1; # Kopie: shellwords bekaeme $1 als Alias
399 # die Shell entquotet ARGS="…", systemd teilt $ARGS an Leerraum
400 3 my @w = split q{ }, join q{ }, Text::ParseWords::shellwords($args);
401 3 ▶ while ( defined( my $w = shift @w ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $w = shift @w)) 4 3 7
402 4 ▶ next unless $w =~ /\A--?(?:no-)?([\w.\-]+)(?:=(.*))?\z/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $w =~ /\A--?(?:no-)?([\w.\-]+)(?:=(.*))?\z/s 0 4 4
403 4 my ( $k, $v ) = ( $1, $2 );
404 0 ▶ if ( $w =~ /\A--?no-/ ) { $f{$k} = 'false'; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($w =~ /\A--?no-/) 0 4 4
405 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
406 4 $f{$k} = $v;
407 }
408 }
409 }
410 3 return \%f;
411 }
412  
413  
414 5 ▶sub promtool {
Subroutine promtool: called CC=13 SCAR=27.4
Pod documented
415 5 my ( $dev, $av ) = @_;
416 5 my @a = grep { !/\A--/ } @$av;
417 5 my ( $cmd, $what, @files ) = @a;
418 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
419 5 my ( @out, $ok );
420 5 $ok = 1;
421 5 for my $f (@files) {
422 5 push @out, "Checking $f";
423 5 ▶ if ( $what eq 'config' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq 'config') { } 4 1 5
424 4 my ( $e, $rules, $n ) = check_prometheus( $dev, $f );
425 4 ▶ if (@$e) { push @out, map {" FAILED: $_"} @$e; $ok = 0; push @out, ''; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@$e) 2 2 4
426 2 push @out, ' SUCCESS: ' . scalar( keys %$rules ) . ' rule files found', " SUCCESS: $f is valid prometheus config file syntax", '';
427 2 for my $r ( sort keys %$rules ) { push @out, "Checking $r", " SUCCESS: " . ( _check_rules( $r, $rules->{$r} ) )[0] . ' rules found', '' }
428 }
429 else {
430 1 my $t = _file_text( $dev, $f );
431 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
432 1 my ( $n, $e ) = _check_rules( $f, $t );
433 1 ▶ if ($e) { push @out, ' FAILED:', @$e, ''; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($e) 1 0 1
434 0 push @out, " SUCCESS: $n rules found", '';
435 }
436 }
437 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
438 5 return ( join( "\n", @out ), $ok );
439 }
440  
441  
442 # Wirksame Einstellungen je Empfaenger: { empfaenger => { repeat_interval, group_wait,
443 # group_interval, group_by } } — Unterrouten erben, was sie nicht selbst setzen (erste Route je Empfaenger)
444 7 our %AM_ROUTE_DEFAULT = ( group_wait => '30s', group_interval => '5m', repeat_interval => '4h' );
445  
446 13 ▶sub _am_routes {
Subroutine _am_routes: called CC=2 SCAR=7.1
447 13 my ($text) = @_;
448 13 my ($d) = _yaml($text);
449 13 my %out;
450 my $walk;
451 27 ▶ $walk = sub {
Subroutine __ANON__: called CC=9 SCAR=22.9
452 27 my ( $r, $parent ) = @_;
453 27 ▶ return unless ref $r eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $r eq "HASH" 0 27 27
454 27 my %eff = %$parent;
455 27 ▶ 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} 29 79 108
456 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 27 27
457 27 my %copy = %eff;
458 27 ▶ $out{ $eff{receiver} } //= \%copy if defined $eff{receiver};
Branch: 1 branch
BranchTrueFalseTotal
if defined $eff{"receiver"} 27 0 27
Condition50%1/2
$out{$eff{"receiver"}} //= \%copy
l!l
027
MC/DC0%0/1
$out{$eff{"receiver"}} //= \%copy
$out{$eff{"receiver"}}
Truth table50%1/2
A
A= $out{$eff{"receiver"}}
Aresult
11
00
459 27 ▶ $walk->( $_, \%eff ) for @{ $r->{routes} || [] };
Condition100%2/2
$$r{'routes'} || []
l!l
1314
MC/DC100%1/1
$$r{'routes'} || []
$$r{'routes'}
Truth table100%2/2
A
A= $$r{'routes'}
Aresult
11
00
460 13 };
461 13 ▶ $walk->( ref $d eq 'HASH' ? $d->{route} : undef, {%AM_ROUTE_DEFAULT} );
Branch: 1 branch
BranchTrueFalseTotal
ref $d eq 'HASH' ? : 13 0 13
462 13 return \%out;
463 }
464  
465 # Zeit: Uhr des Geraets (clock "Oct 24 09:12", Jahr 2026, Zone tz, Vorgabe +02:00) als Epoche
466 7 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 );
467  
468  
469 44 ▶sub now_epoch {
Subroutine now_epoch: called CC=3 SCAR=11.4
Pod documented
470 44 my ($dev) = @_;
471 44 require Time::Local;
472 44 ▶ 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
440
MC/DC0%0/1
$$dev{"clock"} // "Oct 20 09:12"
$$dev{"clock"}
Truth table50%1/2
A
A= $$dev{"clock"}
Aresult
11
00
473 44 ▶ 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
440
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
474 }
475  
476 44 ▶sub _tz_secs {
Subroutine _tz_secs: called CC=4 SCAR=14.3
477 44 my ($dev) = @_;
478 44 ▶ 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 44 0 44
Condition100%2/2
$$dev{"tz"} // "+02:00"
l!l
1232
MC/DC100%1/1
$$dev{"tz"} // "+02:00"
$$dev{"tz"}
Truth table100%2/2
A
A= $$dev{"tz"}
Aresult
11
00
479 44 ▶ return ( $sg eq '-' ? -1 : 1 ) * ( $h * 3600 + $m * 60 );
Branch: 1 branch
BranchTrueFalseTotal
$sg eq '-' ? : 0 44 44
480 }
481  
482 # RFC 3339 -> Epoche; undef wenn nicht lesbar
483 2 ▶sub _rfc3339 {
Subroutine _rfc3339: called CC=5 SCAR=16.8
484 2 my ($t) = @_;
485 2 require Time::Local;
486 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
487 2 my $e = Time::Local::timegm( $s, $m, $h, $D, $M - 1, $Y );
488 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
489 2 return $e;
490 }
491  
492 48 ▶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
493  
494 # Go-Dauer: 2h, 90m, 1h30m, 45s
495 2 ▶sub _godur {
Subroutine _godur: called CC=4 SCAR=14.3
496 2 my ($d) = @_;
497 2 ▶ 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 2 2
Condition33%1/3
defined $d and $d =~ /\A(?:\d+(?:\.\d+)?(?:h|m|s|ms))+\z/
!ll&&!rl&&r
002
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
498 2 my $t = 0;
499 2 ▶ 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) 2 2 4
500 2 return int $t;
501 }
502  
503 # Matcher: name=wert, name!=wert, name=~re, name!~re (Wert ggf. in Anfuehrungszeichen)
504 28 ▶sub _am_matcher {
Subroutine _am_matcher: called CC=2 SCAR=7.0
505 28 my ($x) = @_;
506 28 ▶ 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 28 0 28
507 28 $v =~ s/\A"(.*)"\z/$1/s;
508 28 $v =~ s/\A'(.*)'\z/$1/s;
509 28 return { name => $n, op => $op, value => $v };
510 }
511  
512 59 ▶sub _am_matches {
Subroutine _am_matches: called CC=7 SCAR=19.6
513 59 my ( $ms, $labels ) = @_;
514 59 for my $m (@$ms) {
515 60 ▶ my $have = $labels->{ $m->{name} } // '';
Condition100%2/2
$$labels{$$m{"name"}} // ""
l!l
4713
MC/DC100%1/1
$$labels{$$m{"name"}} // ""
$$labels{$$m{"name"}}
Truth table100%2/2
A
A= $$labels{$$m{"name"}}
Aresult
11
00
516 60 ▶ my $hit = $m->{op} =~ /~/ ? ( eval { $have =~ /\A(?:$m->{value})\z/ } // 0 ) : $have eq $m->{value};
Branch: 1 branch
BranchTrueFalseTotal
$$m{'op'} =~ /~/ ? : 23 37 60
Condition50%1/2
eval { do { $have =~ /\A(?:$$m{"value"})\z/ } } // 0
l!l
230
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
517 60 ▶ $hit = !$hit if $m->{op} =~ /\A!/;
Branch: 1 branch
BranchTrueFalseTotal
if $$m{"op"} =~ /\A!/ 0 60 60
518 60 ▶ return 0 unless $hit;
Branch: 1 branch
BranchTrueFalseTotal
unless $hit 26 34 60
519 }
520 33 return 1;
521 }
522  
523 # Silence mit abgeleiteten Feldern: starts/ends (UTC), state, covers (Namen aus alert_targets)
524 15 ▶sub _am_silence_view {
Subroutine _am_silence_view: called CC=5 SCAR=16.2
525 15 my ( $svc, $sil, $now ) = @_;
526 15 ▶ my $t = $svc->{alert_targets} || {};
Condition50%1/2
$$svc{'alert_targets'} || {}
l!l
150
MC/DC0%0/1
$$svc{'alert_targets'} || {}
$$svc{'alert_targets'}
Truth table50%1/2
A
A= $$svc{'alert_targets'}
Aresult
11
00
527 15 $sil->{starts} = _iso( $sil->{_start} );
528 15 $sil->{ends} = _iso( $sil->{_end} );
529 15 ▶ $sil->{state} = $sil->{_expired} || $sil->{_end} <= $now ? 'expired' : $sil->{_start} > $now ? 'pending' : 'active';
Branch: 2 branches
BranchTrueFalseTotal
$$sil{'_expired'} || $$sil{'_end'} <= $now ? : 2 13 15
$$sil{'_start'} > $now ? : 6 7 13
Condition66%2/3
$$sil{"_expired"} or $$sil{"_end"} <= $now
l!l&&r!l&&!r
2013
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
530 15 $sil->{covers} = [ sort grep { _am_matches( $sil->{_matchers}, $t->{$_} ) } keys %$t ];
531 15 return $sil;
532 }
533  
534 10 ▶sub _am_svc {
Subroutine _am_svc: called CC=4 SCAR=14.6
535 10 my ($dev) = @_;
536 10 ▶ my ($n) = grep { ( $dev->{services}{$_}{config_check} // '' ) eq 'alertmanager' } sort keys %{ $dev->{services} || {} };
Condition50%2/4
$$dev{"services"}{$_}{"config_check"} // ""
l!l
130
$$dev{'services'} || {}
l!l
100
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
537 10 ▶ return defined $n ? $dev->{services}{$n} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 10 0 10
538 }
539  
540 7 ▶sub _amtool_silence {
Subroutine _amtool_silence: called CC=42 SCAR=42.8
541 7 my ( $dev, $sub, $av ) = @_;
542 7 my ( %opt, @pos );
543 7 my @a = @$av;
544 7 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 21 7 28
545 21 my $x = shift @a;
546 21 ▶ if ( $x =~ /\A--([\w.-]+)=(.*)\z/s ) { $opt{$1} = $2 }
Branch: 4 branches
BranchTrueFalseTotal
if ($x =~ /\A--([\w.-]+)=(.*)\z/s) { } 12 9 21
elsif ($x =~ /\A--([\w.-]+)\z/ and not $1 =~ /\A(?:quiet|expired|extended)\z/) { } 0 9 9
elsif ($x =~ /\A-([acdq])\z/) { } 2 7 9
elsif ($x =~ /\A--(quiet|expired|extended)\z/) { } 0 7 7
547 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
900
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
548 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
549 0 elsif ( $x =~ /\A--(quiet|expired|extended)\z/ ) { $opt{$1} = 1 }
550 7 else { push @pos, $x }
551 }
552 7 my $url = $opt{'alertmanager.url'};
553 7 ▶ if ( !defined $url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $url) 1 6 7
554 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
555 1 ($url) = $cf =~ /^\s*alertmanager\.url:\s*"?([^"\s]+)/m;
556 }
557 7 ▶ return ( 'amtool: error: required flag --alertmanager.url not provided', 0 ) unless defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 1 6 7
558 6 my $svc = _am_svc($dev);
559 return ( qq{Post "$url/api/v2/silences": dial tcp: connect: connection refused}, 0 )
560 6 ▶ 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 6 6
Condition33%2/6
$svc and $$svc{"active"} and $url =~ m(\Ahttps?://(?:localhost|127\.0\.0\.1|\[::1\])?(?::9093)?/?\z)
!ll&&!rl&&r
006
$svc and $$svc{"active"}
!ll&&!rl&&r
006
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
561 6 my $now = now_epoch($dev);
562 6 ▶ my $sil = $svc->{silences} //= [];
Condition100%2/2
$$svc{"silences"} //= []
l!l
42
MC/DC100%1/1
$$svc{"silences"} //= []
$$svc{"silences"}
Truth table100%2/2
A
A= $$svc{"silences"}
Aresult
11
00
563 6 $_ = _am_silence_view( $svc, $_, $now ) for @$sil;
564 6 ▶ if ( $sub eq 'add' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "add") 4 2 6
565 4 my @m;
566 4 for my $p (@pos) {
567 5 ▶ 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
50
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
568 5 ▶ return ( qq{amtool: error: bad matcher format: $p}, 0 ) unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 0 5 5
569 5 push @m, $m;
570 }
571 4 ▶ return ( 'amtool: error: no matchers specified', 0 ) unless @m;
Branch: 1 branch
BranchTrueFalseTotal
unless @m 0 4 4
572 4 ▶ 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 3 4
Condition66%2/3
defined $opt{"comment"} and length $opt{"comment"}
!ll&&!rl&&r
103
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
573 3 ▶ my $start = defined $opt{start} ? _rfc3339( $opt{start} ) : $now;
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'start'} ? : 1 2 3
574 3 ▶ 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 3 3
575 3 my $end;
576 3 ▶ if ( defined $opt{end} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{'end'}) { } 1 2 3
577 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
578 }
579 else {
580 2 ▶ 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
20
$opt{"duration"} // "1h"
l!l
20
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
581 2 $end = $start + $d;
582 }
583 3 ▶ return ( 'amtool: error: silence cannot end before it starts', 0 ) if $end <= $start;
Branch: 1 branch
BranchTrueFalseTotal
if $end <= $start 0 3 3
584 3 ▶ return ( 'amtool: error: silence cannot end in the past', 0 ) if $end <= $now;
Branch: 1 branch
BranchTrueFalseTotal
if $end <= $now 0 3 3
585 3 my $id = sprintf '%08x-%04x-4%03x-a%03x-%012x', 0x5e1e0000 + @$sil, 0x2026, scalar @$sil, 0x124, $start;
586 4 ▶ 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
03
MC/DC0%0/1
$opt{"author"} // "root"
$opt{"author"}
Truth table50%1/2
A
A= $opt{"author"}
Aresult
11
00
587 3 author => $opt{author} // 'root', _matchers => \@m, _start => $start, _end => $end }, $now );
588 3 return ( $id, 1 );
589 }
590 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
591 1 ▶ my @l = grep { $opt{expired} ? $_->{state} eq 'expired' : $_->{state} ne 'expired' } @$sil;
Branch: 1 branch
BranchTrueFalseTotal
$opt{'expired'} ? : 0 2 2
592 0 ▶ return ( join( "\n", map { $_->{id} } @l ), 1 ) if $opt{quiet};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"quiet"} 0 1 1
593 1 my $f = '%-37s %-40s %-24s %-10s %s';
594 return ( join( "\n", sprintf( $f, 'ID', 'Matchers', 'Ends At', 'Created By', 'Comment' ),
595 1 map { sprintf( $f, $_->{id}, join( ' ', @{ $_->{matchers} } ), $_->{ends} =~ s/T/ /r =~ s/Z\z/ UTC/r, $_->{author}, $_->{comment} ) } @l ), 1 );
596 }
597 1 ▶ if ( $sub eq 'expire' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "expire") 1 0 1
598 1 ▶ return ( 'amtool: error: no silence IDs specified', 0 ) unless @pos;
Branch: 1 branch
BranchTrueFalseTotal
unless @pos 0 1 1
599 1 for my $id (@pos) {
600 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
601 1 $s->{_expired} = 1;
602 1 _am_silence_view( $svc, $s, $now );
603 }
604 1 return ( '', 1 );
605 }
606 0 push @GAPS, join( ' ', 'amtool silence', $sub, @$av );
607 0 return ( '', 0 );
608 }
609  
610 # amtool config routes [show] | config routes test [--verify.receivers=LISTE] LABEL…: Baum bzw.
611 # Empfaenger aus --config.file oder der laufenden Konfiguration (--alertmanager.url); Matcher je
612 # Route sortiert, ein Zweig nach dem ersten Treffer nur mit continue. () = Luecke
613 8 ▶sub _amtool_routes {
Subroutine _amtool_routes: called CC=34 SCAR=37.7
614 8 my ( $dev, $av ) = @_;
615 8 my ( $file, $verify, @pos );
616 8 my @a = @$av;
617 8 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 25 8 33
618 25 my $x = shift @a;
619 25 ▶ if ( $x =~ /\A--config\.file=(.*)\z/ ) { $file = $1 }
Branch: 7 branches
BranchTrueFalseTotal
if ($x =~ /\A--config\.file=(.*)\z/) { } 5 20 25
elsif ($x eq '--config.file') { } 1 19 20
elsif ($x =~ /\A--verify\.receivers=(.*)\z/) { } 1 18 19
elsif ($x eq '--verify.receivers') { } 0 18 18
elsif ($x =~ /\A--alertmanager\.url=/) { } 0 18 18
elsif ($x eq '--alertmanager.url') { } 0 18 18
elsif ($x =~ /\A-/) { } 0 18 18
620 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
621 1 elsif ( $x =~ /\A--verify\.receivers=(.*)\z/ ) { $verify = $1 }
622 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
623 elsif ( $x =~ /\A--alertmanager\.url=/ ) { }
624 0 elsif ( $x eq '--alertmanager.url' ) { shift @a }
625 0 elsif ( $x =~ /\A-/ ) { return }
626 18 else { push @pos, $x }
627 }
628 8 ▶ my $sub = @pos && $pos[0] =~ /\A(?:show|test)\z/ ? shift @pos : 'show';
Branch: 1 branch
BranchTrueFalseTotal
@pos && $pos[0] =~ /\A(?:show|test)\z/ ? : 7 1 8
Condition66%2/3
@pos and $pos[0] =~ /\A(?:show|test)\z/
!ll&&!rl&&r
107
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
629 8 ▶ return if $sub eq 'show' && @pos;
Branch: 1 branch
BranchTrueFalseTotal
if $sub eq "show" and @pos 0 8 8
Condition66%2/3
$sub eq "show" and @pos
!ll&&!rl&&r
620
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
630 8 my $text;
631 8 ▶ if ( defined $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) { } 6 2 8
632 6 $text = _file_text( $dev, $file );
633 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
634 }
635 else {
636 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
637 2 ▶ return unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 0 2 2
638 2 ▶ my $main = $svc->{config_main} // ( ref $svc->{config} ? $svc->{config}[0] : $svc->{config} ) // return;
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'config'} ? : 0 0 0
Condition40%2/5
($$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})) // (return)
l!l
20
$$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
l!l&&r!l&&!r
200
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 table33%1/3
A // B
A= $$svc{"config_main"}B= (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
ABresult
1X1
011
000
639 2 ▶ $text = ( ref $svc->{running} eq 'HASH' ? $svc->{running}{$main} : undef ) // _file_text( $dev, $main ) // return;
Branch: 1 branch
BranchTrueFalseTotal
ref $$svc{'running'} eq 'HASH' ? : 2 0 2
Condition40%2/5
((ref $$svc{"running"} eq "HASH" ? $$svc{"running"}{$main} : undef) // _file_text($dev, $main)) // (return)
l!l
20
(ref $$svc{"running"} eq "HASH" ? $$svc{"running"}{$main} : undef) // _file_text($dev, $main)
l!l&&r!l&&!r
200
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 table33%1/3
A // B
A= (ref $$svc{"running"} eq "HASH" ? $$svc{"running"}{$main} : undef)B= _file_text($dev, $main)
ABresult
1X1
011
000
640 }
641 8 my $e = _am_check_text($text);
642 8 ▶ return ( "amtool: error: $e->[0]", 0 ) if @$e;
Branch: 1 branch
BranchTrueFalseTotal
if @$e 1 7 8
643 7 my ($d) = _yaml($text);
644 7 ▶ my $q = sub { my $v = shift; $v =~ s/(["\\])/\\$1/g; qq{"$v"} };
Subroutine __ANON__: called CC=1 SCAR=0.0
645 7 my $route;
646 24 ▶ $route = sub {
Subroutine __ANON__: called CC=13 SCAR=26.7
647 24 my ( $r, $parent ) = @_;
648 24 my @m;
649 24 ▶ 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' ? : 7 17 24
Condition50%1/2
_am_matcher($s) // (return)
l!l
120
MC/DC0%0/1
_am_matcher($s) // (return)
_am_matcher($s)
Truth table50%1/2
A
A= _am_matcher($s)
Aresult
11
00
650 24 ▶ 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 19 24
651 24 ▶ 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 19 24
652 24 ▶ @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
653 24 ▶ 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
2400
$$r{'continue'} && "$$r{'continue'}" =~ /\A(?:1|true)\z/
!ll&&!rl&&r
1905
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
654 24 ▶ for my $c ( grep { ref $_ eq 'HASH' } @{ $r->{routes} || [] } ) { push @{ $node->{kids} }, $route->( $c, $node ) // return }
Condition75%3/4
$$r{'routes'} || []
l!l
717
&$route($c, $node) // (return)
l!l
170
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
655 24 return $node;
656 7 };
657 7 ▶ my $root = $route->( $d->{route}, {} ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $root = &$route($$d{"route"}, scalar {}) or return 7 0 7
658 7 ▶ if ( $sub eq 'show' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "show") 1 6 7
659 1 my @l = ( 'Routing tree:', '.' );
660 1 my $tree;
661 4 ▶ $tree = sub {
Subroutine __ANON__: called CC=8 SCAR=20.9
662 4 my ( $n, $pre, $last ) = @_;
663 4 ▶ my $slug = @{ $n->{m} } ? '{' . join( ',', map { $_->{name} . $_->{op} . $q->( $_->{value} ) } @{ $n->{m} } ) . '}' : 'default-route';
Branch: 1 branch
BranchTrueFalseTotal
@{$$n{'m'};} ? : 3 1 4
664 4 ▶ $slug .= ', continue: true' if $n->{continue};
Branch: 1 branch
BranchTrueFalseTotal
if $$n{"continue"} 1 3 4
665 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
666 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
667 4 ▶ $tree->( $k[$_], $pre . ( $last ? ' ' : '│ ' ), $_ == $#k ) for 0 .. $#k;
Branch: 1 branch
BranchTrueFalseTotal
$last ? : 3 0 3
668 1 };
669 1 $tree->( $root, '', 1 );
670 1 return ( join( "\n", @l ), 1 );
671 }
672 6 my %lab;
673 6 ▶ 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 11 0 11
674 6 my $match;
675 18 ▶ $match = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
676 18 my ($n) = @_;
677 18 ▶ return () unless _am_matches( $n->{m}, \%lab );
Branch: 1 branch
BranchTrueFalseTotal
unless _am_matches($$n{"m"}, \%lab) 7 11 18
678 11 my @all;
679 11 ▶ for my $c ( @{ $n->{kids} || [] } ) {
Condition100%2/2
$$n{'kids'} || []
l!l
65
MC/DC100%1/1
$$n{'kids'} || []
$$n{'kids'}
Truth table100%2/2
A
A= $$n{'kids'}
Aresult
11
00
680 12 my @hit = $match->($c);
681 12 push @all, @hit;
682 12 ▶ last if @hit && !$c->{continue};
Branch: 1 branch
BranchTrueFalseTotal
if @hit and not $$c{"continue"} 4 8 12
Condition100%3/3
@hit and not $$c{"continue"}
!ll&&!rl&&r
714
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
683 }
684 11 ▶ return @all ? @all : ($n);
Branch: 1 branch
BranchTrueFalseTotal
@all ? : 4 7 11
685 6 };
686 6 ▶ my $slug = join ',', map { $_->{receiver} // '' } $match->($root);
Condition50%1/2
$$_{"receiver"} // ""
l!l
70
MC/DC0%0/1
$$_{"receiver"} // ""
$$_{"receiver"}
Truth table50%1/2
A
A= $$_{"receiver"}
Aresult
11
00
687 6 ▶ 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 5 6
Condition66%4/6
defined $verify and length $verify and $verify ne $slug
!ll&&!rl&&r
501
defined $verify and length $verify
!ll&&!rl&&r
501
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
688 5 return ( $slug, 1 );
689 }
690  
691 16 ▶sub amtool {
Subroutine amtool: called CC=37 SCAR=45.3
Pod documented
692 16 my ( $dev, $av ) = @_;
693 16 my @all = @$av;
694 16 ▶ if ( ( $all[0] // '' ) eq 'config' && ( $all[1] // '' ) eq 'routes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($all[0] // "") eq "config" and ($all[1] // "") eq "routes") 6 10 16
Condition57%4/7
($all[0] // "") eq "config" and ($all[1] // "") eq "routes"
!ll&&!rl&&r
1006
$all[0] // ""
l!l
160
$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
695 6 my @r = _amtool_routes( $dev, [ @all[ 2 .. $#all ] ] );
696 6 ▶ return @r if @r;
Branch: 1 branch
BranchTrueFalseTotal
if @r 6 0 6
697 0 push @GAPS, join( ' ', 'amtool', @$av );
698 0 return ( '', 0 );
699 }
700 10 ▶ if ( ( $all[0] // '' ) eq 'silence' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($all[0] // "") eq "silence") 7 3 10
Condition50%1/2
$all[0] // ""
l!l
100
MC/DC0%0/1
$all[0] // ""
$all[0]
Truth table50%1/2
A
A= $all[0]
Aresult
11
00
701 7 ▶ my $sub = defined $all[1] && $all[1] !~ /\A-/ ? $all[1] : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $all[1] && !($all[1] =~ /\A-/) ? : 7 0 7
Condition33%1/3
defined $all[1] and not $all[1] =~ /\A-/
!ll&&!rl&&r
007
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
702 7 ▶ return _amtool_silence( $dev, $sub, [ @all[ ( $sub eq '' ? 1 : 2 ) .. $#all ] ] );
Branch: 1 branch
BranchTrueFalseTotal
$sub eq '' ? : 0 7 7
703 }
704 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
705 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
706 2 my $now = now_epoch($dev);
707 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
708 2 $_ = _am_silence_view( $svc, $_, $now ) for @$sil;
709 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
710 2 my @rows;
711 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
712 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
713 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
714 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
715 }
716 2 return ( join( "\n", sprintf( '%-22s %-26s %s', 'Alertname', 'Starts At', 'Summary' ), @rows ), 1 );
717 }
718 1 my @a = grep { !/\A--/ } @$av;
719 1 my ( $cmd, @files ) = @a;
720 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
721 1 my ( @out, $ok );
722 1 $ok = 1;
723 1 for my $f (@files) {
724 1 push @out, "Checking '$f'";
725 1 my $e = check_alertmanager( $dev, $f );
726 1 ▶ if (@$e) { push @out, " FAILED: $_" for @$e; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@$e) 1 0 1
727 0 my ($d) = _yaml( _file_text( $dev, $f ) );
728 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
729 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
730 }
731 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
732 1 return ( join( "\n", @out ), $ok );
733 }
734  
735 7 1;
736  
737 __END__
« blib/lib/Langertha/Holmgang/Lint.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Logrotate.pm »