Code

Added -A/--dig-arguments to check_dig (#1889453/#1874041)
[nagiosplug.git] / plugins / check_ntp_peer.c
index 1c4702c8d8a8ec7f0b08b77f02b9bb1858da1add..753b7b25b0a964d3e7af78793e719cfc64a39e42 100644 (file)
@@ -1,49 +1,46 @@
-/******************************************************************************
-*
+/*****************************************************************************
+* 
 * Nagios check_ntp_peer plugin
-*
+* 
 * License: GPL
-* Copyright (c) 2006 sean finney <seanius@seanius.net>
-* Copyright (c) 2007 nagios-plugins team
-*
+* Copyright (c) 2006 Sean Finney <seanius@seanius.net>
+* Copyright (c) 2006-2008 Nagios Plugins Development Team
+* 
 * Last Modified: $Date$
-*
+* 
 * Description:
-*
+* 
 * This file contains the check_ntp_peer plugin
-*
-*  This plugin checks an NTP server independent of any commandline
-*  programs or external libraries.
-*
-*  Use this plugin to check the health of an NTP server. It supports
-*  checking the offset with the sync peer, the jitter and stratum. This
-*  plugin will not check the clock offset between the local host and NTP
-*  server; please use check_ntp_time for that purpose.
-*
-*
-* License Information:
-*
-* This program is free software; you can redistribute it and/or modify
+* 
+* This plugin checks an NTP server independent of any commandline
+* programs or external libraries.
+* 
+* Use this plugin to check the health of an NTP server. It supports
+* checking the offset with the sync peer, the jitter and stratum. This
+* plugin will not check the clock offset between the local host and NTP
+* server; please use check_ntp_time for that purpose.
+* 
+* 
+* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
+* the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
-*
+* 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
-*
+* 
 * You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+* 
+* $Id$
+* 
 *****************************************************************************/
 
 const char *progname = "check_ntp_peer";
 const char *revision = "$Revision$";
-const char *copyright = "2007";
+const char *copyright = "2006-2008";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
@@ -63,6 +60,7 @@ static short do_jitter=0;
 static char *jwarn="-1:5000";
 static char *jcrit="-1:10000";
 static int syncsource_found=0;
+static int li_alarm=0;
 
 int process_arguments (int, char **);
 thresholds *offset_thresholds = NULL;
@@ -264,8 +262,10 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
                /* Attempt to read the largest size packet possible */
                req.count=htons(MAX_CM_SIZE);
                DBG(printf("recieving READSTAT response"))
-               read(conn, &req, SIZEOF_NTPCM(req));
+               if(read(conn, &req, SIZEOF_NTPCM(req)) == -1)
+                       die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n");
                DBG(print_ntp_control_message(&req));
+               if (LI(req.flags) == LI_ALARM) li_alarm = 1;
                /* Each peer identifier is 4 bytes in the data section, which
                 * we represent as a ntp_assoc_status_pair datatype.
                 */
@@ -296,6 +296,10 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
                status = STATE_WARNING;
                if(verbose) printf("warning: no synchronization source found\n");
        }
+       if(li_alarm){
+               status = STATE_WARNING;
+               if(verbose) printf("warning: LI_ALARM bit is set\n");
+       }
 
 
        for (i = 0; i < npeers; i++){
@@ -544,6 +548,10 @@ int main(int argc, char *argv[]){
        double offset=0, jitter=0;
        char *result_line, *perfdata_line;
 
+       setlocale (LC_ALL, "");
+       bindtextdomain (PACKAGE, LOCALEDIR);
+       textdomain (PACKAGE);
+
        if (process_arguments (argc, argv) == ERROR)
                usage4 (_("Could not parse arguments"));
 
@@ -578,26 +586,28 @@ int main(int argc, char *argv[]){
 
        switch (result) {
                case STATE_CRITICAL :
-                       asprintf(&result_line, "NTP CRITICAL:");
+                       asprintf(&result_line, _("NTP CRITICAL:"));
                        break;
                case STATE_WARNING :
-                       asprintf(&result_line, "NTP WARNING:");
+                       asprintf(&result_line, _("NTP WARNING:"));
                        break;
                case STATE_OK :
-                       asprintf(&result_line, "NTP OK:");
+                       asprintf(&result_line, _("NTP OK:"));
                        break;
                default :
-                       asprintf(&result_line, "NTP UNKNOWN:");
+                       asprintf(&result_line, _("NTP UNKNOWN:"));
                        break;
        }
        if(!syncsource_found)
                asprintf(&result_line, "%s %s,", result_line, _("Server not synchronized"));
-
+       else if(li_alarm)
+               asprintf(&result_line, "%s %s,", result_line, _("Server has the LI_ALARM bit set"));
        if(offset_result == STATE_UNKNOWN){
                asprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
                asprintf(&perfdata_line, "");
        } else {
-               asprintf(&result_line, "%s Offset %.10g secs", result_line, offset);
+               asprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
                asprintf(&perfdata_line, "%s", perfd_offset(offset));
        }
        if (do_jitter) {
@@ -637,7 +647,7 @@ void print_help(void){
        printf ("    %s\n", _("Offset to result in critical status (seconds)"));
        printf (" %s\n", "-W, --warning=THRESHOLD");
        printf ("    %s\n", _("Warning threshold for stratum"));
-       printf (" %s\n", "-W, --critical=THRESHOLD");
+       printf (" %s\n", "-C, --critical=THRESHOLD");
        printf ("    %s\n", _("Critical threshold for stratum"));
        printf (" %s\n", "-j, --warning=THRESHOLD");
        printf ("    %s\n", _("Warning threshold for jitter"));
@@ -661,7 +671,7 @@ void print_help(void){
 
        printf("\n");
        printf("%s\n", _("Examples:"));
-       printf(" %s\n", _("Normal NTP server check:"));
+       printf(" %s\n", _("Simple NTP server check:"));
        printf("  %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1"));
        printf(" %s\n", _("Check jitter too, avoiding critical notifications if jitter isn't available"));
        printf(" %s\n", _("(See Notes above for more details on thresholds formats):"));