« blib/lib/Monitoring/Sneck/Checks/interface.pm
↑ Summary
blib/lib/Monitoring/Sneck/Checks/fail2ban.pm »
| 1 | package Monitoring::Sneck::Checks::time_sync; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 18 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 18 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 18 | ▶ | use parent 'Monitoring::Sneck::Checks::base'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | Monitoring::Sneck::Checks::time_sync - checks the local time daemon is synchronised, chrony, ntpd, or timesyncd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | Version 0.0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 18 | our $VERSION = '0.0.1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Where the tools are. Set by tests. Undef means the first of their PATHS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # that is there. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 18 | our $CHRONYC; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 18 | our @CHRONYC_PATHS = ( '/usr/bin/chronyc', '/usr/local/bin/chronyc', '/usr/sbin/chronyc' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 18 | our $NTPQ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 18 | our @NTPQ_PATHS = ( '/usr/bin/ntpq', '/usr/sbin/ntpq', '/usr/local/bin/ntpq', '/usr/local/sbin/ntpq' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 18 | our $TIMEDATECTL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 18 | our @TIMEDATECTL_PATHS = ( '/usr/bin/timedatectl', '/bin/timedatectl' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # Seconds from the NTP epoch, 1900, to the Unix one, 1970. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 18 | our $NTP_EPOCH_OFFSET = 2208988800; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | time_sync|perl:time_sync | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | time_sync_tight|perl:time_sync -w 0.01 -c 0.1 --since-warning 7200 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | time_sync_ntpd|perl:time_sync -d ntpd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | Asks the local time daemon if it is synchronised, how far off it is, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | and when it last updated the clock. Unlike | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | L<Monitoring::Sneck::Checks::ntp>, which asks a NTP server, this is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | about the daemon keeping this host's clock. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | - chrony :: Through chronyc -n -c tracking. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | - ntpd :: Through ntpq -n -c rv, for the reference ntpd and NTPsec. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | - timesyncd :: Through timedatectl show, which only says if the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | kernel's clock is synchronised, not the offset. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | Without --daemon, the first of chronyc, ntpq, and timedatectl that is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | there is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | - CRITICAL :: Not synchronised. The daemon not answering. The offset or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | time since the last update over their critical. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | - WARNING :: Synchronised only to the local clock, as with chrony's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | local stratum or ntpd's LOCAL(0). The offset or time since the last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | update over their warning. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | - UNKNOWN :: None of the tools being there. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | - -d, --daemon :: chrony, ntpd, or timesyncd, instead of looking for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | - -w, --warning :: Range for the offset, in seconds, either way. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | Default :: 0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | - -c, --critical :: Range for the offset, in seconds, either way. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | Default :: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | - --since-warning :: Range for the seconds since the last update. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | - --since-critical :: Range for the seconds since the last update. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 138 | ▶ | sub option_spec { return ( 'daemon|d=s', 'warning|w=s', 'critical|c=s', 'since-warning=s', 'since-critical=s' ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
option_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 138 | ▶ | sub defaults { return { warning => '0.1', critical => '1' } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 138 | ▶ | sub ranges { return ( 'warning', 'critical', 'since-warning', 'since-critical' ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ranges: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 138 | ▶ | sub validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 138 | my ( $self, $options ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | return ('--daemon must be chrony, ntpd, or timesyncd') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 138 | ▶ | if defined( $options->{daemon} ) && $options->{daemon} !~ /\A(?:chrony|ntpd|timesyncd)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $options->{"daemon"} and not $options->{"daemon"} =~ /\A(?:chrony|ntpd|timesyncd)\z/u
MC/DC100%2/2
defined $options->{"daemon"} and not $options->{"daemon"} =~ /\A(?:chrony|ntpd|timesyncd)\z/u
defined $options->{"daemon"}
not $options->{"daemon"} =~ /\A(?:chrony|ntpd|timesyncd)\z/u
Truth table100%3/3
A and not(B)
A= defined $options->{"daemon"}B= not $options->{"daemon"} =~ /\A(?:chrony|ntpd|timesyncd)\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 137 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | =head2 check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | Does the check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 137 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=19 SCAR=29.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 137 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # set one at a time, as in a list a slice of nothing found would be nothing, shifting what follows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 137 | my %tools; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $tools{chrony} = $CHRONYC // ( grep { -x $_ } @CHRONYC_PATHS )[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Monitoring::Sneck::Checks::time_sync::CHRONYC // (grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::CHRONYC_PATHS)[0]
MC/DC50%1/2
$Monitoring::Sneck::Checks::time_sync::CHRONYC // (grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::CHRONYC_PATHS)[0]
$Monitoring::Sneck::Checks::time_sync::CHRONYC
(grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::CHRONYC_PATHS)[0]
Truth table66%2/3
A // B
A= $Monitoring::Sneck::Checks::time_sync::CHRONYCB= (grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::CHRONYC_PATHS)[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $tools{ntpd} = $NTPQ // ( grep { -x $_ } @NTPQ_PATHS )[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Monitoring::Sneck::Checks::time_sync::NTPQ // (grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::NTPQ_PATHS)[0]
MC/DC50%1/2
$Monitoring::Sneck::Checks::time_sync::NTPQ // (grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::NTPQ_PATHS)[0]
$Monitoring::Sneck::Checks::time_sync::NTPQ
(grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::NTPQ_PATHS)[0]
Truth table66%2/3
A // B
A= $Monitoring::Sneck::Checks::time_sync::NTPQB= (grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::NTPQ_PATHS)[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $tools{timesyncd} = $TIMEDATECTL // ( grep { -x $_ } @TIMEDATECTL_PATHS )[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Monitoring::Sneck::Checks::time_sync::TIMEDATECTL // (grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::TIMEDATECTL_PATHS)[0]
MC/DC50%1/2
$Monitoring::Sneck::Checks::time_sync::TIMEDATECTL // (grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::TIMEDATECTL_PATHS)[0]
$Monitoring::Sneck::Checks::time_sync::TIMEDATECTL
(grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::TIMEDATECTL_PATHS)[0]
Truth table66%2/3
A // B
A= $Monitoring::Sneck::Checks::time_sync::TIMEDATECTLB= (grep {-x $_;} @Monitoring::Sneck::Checks::time_sync::TIMEDATECTL_PATHS)[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 137 | ▶ | my $daemon = $self->opt('daemon') // ( grep { defined( $tools{$_} ) } ( 'chrony', 'ntpd', 'timesyncd' ) )[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->opt("daemon") // (grep {defined $tools{$_};} "chrony", "ntpd", "timesyncd")[0]
MC/DC100%2/2
$self->opt("daemon") // (grep {defined $tools{$_};} "chrony", "ntpd", "timesyncd")[0]
$self->opt("daemon")
(grep {defined $tools{$_};} "chrony", "ntpd", "timesyncd")[0]
Truth table100%3/3
A // B
A= $self->opt("daemon")B= (grep {defined $tools{$_};} "chrony", "ntpd", "timesyncd")[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 137 | ▶ | return $self->finish( $self->UNKNOWN, 'none of chronyc, ntpq, or timedatectl found' ) if !defined($daemon); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 136 | my $tool = $tools{$daemon}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 136 | ▶ | return $self->finish( $self->UNKNOWN, 'no tool for ' . $daemon . ' found' ) if !defined($tool) || !-x $tool; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $tool and -x $tool
MC/DC50%1/2
defined $tool and -x $tool
defined $tool
-x $tool
Truth table66%2/3
A and B
A= defined $toolB= -x $tool
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 135 | ▶ | my $state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | = $daemon eq 'chrony' ? $self->chrony_state($tool) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | : $daemon eq 'ntpd' ? $self->ntpd_state($tool) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | : $self->timesyncd_state($tool); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | return $self->finish( $self->CRITICAL, $daemon . ' is not answering, ' . $state->{says} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 120 | ▶ | if !$state->{answering}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 107 | ▶ | if ( !$state->{synced} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 21 | my $message = $daemon . ' not synchronised'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 21 | ▶ | $message = $message . ', NTP is off' if $state->{ntp_off}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 21 | return $self->finish( $self->CRITICAL, $message ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 86 | my @codes = ( $self->OK ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 86 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 86 | ▶ | if ( $state->{local} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 11 | push( @codes, $self->WARNING ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 11 | push( @parts, $daemon . ' synchronised to the local clock' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | push( @parts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 75 | ▶ | $daemon . ' synchronised' . ( defined( $state->{reference} ) ? ' to ' . $state->{reference} : '' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 86 | ▶ | push( @parts, 'stratum ' . $state->{stratum} ) if defined( $state->{stratum} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 86 | ▶ | if ( defined( $state->{offset} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 81 | my $offset = abs( $state->{offset} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 81 | push( @codes, $self->threshold_status( $offset, $self->opt('warning'), $self->opt('critical') ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 81 | push( @parts, 'offset ' . sprintf( '%.6f', $state->{offset} ) . ' seconds' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 81 | $self->perfdata( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | label => 'offset', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | value => sprintf( '%.6f', $offset ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | uom => 's', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | warning => $self->opt('warning'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | critical => $self->opt('critical'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | min => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } ## end if ( defined( $state->{offset} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 86 | ▶ | if ( defined( $state->{updated} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 81 | my $since = time - int( $state->{updated} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 81 | ▶ | $since = 0 if $since < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 81 | push( @codes, $self->threshold_status( $since, $self->opt('since-warning'), $self->opt('since-critical') ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 81 | push( @parts, 'updated ' . $since . ' seconds ago' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 81 | $self->perfdata( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | label => 'since_update', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | value => $since, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | uom => 's', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | warning => $self->opt('since-warning'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | critical => $self->opt('since-critical'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | min => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } ## end if ( defined( $state->{updated} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 86 | return $self->finish( $self->worst(@codes), join( ', ', @parts ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } ## end sub check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | =head2 chrony_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | Asks chrony through chronyc -n -c tracking. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | - chronyc :: The path to chronyc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | Returns a hash ref of answering, 1 or 0, and if not, says, what went | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | wrong, else synced, 1 or 0, local, 1 if synchronised to the local | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | clock, reference, the server's address, stratum, offset, in seconds, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | and updated, the epoch of the last update, or undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | my $state = $check->chrony_state('/usr/bin/chronyc'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # { answering => 1, synced => 1, local => 0, reference => '192.0.2.123', stratum => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # offset => -0.000156213, updated => 1794200902.841540871 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 100 | ▶ | sub chrony_state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chrony_state: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 100 | my ( $self, $chronyc ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 100 | my ( $exit, $output ) = $self->run_command( $chronyc, '-n', '-c', 'tracking' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 92 | ▶ | my $first = ( grep { /\S/ } split( /\n/, $output ) )[0] // 'saying nothing'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
(grep {/\S/u;} split(/\n/u, $output, 0))[0] // "saying nothing"
MC/DC0%0/1
(grep {/\S/u;} split(/\n/u, $output, 0))[0] // "saying nothing"
(grep {/\S/u;} split(/\n/u, $output, 0))[0]
Truth table50%1/2
A
A= (grep {/\S/u;} split(/\n/u, $output, 0))[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # reference ID, address, stratum, reference time, system offset, ..., leap status | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 92 | my @fields = split( /,/, $first ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 92 | ▶ | return { answering => 0, says => $first } if $exit || @fields < 14 || $fields[2] !~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$exit or @fields < 14 or not $fields[2] =~ /\A[0-9]+\z/u
$exit or @fields < 14
MC/DC33%1/3
$exit or @fields < 14 or not $fields[2] =~ /\A[0-9]+\z/u
$exit
@fields < 14
not $fields[2] =~ /\A[0-9]+\z/u
Truth table50%2/4
A or B or not(C)
A= $exitB= @fields < 14C= not $fields[2] =~ /\A[0-9]+\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 84 | ▶ | answering => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$fields[13] ne "Not synchronised" and $fields[2] < 16
MC/DC50%1/2
$fields[13] ne "Not synchronised" and $fields[2] < 16
$fields[13] ne "Not synchronised"
$fields[2] < 16
Truth table66%2/3
A and B
A= $fields[13] ne "Not synchronised"B= $fields[2] < 16
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | synced => ( $fields[13] ne 'Not synchronised' && $fields[2] < 16 ) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | local => uc( $fields[0] ) eq '7F7F0101' ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | reference => $fields[1] ne '' ? $fields[1] : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | stratum => $fields[2], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | offset => $fields[4], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | updated => $fields[3] > 0 ? $fields[3] : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } ## end sub chrony_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | =head2 ntpd_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | Asks ntpd through ntpq -n -c rv. Returns the same as L</chrony_state>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | the offset turned from milliseconds to seconds. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | - ntpq :: The path to ntpq. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | my $state = $check->ntpd_state('/usr/bin/ntpq'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 24 | ▶ | sub ntpd_state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ntpd_state: called CC=12 SCAR=26.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 24 | my ( $self, $ntpq ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 24 | my ( $exit, $output ) = $self->run_command( $ntpq, '-n', '-c', 'rv' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 20 | my ($leap) = $output =~ /\bleap=([0-9]+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 20 | my ($stratum) = $output =~ /\bstratum=([0-9]+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 20 | ▶ | if ( $exit || !defined($leap) || !defined($stratum) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$exit or not defined $leap or not defined $stratum
$exit or not defined $leap
MC/DC33%1/3
$exit or not defined $leap or not defined $stratum
$exit
not defined $leap
not defined $stratum
Truth table50%2/4
A or not(B) or not(C)
A= $exitB= not defined $leapC= not defined $stratum
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 5 | ▶ | return { answering => 0, says => ( grep { /\S/ } split( /\n/, $output ) )[0] // 'saying nothing' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
(grep {/\S/u;} split(/\n/u, $output, 0))[0] // "saying nothing"
MC/DC0%0/1
(grep {/\S/u;} split(/\n/u, $output, 0))[0] // "saying nothing"
(grep {/\S/u;} split(/\n/u, $output, 0))[0]
Truth table50%1/2
A
A= (grep {/\S/u;} split(/\n/u, $output, 0))[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 15 | my ($offset) = $output =~ /\boffset=([-+]?[0-9.]+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 15 | my ($refid) = $output =~ /\brefid=([^,\s]+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 15 | my ($reftime) = $output =~ /\breftime=([0-9a-f]+)\./; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 15 | ▶ | answering => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition55%5/9
$leap ne 11 and $stratum < 16
defined $refid and $refid =~ /\A(?:LOCAL\(|127\.127\.1\.)/u
defined $reftime and hex $reftime
MC/DC50%1/2
$leap ne 11 and $stratum < 16
$leap ne 11
$stratum < 16
MC/DC0%0/2
defined $refid and $refid =~ /\A(?:LOCAL\(|127\.127\.1\.)/u
defined $refid
$refid =~ /\A(?:LOCAL\(|127\.127\.1\.)/u
MC/DC50%1/2
defined $reftime and hex $reftime
defined $reftime
hex $reftime
Truth table66%2/3
A and B
A= $leap ne 11B= $stratum < 16
Truth table33%1/3
A and B
A= defined $refidB= $refid =~ /\A(?:LOCAL\(|127\.127\.1\.)/u
Truth table66%2/3
A and B
A= defined $reftimeB= hex $reftime
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | synced => ( $leap ne '11' && $stratum < 16 ) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | local => ( defined($refid) && $refid =~ /\A(?:LOCAL\(|127\.127\.1\.)/ ) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | reference => $refid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | stratum => $stratum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | offset => defined($offset) ? $offset / 1000 : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | updated => ( defined($reftime) && hex($reftime) ) ? hex($reftime) - $NTP_EPOCH_OFFSET : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } ## end sub ntpd_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | =head2 timesyncd_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | Asks systemd through timedatectl show. Returns the same as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | L</chrony_state>, but with only answering, says, and synced, plus | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | ntp_off, 1 if NTP is turned off. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | - timedatectl :: The path to timedatectl. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | my $state = $check->timesyncd_state('/usr/bin/timedatectl'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # { answering => 1, synced => 1, ntp_off => 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 11 | ▶ | sub timesyncd_state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timesyncd_state: called CC=9 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 11 | my ( $self, $timedatectl ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 11 | my ( $exit, $output ) = $self->run_command( $timedatectl, 'show' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 8 | my %show; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 8 | foreach my $line ( split( /\n/, $output ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 56 | ▶ | $show{$1} = $2 if $line =~ /\A([^=]+)=(.*)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 8 | ▶ | if ( $exit || !defined( $show{NTPSynchronized} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$exit or not defined $show{"NTPSynchronized"}
MC/DC0%0/2
$exit or not defined $show{"NTPSynchronized"}
$exit
not defined $show{"NTPSynchronized"}
Truth table33%1/3
A or not(B)
A= $exitB= not defined $show{"NTPSynchronized"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | return { answering => 0, says => ( grep { /\S/ } split( /\n/, $output ) )[0] // 'saying nothing' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
(grep {/\S/u;} split(/\n/u, $output, 0))[0] // "saying nothing"
MC/DC0%0/1
(grep {/\S/u;} split(/\n/u, $output, 0))[0] // "saying nothing"
(grep {/\S/u;} split(/\n/u, $output, 0))[0]
Truth table0%0/2
A
A= (grep {/\S/u;} split(/\n/u, $output, 0))[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | answering => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | synced => $show{NTPSynchronized} eq 'yes' ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 8 | ▶ | ntp_off => ( $show{NTP} // '' ) eq 'no' ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$show{"NTP"} // ""
MC/DC0%0/1
$show{"NTP"} // ""
$show{"NTP"}
Truth table50%1/2
A
A= $show{"NTP"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } ## end sub timesyncd_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 18 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||