projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
contrib/php-collection: Add a PHP frontend for graph generation.
[collectd.git]
/
src
/
utils_cmd_putnotif.c
diff --git
a/src/utils_cmd_putnotif.c
b/src/utils_cmd_putnotif.c
index
0282e4e
..
eb7d60b
100644
(file)
--- a/
src/utils_cmd_putnotif.c
+++ b/
src/utils_cmd_putnotif.c
@@
-23,6
+23,14
@@
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
+#define print_to_socket(fh, ...) \
+ if (fprintf (fh, __VA_ARGS__) < 0) { \
+ char errbuf[1024]; \
+ WARNING ("handle_putnotif: failed to write to socket #%i: %s", \
+ fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
+ return -1; \
+ }
+
static int parse_option_severity (notification_t *n, char *value)
{
if (strcasecmp (value, "Failure") == 0)
static int parse_option_severity (notification_t *n, char *value)
{
if (strcasecmp (value, "Failure") == 0)
@@
-107,9
+115,9
@@
int handle_putnotif (FILE *fh, char **fields, int fields_num)
if (fields_num < 4)
{
DEBUG ("cmd putnotif: Wrong number of fields: %i", fields_num);
if (fields_num < 4)
{
DEBUG ("cmd putnotif: Wrong number of fields: %i", fields_num);
- fprintf (fh, "-1 Wrong number of fields: Got %i, expected at least 4.\n",
+ print_to_socket (fh, "-1 Wrong number of fields: Got %i, "
+ "expected at least 4.\n",
fields_num);
fields_num);
- fflush (fh);
return (-1);
}
return (-1);
}
@@
-123,7
+131,7
@@
int handle_putnotif (FILE *fh, char **fields, int fields_num)
status = parse_message (&n, fields + i, fields_num - i);
if (status != 0)
{
status = parse_message (&n, fields + i, fields_num - i);
if (status != 0)
{
-
fprintf
(fh, "-1 Error parsing the message. Have you hit the "
+
print_to_socket
(fh, "-1 Error parsing the message. Have you hit the "
"limit of %u bytes?\n", (unsigned int) sizeof (n.message));
}
break;
"limit of %u bytes?\n", (unsigned int) sizeof (n.message));
}
break;
@@
-133,7
+141,7
@@
int handle_putnotif (FILE *fh, char **fields, int fields_num)
status = parse_option (&n, fields[i]);
if (status != 0)
{
status = parse_option (&n, fields[i]);
if (status != 0)
{
-
fprintf (fh, "-1 Error parsing option `%s'
", fields[i]);
+
print_to_socket (fh, "-1 Error parsing option `%s'\n
", fields[i]);
break;
}
}
break;
}
}
@@
-142,17
+150,17
@@
int handle_putnotif (FILE *fh, char **fields, int fields_num)
/* Check for required fields and complain if anything is missing. */
if ((status == 0) && (n.severity == 0))
{
/* Check for required fields and complain if anything is missing. */
if ((status == 0) && (n.severity == 0))
{
-
fprintf
(fh, "-1 Option `severity' missing.\n");
+
print_to_socket
(fh, "-1 Option `severity' missing.\n");
status = -1;
}
if ((status == 0) && (n.time == 0))
{
status = -1;
}
if ((status == 0) && (n.time == 0))
{
-
fprintf
(fh, "-1 Option `time' missing.\n");
+
print_to_socket
(fh, "-1 Option `time' missing.\n");
status = -1;
}
if ((status == 0) && (strlen (n.message) == 0))
{
status = -1;
}
if ((status == 0) && (strlen (n.message) == 0))
{
-
fprintf
(fh, "-1 No message or message of length 0 given.\n");
+
print_to_socket
(fh, "-1 No message or message of length 0 given.\n");
status = -1;
}
status = -1;
}
@@
-161,9
+169,8
@@
int handle_putnotif (FILE *fh, char **fields, int fields_num)
if (status == 0)
{
plugin_dispatch_notification (&n);
if (status == 0)
{
plugin_dispatch_notification (&n);
-
fprintf
(fh, "0 Success\n");
+
print_to_socket
(fh, "0 Success\n");
}
}
- fflush (fh);
return (0);
} /* int handle_putnotif */
return (0);
} /* int handle_putnotif */