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