summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9064837)
raw | patch | inline | side by side (parent: 9064837)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Mon, 18 Aug 2003 11:05:17 +0000 (11:05 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Mon, 18 Aug 2003 11:05:17 +0000 (11:05 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@683 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_ping.c | patch | blob | history |
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index 87f9db011d83bede362ff8fbe1efdd03d870d5d2..7d9dd3bff17552556ae572401ddd380073d56834 100644 (file)
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
int process_arguments (int, char **);
int get_threshold (char *, float *, int *);
int validate_arguments (void);
-int run_ping (char *, char *);
+int run_ping (const char *cmd, const char *addr);
+int error_scan (char buf[MAX_INPUT_BUFFER], const char *addr);
void print_usage (void);
void print_help (void);
\f
int
-run_ping (char *cmd, char *server_address)
+run_ping (const char *cmd, const char *addr)
{
char buf[MAX_INPUT_BUFFER];
int result = STATE_UNKNOWN;
while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
- if (strstr (buf, _("(DUP!)"))) {
- result = max_state (result, STATE_WARNING);
- warn_text = strdup (WARN_DUPLICATES);
- if (!warn_text)
- die (STATE_UNKNOWN, _("unable to realloc warn_text"));
- }
+ result = max_state (result, error_scan (buf, addr));
/* get the percent loss statistics */
if(sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss",&pl)==1 ||
if (pl == 100)
rta = crta;
- /* check stderr */
- while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) {
- if (strstr(buf,"Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP"))
- continue;
-
- if (strstr (buf, "Network is unreachable"))
- die (STATE_CRITICAL,
- _("PING CRITICAL - Network unreachable (%s)"),
- server_address);
- else if (strstr (buf, "Destination Host Unreachable"))
- die (STATE_CRITICAL,
- _("PING CRITICAL - Host Unreachable (%s)"),
- server_address);
- else if (strstr (buf, "unknown host" ))
- die (STATE_CRITICAL,
- _("PING CRITICAL - Host not found (%s)"),
- server_address);
+ /* check stderr, setting at least WARNING if there is output here */
+ while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
+ if (! strstr(buf,"Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP"))
+ result = max_state (STATE_WARNING, error_scan (buf, addr));
- if (warn_text == NULL)
- warn_text = strdup (buf);
- else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1)
- die (STATE_UNKNOWN, _("unable to realloc warn_text"));
-
- if (strstr (buf, "DUPLICATES FOUND"))
- result = max_state (result, STATE_WARNING);
- else
- result = STATE_CRITICAL ;
- }
(void) fclose (child_stderr);
+int
+error_scan (char buf[MAX_INPUT_BUFFER], const char *addr)
+{
+ if (strstr (buf, "Network is unreachable"))
+ die (STATE_CRITICAL, _("PING CRITICAL - Network unreachable (%s)"), addr);
+ else if (strstr (buf, "Destination Host Unreachable"))
+ die (STATE_CRITICAL, _("PING CRITICAL - Host Unreachable (%s)"), addr);
+ else if (strstr (buf, "unknown host" ))
+ die (STATE_CRITICAL, _("PING CRITICAL - Host not found (%s)"), addr);
+
+ if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) {
+ if (warn_text == NULL)
+ warn_text = strdup (_(WARN_DUPLICATES));
+ else if (! strstr (warn_text, _(WARN_DUPLICATES)) &&
+ asprintf (&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1)
+ die (STATE_UNKNOWN, _("unable to realloc warn_text"));
+ return (STATE_WARNING);
+ }
+
+ return (STATE_OK);
+}
+
+
+
+
+
\f
void
print_usage (void)