summaryrefslogtreecommitdiffstats
path: root/plugins/check_fping.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_fping.c')
-rw-r--r--plugins/check_fping.c107
1 files changed, 54 insertions, 53 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 0753cf3..7b8e764 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -1,35 +1,24 @@
1/****************************************************************************** 1/******************************************************************************
2* 2
3* CHECK_FPING.C 3 This program is free software; you can redistribute it and/or modify
4* 4 it under the terms of the GNU General Public License as published by
5* Program: Fping plugin for Nagios 5 the Free Software Foundation; either version 2 of the License, or
6* License: GPL 6 (at your option) any later version.
7* Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at) 7
8* $Id$ 8 This program is distributed in the hope that it will be useful,
9* 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10* Modifications: 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* 11 GNU General Public License for more details.
12* 08-24-1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at) 12
13* Intial Coding 13 You should have received a copy of the GNU General Public License
14* 09-11-1999 Karl DeBisschop (kdebiss@alum.mit.edu) 14 along with this program; if not, write to the Free Software
15* Change to spopen 15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16* Fix so that state unknown is returned by default 16
17* (formerly would give state ok if no fping specified)
18* Add server_name to output
19* Reformat to 80-character standard screen
20* 11-18-1999 Karl DeBisschop (kdebiss@alum.mit.edu)
21* set STATE_WARNING of stderr written or nonzero status returned
22*
23* Description:
24*
25* This plugin will use the /bin/fping command (from saint) to ping
26* the specified host for a fast check if the host is alive. Note that
27* it is necessary to set the suid flag on fping.
28******************************************************************************/ 17******************************************************************************/
29 18
30const char *progname = "check_fping"; 19const char *progname = "check_fping";
31const char *revision = "$Revision$"; 20const char *revision = "$Revision$";
32const char *copyright = "1999-2003"; 21const char *copyright = "2000-2003";
33const char *email = "nagiosplug-devel@lists.sourceforge.net"; 22const char *email = "nagiosplug-devel@lists.sourceforge.net";
34 23
35#include "common.h" 24#include "common.h"
@@ -37,13 +26,12 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
37#include "netutils.h" 26#include "netutils.h"
38#include "utils.h" 27#include "utils.h"
39 28
40#define PACKET_COUNT 1 29enum {
41#define PACKET_SIZE 56 30 PACKET_COUNT = 1,
42#define UNKNOWN_PACKET_LOSS 200 /* 200% */ 31 PACKET_SIZE = 56,
43#define UNKNOWN_TRIP_TIME -1.0 /* -1 seconds */ 32 PL = 0,
44 33 RTA = 1
45#define PL 0 34};
46#define RTA 1
47 35
48int textscan (char *buf); 36int textscan (char *buf);
49int process_arguments (int, char **); 37int process_arguments (int, char **);
@@ -52,13 +40,17 @@ void print_help (void);
52void print_usage (void); 40void print_usage (void);
53 41
54char *server_name = NULL; 42char *server_name = NULL;
55int cpl = UNKNOWN_PACKET_LOSS;
56int wpl = UNKNOWN_PACKET_LOSS;
57double crta = UNKNOWN_TRIP_TIME;
58double wrta = UNKNOWN_TRIP_TIME;
59int packet_size = PACKET_SIZE; 43int packet_size = PACKET_SIZE;
60int packet_count = PACKET_COUNT; 44int packet_count = PACKET_COUNT;
61int verbose = FALSE; 45int verbose = FALSE;
46int cpl;
47int wpl;
48double crta;
49double wrta;
50int cpl_p = FALSE;
51int wpl_p = FALSE;
52int crta_p = FALSE;
53int wrta_p = FALSE;
62 54
63int 55int
64main (int argc, char **argv) 56main (int argc, char **argv)
@@ -160,18 +152,21 @@ textscan (char *buf)
160 rtastr = 1 + index (rtastr, '/'); 152 rtastr = 1 + index (rtastr, '/');
161 loss = strtod (losstr, NULL); 153 loss = strtod (losstr, NULL);
162 rta = strtod (rtastr, NULL); 154 rta = strtod (rtastr, NULL);
163 if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl) 155 if (cpl_p == TRUE && loss > cpl)
164 status = STATE_CRITICAL; 156 status = STATE_CRITICAL;
165 else if (crta <= 0 && rta > crta) 157 else if (crta_p == TRUE && rta > crta)
166 status = STATE_CRITICAL; 158 status = STATE_CRITICAL;
167 else if (wpl != UNKNOWN_PACKET_LOSS && loss > wpl) 159 else if (wpl_p == TRUE && loss > wpl)
168 status = STATE_WARNING; 160 status = STATE_WARNING;
169 else if (wrta >= 0 && rta > wrta) 161 else if (wrta_p == TRUE && rta > wrta)
170 status = STATE_WARNING; 162 status = STATE_WARNING;
171 else 163 else
172 status = STATE_OK; 164 status = STATE_OK;
173 die (status, _("FPING %s - %s (loss=%f%%, rta=%f ms)\n"), 165 die (status,
174 state_text (status), server_name, loss, rta); 166 _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"),
167 state_text (status), server_name, loss, rta,
168 perfdata ("loss", (int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100),
169 perfdata ("rta", (long int)(rta*1.0e3), "us", wrta_p, (long int)(wrta*1.0e3), crta_p, (long int)(crta*1.0e3), TRUE, 0, FALSE, 0));
175 170
176 } 171 }
177 else if(strstr (buf, "xmt/rcv/%loss") ) { 172 else if(strstr (buf, "xmt/rcv/%loss") ) {
@@ -182,15 +177,16 @@ textscan (char *buf)
182 loss = strtod (losstr, NULL); 177 loss = strtod (losstr, NULL);
183 if (atoi(losstr) == 100) 178 if (atoi(losstr) == 100)
184 status = STATE_CRITICAL; 179 status = STATE_CRITICAL;
185 else if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl) 180 else if (cpl_p == TRUE && loss > cpl)
186 status = STATE_CRITICAL; 181 status = STATE_CRITICAL;
187 else if (wpl != UNKNOWN_PACKET_LOSS && loss > wpl) 182 else if (wpl_p == TRUE && loss > wpl)
188 status = STATE_WARNING; 183 status = STATE_WARNING;
189 else 184 else
190 status = STATE_OK; 185 status = STATE_OK;
191 186 /* loss=%.0f%%;%d;%d;0;100 */
192 die (status, _("FPING %s - %s (loss=%f%% )\n"), 187 die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"),
193 state_text (status), server_name, loss ); 188 state_text (status), server_name, loss ,
189 perfdata ("loss", (int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100));
194 190
195 } 191 }
196 else { 192 else {
@@ -267,22 +263,26 @@ process_arguments (int argc, char **argv)
267 case 'c': 263 case 'c':
268 get_threshold (optarg, rv); 264 get_threshold (optarg, rv);
269 if (rv[RTA]) { 265 if (rv[RTA]) {
270 crta = strtod (rv[RTA], NULL); 266 crta = 1e3 * strtod (rv[RTA], NULL);
267 crta_p = TRUE;
271 rv[RTA] = NULL; 268 rv[RTA] = NULL;
272 } 269 }
273 if (rv[PL]) { 270 if (rv[PL]) {
274 cpl = atoi (rv[PL]); 271 cpl = atoi (rv[PL]);
272 cpl_p = TRUE;
275 rv[PL] = NULL; 273 rv[PL] = NULL;
276 } 274 }
277 break; 275 break;
278 case 'w': 276 case 'w':
279 get_threshold (optarg, rv); 277 get_threshold (optarg, rv);
280 if (rv[RTA]) { 278 if (rv[RTA]) {
281 wrta = strtod (rv[RTA], NULL); 279 wrta = 1e3 * strtod (rv[RTA], NULL);
280 wrta_p = TRUE;
282 rv[RTA] = NULL; 281 rv[RTA] = NULL;
283 } 282 }
284 if (rv[PL]) { 283 if (rv[PL]) {
285 wpl = atoi (rv[PL]); 284 wpl = atoi (rv[PL]);
285 wpl_p = TRUE;
286 rv[PL] = NULL; 286 rv[PL] = NULL;
287 } 287 }
288 break; 288 break;
@@ -355,7 +355,6 @@ get_threshold (char *arg, char *rv[2])
355 355
356 356
357 357
358
359 358
360void 359void
361print_help (void) 360print_help (void)
@@ -363,8 +362,10 @@ print_help (void)
363 362
364 print_revision (progname, "$Revision$"); 363 print_revision (progname, "$Revision$");
365 364
365 printf (_("Copyright (c) 1999 Didi Rieder <adrieder@sbox.tu-graz.ac.at>\n"));
366 printf (_(COPYRIGHT), copyright, email);
367
366 printf (_("\ 368 printf (_("\
367Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n\n\
368This plugin will use the /bin/fping command (from saint) to ping the\n\ 369This plugin will use the /bin/fping command (from saint) to ping the\n\
369specified host for a fast check if the host is alive. Note that it is\n\ 370specified host for a fast check if the host is alive. Note that it is\n\
370necessary to set the suid flag on fping.\n\n")); 371necessary to set the suid flag on fping.\n\n"));