« 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, $_)
$$dev{'files'} || {}
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, $_)
Truth table50%1/2
A
A= $$dev{'files'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 137 | ▶ | return ($d) unless $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$what //= "did not find expected key"
$what
Truth table0%0/2
A
A= $what
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $what =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return ( undef, 'yaml: line ' . ( $line // 1 ) . ": $what" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$line // 1
MC/DC0%0/1
$line // 1
$line
Truth table0%0/2
A
A= $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $s and $s =~ /\A(?:\d+(?:ms|s|m|h|d|w|y))+\z/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 39 | ▶ | return ( undef, ["$path: yaml: unmarshal errors: groups missing"] ) unless ref $d eq 'HASH' && ref $d->{groups} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $d eq "HASH" and ref $$d{"groups"} eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
ref $g eq "HASH" and defined $$g{"name"} and length $$g{"name"}
ref $g eq "HASH" and defined $$g{"name"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 39 | ▶ | next unless ref $g eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 39 | ▶ | push @e, "$path: $g->{name}: repeated in the same file" if defined $g->{name} && $gn{ $g->{name} }++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $$g{"name"} and $gn{$$g{"name"}}++
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"}}++
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 39 | ▶ | for my $r ( @{ $g->{rules} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$g{'rules'} || []
MC/DC0%0/1
$$g{'rules'} || []
$$g{'rules'}
Truth table50%1/2
A
A= $$g{'rules'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ( ref $r ne 'HASH' ) { push @e, "$path: rule is not a map"; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $$r{"alert"} or defined $$r{"record"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $$r{"expr"} and length $$r{"expr"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 39 | ▶ | if ( defined $r->{expr} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/5
($$r{"alert"} // $$r{"record"}) // ""
$$r{"alert"} // $$r{"record"}
MC/DC0%0/2
($$r{"alert"} // $$r{"record"}) // ""
$$r{"alert"}
$$r{"record"}
Truth table0%0/3
A // B
A= $$r{"alert"}B= $$r{"record"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $$r{"for"} and not $$r{"for"} =~ /\A\d+(?:ms|s|m|h|d|w|y)\z/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 48 | my ( $d, $ye ) = _yaml($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 48 | ▶ | return ( ["parsing YAML file $path: $ye"], {} ) if $ye; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 48 | ▶ | return ( ["parsing YAML file $path: yaml: unmarshal errors: config is not a map"], {} ) unless ref $d eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 48 | ▶ | my $gi = _dur( $g->{scrape_interval} // '1m' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$g{"scrape_interval"} // "1m"
MC/DC0%0/1
$$g{"scrape_interval"} // "1m"
$$g{"scrape_interval"}
Truth table50%1/2
A
A= $$g{"scrape_interval"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 48 | ▶ | my $gt = _dur( $g->{scrape_timeout} // '10s' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$g{"scrape_timeout"} // "10s"
MC/DC0%0/1
$$g{"scrape_timeout"} // "10s"
$$g{"scrape_timeout"}
Truth table50%1/2
A
A= $$g{"scrape_timeout"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 48 | ▶ | for my $sc ( @{ $d->{scrape_configs} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$d{'scrape_configs'} || []
MC/DC0%0/1
$$d{'scrape_configs'} || []
$$d{'scrape_configs'}
Truth table50%1/2
A
A= $$d{'scrape_configs'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 61 | ▶ | my $j = ref $sc eq 'HASH' ? $sc->{job_name} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( !defined $j || !length $j ) { push @e, "parsing YAML file $path: job_name is empty"; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $j and length $j
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 61 | ▶ | push @e, "parsing YAML file $path: found multiple scrape configs with job name \"$j\"" if $jobs{$j}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 61 | ▶ | my $iv = defined $sc->{scrape_interval} ? _dur( $sc->{scrape_interval} ) : $gi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 61 | ▶ | my $to = defined $sc->{scrape_timeout} ? _dur( $sc->{scrape_timeout} ) : ( $gt > $iv ? $iv : $gt ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $$sc{$k} and not defined _dur($$sc{$k})
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})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
defined $iv and defined $to and $to > $iv
defined $iv and defined $to
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | if defined $iv && defined $to && $to > $iv; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 61 | ▶ | for my $s ( @{ $sc->{static_configs} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$sc{'static_configs'} || []
MC/DC100%1/1
$$sc{'static_configs'} || []
$$sc{'static_configs'}
Truth table100%2/2
A
A= $$sc{'static_configs'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 60 | ▶ | for my $t ( @{ ( ref $s eq 'HASH' ? $s->{targets} : undef ) || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
(ref $s eq 'HASH' ? $$s{'targets'} : undef) || []
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $t and $t =~ /\A[\w.\-\[\]:]+:\d+\z/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 48 | my ( %rules, $nr ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 48 | ▶ | for my $pat ( @{ $d->{rule_files} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$d{'rule_files'} || []
MC/DC100%1/1
$$d{'rule_files'} || []
$$d{'rule_files'}
Truth table100%2/2
A
A= $$d{'rule_files'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 34 | $rules{$f} = $t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 34 | $nr += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 48 | ▶ | return ( \@e, \%rules, $nr // 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$nr // 0
MC/DC100%1/1
$nr // 0
$nr
Truth table100%2/2
A
A= $nr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 22 | ▶ | return ['no route provided in config'] unless ref $d eq 'HASH' && ref $d->{route} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $d eq "HASH" and ref $$d{"route"} eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 22 | ▶ | my %recv = map { ( ref $_ eq 'HASH' ? $_->{name} // '' : '' ) => 1 } @{ $d->{receivers} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$$_{"name"} // ""
$$d{'receivers'} || []
MC/DC0%0/1
$$_{"name"} // ""
$$_{"name"}
MC/DC0%0/1
$$d{'receivers'} || []
$$d{'receivers'}
Truth table50%1/2
A
A= $$_{"name"}
Truth table50%1/2
A
A= $$d{'receivers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'} || []
MC/DC100%1/1
$$r{'routes'} || []
$$r{'routes'}
Truth table100%2/2
A
A= $$r{'routes'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 57 | my $ts = 'ts=2026-10-24T09:12:03.000Z'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 57 | ▶ | if ( $kind eq 'prometheus' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 42 | return ( [], $rules ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 13 | ▶ | if ( $kind eq 'alertmanager' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // ""
$$dev{'services'} || {}
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"}
Truth table50%1/2
A
A= $$dev{'services'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 29 | ▶ | return ( '', 0 ) unless $svc && $svc->{active}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$svc and $$svc{"active"}
MC/DC50%1/2
$svc and $$svc{"active"}
$svc
$$svc{"active"}
Truth table66%2/3
A and B
A= $svcB= $$svc{"active"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 28 | ▶ | my $run_cfg = ref $svc->{running} eq 'HASH' ? $svc->{running} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 28 | ▶ | my $main = $svc->{config_main} // ( ref $svc->{config} ? $svc->{config}[0] : $svc->{config} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 28 | my %qs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 28 | ▶ | if ( $path =~ s/\?(.*)//s ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
$_ // ""
MC/DC0%0/1
$_ // ""
$_
Truth table50%1/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 21 | ▶ | return ( 'Prometheus Server is Healthy.', 200 ) if $path eq '/-/healthy'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 20 | ▶ | return ( 'Prometheus Server is Ready.', 200 ) if $path eq '/-/ready'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 20 | ▶ | if ( $path eq '/api/v1/targets' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | ▶ | my $t = _prom_targets( $dev, $svc, $run_cfg, $main, $probe ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | my @want = grep { ( $qs{state} // 'any' ) =~ /\A(?:any|active)\z/ } @$t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$qs{"state"} // "any"
MC/DC0%0/1
$qs{"state"} // "any"
$qs{"state"}
Truth table50%1/2
A
A= $qs{"state"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | return ( $js->( { activeTargets => \@want, droppedTargets => [], droppedTargetCounts => {} } ), 200 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 18 | ▶ | if ( $path eq '/api/v1/query' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $qs{"query"} and $qs{"query"} =~ /\S/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | ▶ | my $r = _prom_query( $dev, $svc, $run_cfg, $main, $probe, $qs{query} ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 6 | return ( $js->( { resultType => 'vector', result => $r } ), 200 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | ▶ | if ( $path eq '/-/reload' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | ▶ | return ( 'Only POST or PUT requests allowed', 405 ) if $method ne 'POST'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 2 | ▶ | my $args = join ' ', map { $run_cfg->{$_} // '' } grep { m{\A/etc/default/} } keys %$run_cfg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$run_cfg{$_} // ""
MC/DC0%0/1
$$run_cfg{$_} // ""
$$run_cfg{$_}
Truth table50%1/2
A
A= $$run_cfg{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | ▶ | return ( 'Lifecycle API is not enabled.', 403 ) unless $args =~ /--web\.enable-lifecycle/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | my ( $o, $ok ) = $run->("systemctl reload $name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | return ( $ok ? '' : "failed to reload config: $o", $ok ? 200 : 500 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 6 | ▶ | return ( $js->( { yaml => $run_cfg->{$main} // '' } ), 200 ) if $path eq '/api/v1/status/config'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$run_cfg{$main} // ""
MC/DC0%0/1
$$run_cfg{$main} // ""
$$run_cfg{$main}
Truth table50%1/2
A
A= $$run_cfg{$main}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | ▶ | return ( $js->( _prom_flags($run_cfg) ), 200 ) if $path eq '/api/v1/status/flags'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | ▶ | return ( $js->( { alerts => [] } ), 200 ) if $path eq '/api/v1/alerts'; # Regeln stehen auf inactive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | ▶ | if ( $path eq '/api/v1/rules' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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/]
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/]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | my ($d) = _yaml( $run_cfg->{$f} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | ▶ | for my $g ( @{ ( ref $d eq 'HASH' ? $d->{groups} : undef ) || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
(ref $d eq 'HASH' ? $$d{'groups'} : undef) || []
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | my @r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | ▶ | for my $x ( grep { ref $_ eq 'HASH' } @{ $g->{rules} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$g{'rules'} || []
MC/DC0%0/1
$$g{'rules'} || []
$$g{'rules'}
Truth table50%1/2
A
A= $$g{'rules'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | my %r = ( name => $x->{alert} // $x->{record}, query => $x->{expr}, health => 'ok', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | ▶ | type => defined $x->{alert} ? 'alerting' : 'recording' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$x{"alert"} // $$x{"record"}
MC/DC0%0/2
$$x{"alert"} // $$x{"record"}
$$x{"alert"}
$$x{"record"}
Truth table33%1/3
A // B
A= $$x{"alert"}B= $$x{"record"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%4/8
_dur($$x{"for"} // "0s") // 0
$$x{"for"} // "0s"
$$x{"labels"} // {}
$$x{"annotations"} // {}
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")
Truth table50%1/2
A
A= $$x{"for"}
Truth table50%1/2
A
A= $$x{"labels"}
Truth table50%1/2
A
A= $$x{"annotations"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$path eq "/-/healthy" or $path eq "/-/ready"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | ▶ | if ( $path eq '/-/reload' ) { # bei Alertmanager immer offen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | return ( 'Only POST requests allowed', 405 ) if $method ne 'POST'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my ( $o, $ok ) = $run->("systemctl reload $name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | return ( $ok ? '' : "failed to reload config: $o", $ok ? 200 : 500 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | return ( $raw->( { config => { original => $run_cfg->{$main} // '' }, cluster => { status => 'disabled' } } ), 200 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$run_cfg{$main} // ""
MC/DC0%0/1
$$run_cfg{$main} // ""
$$run_cfg{$main}
Truth table0%0/2
A
A= $$run_cfg{$main}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | ▶ | if ( $path eq '/api/v2/receivers' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | ▶ | my ($d) = _yaml( $run_cfg->{$main} // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$run_cfg{$main} // ""
MC/DC0%0/1
$$run_cfg{$main} // ""
$$run_cfg{$main}
Truth table50%1/2
A
A= $$run_cfg{$main}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | ▶ | return ( $raw->( [ map { { name => $_->{name} } } grep { ref $_ eq 'HASH' } @{ ( ref $d eq 'HASH' ? $d->{receivers} : undef ) || [] } ] ), 200 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
(ref $d eq 'HASH' ? $$d{'receivers'} : undef) || []
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 5 | my $now = now_epoch($dev); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | ▶ | my $sil = $svc->{silences} || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$svc{'silences'} || []
MC/DC100%1/1
$$svc{'silences'} || []
$$svc{'silences'}
Truth table100%2/2
A
A= $$svc{'silences'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 5 | $_ = _am_silence_view( $svc, $_, $now ) for @$sil; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 5 | ▶ | if ( $path eq '/api/v2/silences' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$$s{'_matchers'} || []
MC/DC0%0/1
$$s{'_matchers'} || []
$$s{'_matchers'}
Truth table50%1/2
A
A= $$s{'_matchers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } @$sil; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | return ( $raw->( \@l ), 200 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | ▶ | if ( $path eq '/api/v2/alerts' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | ▶ | my $t = $svc->{alert_targets} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$svc{'alert_targets'} || {}
MC/DC0%0/1
$$svc{'alert_targets'} || {}
$$svc{'alert_targets'}
Truth table50%1/2
A
A= $$svc{'alert_targets'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | my @l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | ▶ | for my $a ( @{ $svc->{alerts} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$svc{'alerts'} || []
MC/DC0%0/1
$$svc{'alerts'} || []
$$svc{'alerts'}
Truth table50%1/2
A
A= $$svc{'alerts'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | ▶ | my $lab = { %{ $t->{ $a->{target} // '' } || {} }, alertname => $a->{alertname} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$$t{$$a{'target'} // ''} || {}
$$a{"target"} // ""
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'} // ''}
Truth table50%1/2
A
A= $$a{"target"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | ▶ | next if @by && ( $qs{silenced} // 'true' ) eq 'false'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
@by and ($qs{"silenced"} // "true") eq "false"
$qs{"silenced"} // "true"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | my ( $slug, $ok ) = _amtool_routes( $dev, [ 'test', map {"$_=$lab->{$_}"} sort keys %$lab ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | ▶ | return unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$$a{"since"} // "2026-10-24 06:58:12 UTC"
$$a{"since"}
Truth table50%1/2
A
A= $$a{"since"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 5 | ▶ | my ($d) = _yaml( $run_cfg->{$main} // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$run_cfg{$main} // ""
MC/DC0%0/1
$$run_cfg{$main} // ""
$$run_cfg{$main}
Truth table50%1/2
A
A= $$run_cfg{$main}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 5 | ▶ | return unless ref $d eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 5 | ▶ | my $g = ref $d->{global} eq 'HASH' ? $d->{global} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'} || []
MC/DC0%0/1
$$d{'scrape_configs'} || []
$$d{'scrape_configs'}
Truth table50%1/2
A
A= $$d{'scrape_configs'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 9 | ▶ | return if grep { /_sd_configs\z|\Arelabel_configs\z/ } keys %$sc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 9 | ▶ | my $job = $sc->{job_name} // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$sc{"job_name"} // (return)
MC/DC0%0/1
$$sc{"job_name"} // (return)
$$sc{"job_name"}
Truth table50%1/2
A
A= $$sc{"job_name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 9 | ▶ | my $scheme = $sc->{scheme} // 'http'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$sc{"scheme"} // "http"
MC/DC0%0/1
$$sc{"scheme"} // "http"
$$sc{"scheme"}
Truth table50%1/2
A
A= $$sc{"scheme"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 9 | ▶ | my $mpath = $sc->{metrics_path} // '/metrics'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$sc{"metrics_path"} // "/metrics"
MC/DC0%0/1
$$sc{"metrics_path"} // "/metrics"
$$sc{"metrics_path"}
Truth table50%1/2
A
A= $$sc{"metrics_path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 9 | ▶ | my $int = $sc->{scrape_interval} // $g->{scrape_interval} // '1m'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
($$sc{"scrape_interval"} // $$g{"scrape_interval"}) // "1m"
$$sc{"scrape_interval"} // $$g{"scrape_interval"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 9 | ▶ | my $to = $sc->{scrape_timeout} // $g->{scrape_timeout} // '10s'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
($$sc{"scrape_timeout"} // $$g{"scrape_timeout"}) // "10s"
$$sc{"scrape_timeout"} // $$g{"scrape_timeout"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 9 | ▶ | for my $s ( grep { ref $_ eq 'HASH' } @{ $sc->{static_configs} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$sc{'static_configs'} || []
MC/DC0%0/1
$$sc{'static_configs'} || []
$$sc{'static_configs'}
Truth table50%1/2
A
A= $$sc{'static_configs'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 9 | ▶ | for my $inst ( @{ $s->{targets} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$s{'targets'} || []
MC/DC0%0/1
$$s{'targets'} || []
$$s{'targets'}
Truth table50%1/2
A
A= $$s{'targets'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 14 | ▶ | my ( $h, $p ) = $inst =~ /\A\[?([^\]\s]+?)\]?:(\d+)\z/ or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 14 | ▶ | return unless defined $st; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 13 | ▶ | my %lab = ( %{ ref $s->{labels} eq 'HASH' ? $s->{labels} : {} }, instance => $inst, job => $job ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 13 | ▶ | push @t, { discoveredLabels => { __address__ => $inst, __metrics_path__ => $mpath, __scheme__ => $scheme, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 7 | my @m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 7 | ▶ | if ( defined $sel ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | ▶ | return if $rest =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 7 | ▶ | push @m, { name => '__name__', op => '=', value => $name } if defined $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 7 | ▶ | my ($nm) = map { $_->{value} } grep { $_->{name} eq '__name__' && $_->{op} eq '=' } @m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$$_{'name'} eq '__name__' && $$_{'op'} eq '='
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 '='
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 7 | ▶ | return unless defined $nm; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 7 | my @series; # [ labels, wert ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 7 | ▶ | if ( $nm eq 'up' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 3 | ▶ | my $t = _prom_targets( $dev, $svc, $run_cfg, $main, $probe ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | ▶ | @series = map { [ { %{ $_->{labels} }, __name__ => 'up' }, $_->{health} eq 'up' ? 1 : 0 ] } @$t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | elsif ( $nm =~ /\AALERTS(?:_FOR_STATE)?\z/ ) { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 3 | ▶ | return unless defined $svc->{metrics}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | for my $line ( split /\n/, $svc->{metrics} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 6 | ▶ | next if $line =~ /\A\s*(?:#|\z)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 3 | ▶ | my ( $n, $l, $v ) = $line =~ /\A\s*([a-zA-Z_:][\w:]*)\s*(?:\{(.*)\})?\s+(\S+)\s*\z/ or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 3 | my %lab = ( __name__ => $n ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 3 | ▶ | $lab{$1} = $2 while ( $l // '' ) =~ /([A-Za-z_]\w*)\s*=\s*"((?:[^"\\]|\\.)*)"/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$l // ""
MC/DC0%0/1
$l // ""
$l
Truth table50%1/2
A
A= $l
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 9 | ▶ | my $v = $age ? $now - $s->[1] : $s->[1]; # time() - x: Alter, ohne Namen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 9 | ▶ | next if defined $cmp && !$op{$cmp}->( $v, $num ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cmp and not $op{$cmp}($v, $num)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 8 | my %lab = %{ $s->[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 8 | ▶ | delete $lab{__name__} if $age; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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} // ""
MC/DC0%0/1
$$run_cfg{$file} // ""
$$run_cfg{$file}
Truth table50%1/2
A
A= $$run_cfg{$file}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 3 | ▶ | next unless $line =~ /\A\s*ARGS=(.*)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 4 | ▶ | next unless $w =~ /\A--?(?:no-)?([\w.\-]+)(?:=(.*))?\z/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 4 | my ( $k, $v ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | if ( $w =~ /\A--?no-/ ) { $f{$k} = 'false'; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 4 | ▶ | $v //= @w && $w[0] !~ /\A-/ && ( $f{$k} // '' ) !~ /\A(?:true|false)\z/ ? shift @w : 'true'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition45%5/11
$v //= @w && !($w[0] =~ /\A-/) && !(($f{$k} // "") =~ /\A(?:true|false)\z/) ? shift @w : "true"
@w and not $w[0] =~ /\A-/ and not +($f{$k} // "") =~ /\A(?:true|false)\z/
@w and not $w[0] =~ /\A-/
$f{$k} // ""
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition42%3/7
($cmd // "") ne "check" or not +($what // "") =~ /\A(?:config|rules)\z/
$cmd // ""
$what // ""
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | my ( $n, $e ) = _check_rules( $f, $t ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | ▶ | if ($e) { push @out, ' FAILED:', @$e, ''; $ok = 0; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | push @out, " SUCCESS: $n rules found", ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 5 | ▶ | pop @out while @out && $out[-1] eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@out and $out[-1] eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | $eff{group_by} = join( ',', @{ $r->{group_by} } ) if ref $r->{group_by} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 27 | my %copy = %eff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 27 | ▶ | $out{ $eff{receiver} } //= \%copy if defined $eff{receiver}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$out{$eff{"receiver"}} //= \%copy
MC/DC0%0/1
$out{$eff{"receiver"}} //= \%copy
$out{$eff{"receiver"}}
Truth table50%1/2
A
A= $out{$eff{"receiver"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 27 | ▶ | $walk->( $_, \%eff ) for @{ $r->{routes} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$r{'routes'} || []
MC/DC100%1/1
$$r{'routes'} || []
$$r{'routes'}
Truth table100%2/2
A
A= $$r{'routes'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 13 | ▶ | $walk->( ref $d eq 'HASH' ? $d->{route} : undef, {%AM_ROUTE_DEFAULT} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$$dev{"clock"} // "Oct 20 09:12"
$$dev{"clock"}
Truth table50%1/2
A
A= $$dev{"clock"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$$dev{"tz"} // "+02:00"
MC/DC100%1/1
$$dev{"tz"} // "+02:00"
$$dev{"tz"}
Truth table100%2/2
A
A= $$dev{"tz"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 44 | ▶ | return ( $sg eq '-' ? -1 : 1 ) * ( $h * 3600 + $m * 60 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$t // ""
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $d and $d =~ /\A(?:\d+(?:\.\d+)?(?:h|m|s|ms))+\z/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}} // ""
MC/DC100%1/1
$$labels{$$m{"name"}} // ""
$$labels{$$m{"name"}}
Truth table100%2/2
A
A= $$labels{$$m{"name"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 60 | ▶ | my $hit = $m->{op} =~ /~/ ? ( eval { $have =~ /\A(?:$m->{value})\z/ } // 0 ) : $have eq $m->{value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
eval {
do {
$have =~ /\A(?:$$m{"value"})\z/
}
} // 0
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/
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 60 | ▶ | $hit = !$hit if $m->{op} =~ /\A!/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 60 | ▶ | return 0 unless $hit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'} || {}
MC/DC0%0/1
$$svc{'alert_targets'} || {}
$$svc{'alert_targets'}
Truth table50%1/2
A
A= $$svc{'alert_targets'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$$sil{"_expired"} or $$sil{"_end"} <= $now
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // ""
$$dev{'services'} || {}
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"}
Truth table50%1/2
A
A= $$dev{'services'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 10 | ▶ | return defined $n ? $dev->{services}{$n} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 21 | my $x = shift @a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 21 | ▶ | if ( $x =~ /\A--([\w.-]+)=(.*)\z/s ) { $opt{$1} = $2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")) // ""
_file_text($dev, "/etc/amtool/config.yml") // _file_text($dev, "/root/.config/amtool/config.yml")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$svc and $$svc{"active"} and $url =~ m(\Ahttps?://(?:localhost|127\.0\.0\.1|\[::1\])?(?::9093)?/?\z)
$svc and $$svc{"active"}
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 6 | my $now = now_epoch($dev); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 6 | ▶ | my $sil = $svc->{silences} //= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$svc{"silences"} //= []
MC/DC100%1/1
$$svc{"silences"} //= []
$$svc{"silences"}
Truth table100%2/2
A
A= $$svc{"silences"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 6 | $_ = _am_silence_view( $svc, $_, $now ) for @$sil; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 6 | ▶ | if ( $sub eq 'add' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
_am_matcher($p) // ($p =~ /\A[\w:.-]+\z/ ? {"name", "alertname", "op", "=", "value", $p} : undef)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 5 | ▶ | return ( qq{amtool: error: bad matcher format: $p}, 0 ) unless $m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 5 | push @m, $m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 4 | ▶ | return ( 'amtool: error: no matchers specified', 0 ) unless @m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 4 | ▶ | return ( 'amtool: error: comment required by config', 0 ) unless defined $opt{comment} && length $opt{comment}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opt{"comment"} and length $opt{"comment"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 3 | ▶ | my $start = defined $opt{start} ? _rfc3339( $opt{start} ) : $now; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 3 | my $end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 3 | ▶ | if ( defined $opt{end} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
$opt{"duration"} // "1h"
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")
Truth table50%1/2
A
A= $opt{"duration"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 2 | $end = $start + $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 3 | ▶ | return ( 'amtool: error: silence cannot end before it starts', 0 ) if $end <= $start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 3 | ▶ | return ( 'amtool: error: silence cannot end in the past', 0 ) if $end <= $now; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$opt{"author"} // "root"
$opt{"author"}
Truth table50%1/2
A
A= $opt{"author"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$sub eq "query" or $sub eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | ▶ | my @l = grep { $opt{expired} ? $_->{state} eq 'expired' : $_->{state} ne 'expired' } @$sil; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | return ( join( "\n", map { $_->{id} } @l ), 1 ) if $opt{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | ▶ | return ( 'amtool: error: no silence IDs specified', 0 ) unless @pos; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 25 | my $x = shift @a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 25 | ▶ | if ( $x =~ /\A--config\.file=(.*)\z/ ) { $file = $1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 1 | ▶ | elsif ( $x eq '--config.file' ) { $file = shift(@a) // return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @a // (return)
MC/DC0%0/1
shift @a // (return)
shift @a
Truth table50%1/2
A
A= shift @a
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
shift @a // (return)
shift @a
Truth table0%0/2
A
A= shift @a
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
@pos and $pos[0] =~ /\A(?:show|test)\z/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 8 | ▶ | return if $sub eq 'show' && @pos; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sub eq "show" and @pos
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 8 | my $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 8 | ▶ | if ( defined $file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 2 | ▶ | my $svc = _am_svc($dev) or return ( 'amtool: error: required flag --alertmanager.url not provided', 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 2 | ▶ | return unless $svc->{active}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 2 | ▶ | my $main = $svc->{config_main} // ( ref $svc->{config} ? $svc->{config}[0] : $svc->{config} ) // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
($$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})) // (return)
$$svc{"config_main"} // (ref $$svc{"config"} ? $$svc{"config"}[0] : $$svc{"config"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 2 | ▶ | $text = ( ref $svc->{running} eq 'HASH' ? $svc->{running}{$main} : undef ) // _file_text( $dev, $main ) // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
((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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 8 | my $e = _am_check_text($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 8 | ▶ | return ( "amtool: error: $e->[0]", 0 ) if @$e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
_am_matcher($s) // (return)
MC/DC0%0/1
_am_matcher($s) // (return)
_am_matcher($s)
Truth table50%1/2
A
A= _am_matcher($s)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 24 | ▶ | push @m, map { { name => $_, op => '=', value => $r->{match}{$_} } } sort keys %{ ref $r->{match} eq 'HASH' ? $r->{match} : {} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'}
$$a{"name"} cmp $$b{"name"} or $$a{"value"} cmp $$b{"value"}
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}
$$r{'continue'} && "$$r{'continue'}" =~ /\A(?:1|true)\z/
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"}
Truth table66%2/3
A && B
A= $$r{'continue'}B= "$$r{'continue'}" =~ /\A(?:1|true)\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 24 | ▶ | for my $c ( grep { ref $_ eq 'HASH' } @{ $r->{routes} || [] } ) { push @{ $node->{kids} }, $route->( $c, $node ) // return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$$r{'routes'} || []
&$route($c, $node) // (return)
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'}
Truth table50%1/2
A
A= &$route($c, $node)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 24 | return $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 7 | ▶ | my $root = $route->( $d->{route}, {} ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 7 | ▶ | if ( $sub eq 'show' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 4 | ▶ | $slug .= ', continue: true' if $n->{continue}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 4 | ▶ | push @l, $pre . ( $last ? '└── ' : '├── ' ) . "$slug receiver: " . ( $n->{receiver} // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$n{"receiver"} // ""
MC/DC0%0/1
$$n{"receiver"} // ""
$$n{"receiver"}
Truth table50%1/2
A
A= $$n{"receiver"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 4 | ▶ | my @k = @{ $n->{kids} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$n{'kids'} || []
MC/DC100%1/1
$$n{'kids'} || []
$$n{'kids'}
Truth table100%2/2
A
A= $$n{'kids'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 4 | ▶ | $tree->( $k[$_], $pre . ( $last ? ' ' : '│ ' ), $_ == $#k ) for 0 .. $#k; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 11 | my @all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 11 | ▶ | for my $c ( @{ $n->{kids} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$n{'kids'} || []
MC/DC100%1/1
$$n{'kids'} || []
$$n{'kids'}
Truth table100%2/2
A
A= $$n{'kids'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 12 | my @hit = $match->($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 12 | push @all, @hit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 12 | ▶ | last if @hit && !$c->{continue}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@hit and not $$c{"continue"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 11 | ▶ | return @all ? @all : ($n); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 6 | ▶ | my $slug = join ',', map { $_->{receiver} // '' } $match->($root); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$_{"receiver"} // ""
MC/DC0%0/1
$$_{"receiver"} // ""
$$_{"receiver"}
Truth table50%1/2
A
A= $$_{"receiver"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 6 | ▶ | return ( "$slug\nWARNING: Expected receivers did not match resolved receivers.", 0 ) if defined $verify && length $verify && $verify ne $slug; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $verify and length $verify and $verify ne $slug
defined $verify and length $verify
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition57%4/7
($all[0] // "") eq "config" and ($all[1] // "") eq "routes"
$all[0] // ""
$all[1] // ""
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 6 | my @r = _amtool_routes( $dev, [ @all[ 2 .. $#all ] ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 6 | ▶ | return @r if @r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | push @GAPS, join( ' ', 'amtool', @$av ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | return ( '', 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 10 | ▶ | if ( ( $all[0] // '' ) eq 'silence' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$all[0] // ""
MC/DC0%0/1
$all[0] // ""
$all[0]
Truth table50%1/2
A
A= $all[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 7 | ▶ | my $sub = defined $all[1] && $all[1] !~ /\A-/ ? $all[1] : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $all[1] and not $all[1] =~ /\A-/
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-/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 7 | ▶ | return _amtool_silence( $dev, $sub, [ @all[ ( $sub eq '' ? 1 : 2 ) .. $#all ] ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 3 | ▶ | if ( ( $all[0] // '' ) eq 'alert' && ( ( $all[1] // 'query' ) eq 'query' || $all[1] =~ /\A-/ ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%5/10
($all[0] // "") eq "alert" and ($all[1] // "query") eq "query" || $all[1] =~ /\A-/
$all[0] // ""
($all[1] // "query") eq "query" or $all[1] =~ /\A-/
$all[1] // "query"
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-/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 2 | ▶ | my $svc = _am_svc($dev) or return ( 'amtool: error: required flag --alertmanager.url not provided', 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 2 | my $now = now_epoch($dev); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 2 | ▶ | my $sil = $svc->{silences} || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$svc{'silences'} || []
MC/DC0%0/1
$$svc{'silences'} || []
$$svc{'silences'}
Truth table50%1/2
A
A= $$svc{'silences'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 2 | $_ = _am_silence_view( $svc, $_, $now ) for @$sil; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 2 | ▶ | my $t = $svc->{alert_targets} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$svc{'alert_targets'} || {}
MC/DC0%0/1
$$svc{'alert_targets'} || {}
$$svc{'alert_targets'}
Truth table50%1/2
A
A= $$svc{'alert_targets'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 2 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 2 | ▶ | for my $a ( @{ $svc->{alerts} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$svc{'alerts'} || []
MC/DC0%0/1
$$svc{'alerts'} || []
$$svc{'alerts'}
Truth table50%1/2
A
A= $$svc{'alerts'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 4 | ▶ | my $lab = { %{ $t->{ $a->{target} // '' } || {} }, alertname => $a->{alertname} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$$t{$$a{'target'} // ''} || {}
$$a{"target"} // ""
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'} // ''}
Truth table50%1/2
A
A= $$a{"target"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 4 | ▶ | next if grep { $_->{state} eq 'active' && _am_matches( $_->{_matchers}, $lab ) } @$sil; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$$_{'state'} eq 'active' && _am_matches($$_{'_matchers'}, $lab)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
$$a{"summary"} // ""
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"}
Truth table50%1/2
A
A= $$a{"summary"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$cmd // ""
MC/DC0%0/1
$cmd // ""
$cmd
Truth table50%1/2
A
A= $cmd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'} || []
MC/DC0%0/1
$$d{'inhibit_rules'} || []
$$d{'inhibit_rules'}
Truth table0%0/2
A
A= $$d{'inhibit_rules'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | ' - ' . scalar( @{ $d->{receivers} || [] } ) . ' receivers', ' - 0 templates', ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$d{'receivers'} || []
MC/DC0%0/1
$$d{'receivers'} || []
$$d{'receivers'}
Truth table0%0/2
A
A= $$d{'receivers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 1 | ▶ | pop @out while @out && $out[-1] eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@out and $out[-1] eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 1 | return ( join( "\n", @out ), $ok ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||