check_ntp.pl
changeset 4 60373f213ec0
parent 3 cae04ac746e1
equal deleted inserted replaced
3:cae04ac746e1 4:60373f213ec0
     1 #! /usr/bin/perl -w
     1 #! /usr/bin/perl -w
     2 
     2 
     3 #    Copyright (C) 2011  Christian Arnold
     3 #    Copyright (C) 2012  Christian Arnold
     4 #
     4 #
     5 #    This program is free software: you can redistribute it and/or modify
     5 #    This program is free software: you can redistribute it and/or modify
     6 #    it under the terms of the GNU General Public License as published by
     6 #    it under the terms of the GNU General Public License as published by
     7 #    the Free Software Foundation, either version 3 of the License, or
     7 #    the Free Software Foundation, either version 3 of the License, or
     8 #    (at your option) any later version.
     8 #    (at your option) any later version.
    35 sub get_time_delta($$);
    35 sub get_time_delta($$);
    36 sub report($$);
    36 sub report($$);
    37 sub version($$);
    37 sub version($$);
    38 
    38 
    39 my $ME      = basename $0;
    39 my $ME      = basename $0;
    40 my $VERSION = "2.2";
    40 my $VERSION = "2.3";
    41 
    41 
    42 my %opt = (
    42 my %opt = (
    43     host     => "de.pool.ntp.org",
    43     host     => "de.pool.ntp.org",
    44     port     => "ntp",
    44     port     => "ntp",
    45     warning  => 10,
    45     warning  => 10,
    81     my $r_time = $response{"Receive Timestamp"};
    81     my $r_time = $response{"Receive Timestamp"};
    82     my $delta  = $l_time - $r_time;
    82     my $delta  = $l_time - $r_time;
    83 
    83 
    84     my $rc = "OK";
    84     my $rc = "OK";
    85   SWITCH: {
    85   SWITCH: {
       
    86         $delta < -$opt{critical} and $rc = "CRITICAL", last;
    86         $delta < -$opt{warning}  and $rc = "WARNING",  last;
    87         $delta < -$opt{warning}  and $rc = "WARNING",  last;
    87         $delta < -$opt{critical} and $rc = "CRITICAL", last;
    88         $delta > $opt{critical}  and $rc = "CRITICAL", last;
    88         $delta > $opt{warning}   and $rc = "WARNING",  last;
    89         $delta > $opt{warning}   and $rc = "WARNING",  last;
    89         $delta > $opt{critical}  and $rc = "CRITICAL", last;
       
    90     }
    90     }
    91 
    91 
    92     $delta = sprintf "%.1fs", $delta;
    92     $delta = sprintf "%.1fs", $delta;
    93 
    93 
    94     return ( $delta, $rc );
    94     return ( $delta, $rc );
   104 sub version($$) {
   104 sub version($$) {
   105     my ( $progname, $version ) = @_;
   105     my ( $progname, $version ) = @_;
   106 
   106 
   107     print <<_VERSION;
   107     print <<_VERSION;
   108 $progname version $version
   108 $progname version $version
   109 Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support.
   109 Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support.
   110 
   110 
   111 $ME comes with ABSOLUTELY NO WARRANTY. This is free software,
   111 $ME comes with ABSOLUTELY NO WARRANTY. This is free software,
   112 and you are welcome to redistribute it under certain conditions.
   112 and you are welcome to redistribute it under certain conditions.
   113 See the GNU General Public Licence for details.
   113 See the GNU General Public Licence for details.
   114 _VERSION
   114 _VERSION
   168 
   168 
   169 This plugin compares the system time with the ntp server time.
   169 This plugin compares the system time with the ntp server time.
   170 
   170 
   171 =head1 VERSION
   171 =head1 VERSION
   172 
   172 
   173 This man page is current for version 2.2 of check_ntp.
   173 This man page is current for version 2.3 of check_ntp.
   174 
   174 
   175 =head1 AUTHOR
   175 =head1 AUTHOR
   176 
   176 
   177 Written by Christian Arnold L<arnold@schlittermann.de>
   177 Written by Christian Arnold L<arnold@schlittermann.de>
   178 
   178 
   179 =head1 COPYRIGHT
   179 =head1 COPYRIGHT
   180 
   180 
   181 Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support.
   181 Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support.
   182 This is free software, and you are welcome to redistribute it under certain conditions.
   182 This is free software, and you are welcome to redistribute it under certain conditions.
   183 See the GNU General Public Licence for details.
   183 See the GNU General Public Licence for details.
   184 
   184 
   185 =cut
   185 =cut