Fix #1536
This commit is contained in:
parent
6ee8d3437d
commit
33ff112c4a
|
@ -37,14 +37,14 @@ sub new {
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$self->{version} = '1.0';
|
$self->{version} = '1.0';
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'ntp-hostname:s' => { name => 'ntp_hostname' },
|
||||||
"ntp-hostname:s" => { name => 'ntp_hostname' },
|
'ntp-port:s' => { name => 'ntp_port', default => 123 },
|
||||||
"ntp-port:s" => { name => 'ntp_port', default => 123 },
|
'warning:s' => { name => 'warning' },
|
||||||
"warning:s" => { name => 'warning' },
|
'critical:s' => { name => 'critical' },
|
||||||
"critical:s" => { name => 'critical' },
|
'timeout:s' => { name => 'timeout', default => 30 },
|
||||||
"timeout:s" => { name => 'timeout', default => 30 },
|
});
|
||||||
});
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,12 +53,28 @@ sub check_options {
|
||||||
$self->SUPER::init(%options);
|
$self->SUPER::init(%options);
|
||||||
|
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_ntp_query {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my ($stdout) = centreon::plugins::misc::windows_execute(
|
||||||
|
output => $self->{output},
|
||||||
|
timeout => $self->{option_results}->{timeout},
|
||||||
|
command => 'w32tm /query /status',
|
||||||
|
command_path => undef,
|
||||||
|
command_options => undef,
|
||||||
|
no_quit => 1
|
||||||
|
);
|
||||||
|
if ($stdout =~ /^Source:\s+(\S+)/mi) {
|
||||||
|
return $1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,11 +83,13 @@ sub run {
|
||||||
|
|
||||||
my $ntp_hostname = $self->{option_results}->{ntp_hostname};
|
my $ntp_hostname = $self->{option_results}->{ntp_hostname};
|
||||||
if (!defined($ntp_hostname)) {
|
if (!defined($ntp_hostname)) {
|
||||||
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output},
|
my ($stdout) = centreon::plugins::misc::windows_execute(
|
||||||
timeout => $self->{option_results}->{timeout},
|
output => $self->{output},
|
||||||
command => 'w32tm /dumpreg /subkey:parameters',
|
timeout => $self->{option_results}->{timeout},
|
||||||
command_path => undef,
|
command => 'w32tm /dumpreg /subkey:parameters',
|
||||||
command_options => undef);
|
command_path => undef,
|
||||||
|
command_options => undef
|
||||||
|
);
|
||||||
my ($type, $ntp_server);
|
my ($type, $ntp_server);
|
||||||
$stdout =~ /^Type\s+\S+\s+(\S+)/mi;
|
$stdout =~ /^Type\s+\S+\s+(\S+)/mi;
|
||||||
$type = $1;
|
$type = $1;
|
||||||
|
@ -85,16 +103,19 @@ sub run {
|
||||||
# AllSync: The client synchronizes time from any available time source, including domain hierarchy and external time sources
|
# AllSync: The client synchronizes time from any available time source, including domain hierarchy and external time sources
|
||||||
if ($type =~ /NoSync/i) {
|
if ($type =~ /NoSync/i) {
|
||||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||||
short_msg => sprintf("No ntp configuration set. Please use --ntp-hostname or set windows ntp configuration."));
|
short_msg => sprintf('No ntp configuration set. Please use --ntp-hostname or set windows ntp configuration.'));
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
|
} elsif ($type =~ /NT5DS/i) {
|
||||||
|
$ntp_server = $self->check_ntp_query();
|
||||||
}
|
}
|
||||||
if (!defined($ntp_server)) {
|
if (!defined($ntp_server)) {
|
||||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||||
short_msg => sprintf("Cannot get ntp source configuration (it uses AD). Please use --ntp-hostname."));
|
short_msg => sprintf('Cannot get ntp source configuration. Please use --ntp-hostname.'));
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$ntp_hostname = $ntp_server;
|
$ntp_hostname = $ntp_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,13 +138,14 @@ sub run {
|
||||||
my $exit = $self->{perfdata}->threshold_check(value => $diff,
|
my $exit = $self->{perfdata}->threshold_check(value => $diff,
|
||||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(severity => $exit,
|
||||||
short_msg => sprintf("Time offset %.3f second(s)", $diff));
|
short_msg => sprintf('Time offset %.3f second(s)', $diff));
|
||||||
|
|
||||||
$self->{output}->perfdata_add(label => 'offset', unit => 's',
|
$self->{output}->perfdata_add(
|
||||||
value => sprintf("%.3f", $diff),
|
label => 'offset', unit => 's',
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
value => sprintf("%.3f", $diff),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||||
);
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||||
|
);
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
|
|
Loading…
Reference in New Issue