summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 88def49)
raw | patch | inline | side by side (parent: 88def49)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 28 Jan 2007 19:00:28 +0000 (20:00 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 28 Jan 2007 19:00:28 +0000 (20:00 +0100) |
This is, of course, necessary, because many hosts may submit their values.
src/collectd-nagios.c | patch | blob | history | |
src/unixsock.c | patch | blob | history |
diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c
index d3369b24a85ce012356a4709a602bee210c64838..160412c5ed84b4131e8ad8dc159b0ea8da01ef43 100644 (file)
--- a/src/collectd-nagios.c
+++ b/src/collectd-nagios.c
static char *socket_file_g = NULL;
static char *value_string_g = NULL;
+static char *hostname_g = NULL;
+
static range_t range_critical_g;
static range_t range_warning_g;
static int consolitation_g = CON_NONE;
return (-1);
}
- fprintf (fh, "GETVAL %s\n", value_string_g);
+ fprintf (fh, "GETVAL %s/%s\n", hostname_g, value_string_g);
fflush (fh);
if (fgets (buffer, sizeof (buffer), fh) == NULL)
static void usage (const char *name)
{
- fprintf (stderr, "Usage: %s <-s socket> <-n value_spec> [options]\n"
+ fprintf (stderr, "Usage: %s <-s socket> <-n value_spec> <-H hostname> [options]\n"
"\n"
"Valid options are:\n"
" -s <socket> Path to collectd's UNIX-socket.\n"
" DSes. By default all DSes are used.\n"
" -g <consol> Method to use to consolidate several DSes.\n"
" Valid arguments are `none', `average' and `sum'\n"
+ " -H <host> Hostname to query the values for.\n"
" -c <range> Critical range\n"
" -w <range> Warning range\n"
"\n"
{
int c;
- c = getopt (argc, argv, "w:c:s:n:g:d:h");
+ c = getopt (argc, argv, "w:c:s:n:H:g:d:h");
if (c < 0)
break;
case 'n':
value_string_g = optarg;
break;
+ case 'H':
+ hostname_g = optarg;
+ break;
case 'g':
if (strcasecmp (optarg, "none") == 0)
consolitation_g = CON_NONE;
} /* switch (c) */
}
- if ((socket_file_g == NULL) || (value_string_g == NULL))
+ if ((socket_file_g == NULL) || (value_string_g == NULL)
+ || (hostname_g == NULL))
usage (argv[0]);
return (do_check ());
diff --git a/src/unixsock.c b/src/unixsock.c
index 21c9cc6525fc6bf5a3b4f05afa7eedbea98b57e7..e6017ef2584b532e85088f2c82087c50fee8bbed 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
} /* value_cache_t *cache_search */
static int cache_alloc_name (char *ret, int ret_len,
+ const char *hostname,
const char *plugin, const char *plugin_instance,
const char *type, const char *type_instance)
{
if ((plugin_instance == NULL) || (strlen (plugin_instance) == 0))
{
if ((type_instance == NULL) || (strlen (type_instance) == 0))
- status = snprintf (ret, ret_len, "%s/%s",
- plugin, type);
+ status = snprintf (ret, ret_len, "%s/%s/%s",
+ hostname, plugin, type);
else
- status = snprintf (ret, ret_len, "%s/%s-%s",
- plugin, type, type_instance);
+ status = snprintf (ret, ret_len, "%s/%s/%s-%s",
+ hostname, plugin, type, type_instance);
}
else
{
if ((type_instance == NULL) || (strlen (type_instance) == 0))
- status = snprintf (ret, ret_len, "%s-%s/%s",
- plugin, plugin_instance, type);
+ status = snprintf (ret, ret_len, "%s/%s-%s/%s",
+ hostname, plugin, plugin_instance, type);
else
- status = snprintf (ret, ret_len, "%s-%s/%s-%s",
- plugin, plugin_instance,
- type, type_instance);
+ status = snprintf (ret, ret_len, "%s/%s-%s/%s-%s",
+ hostname, plugin, plugin_instance, type, type_instance);
}
if ((status < 1) || (status >= ret_len))
}
if (cache_alloc_name (vc->name, sizeof (vc->name),
- vl->plugin, vl->plugin_instance,
+ vl->host, vl->plugin, vl->plugin_instance,
ds->type, vl->type_instance) != 0)
{
pthread_mutex_unlock (&cache_lock);
int i;
if (cache_alloc_name (name, sizeof (name),
+ vl->host,
vl->plugin, vl->plugin_instance,
ds->type, vl->type_instance) != 0)
return (-1);
static int us_handle_getval (FILE *fh, char **fields, int fields_num)
{
- char *plugin = fields[1];
+ char *hostname = fields[1];
+ char *plugin;
char *plugin_instance;
char *type;
char *type_instance;
if (fields_num != 2)
return (-1);
+ plugin = strchr (hostname, '/');
+ if (plugin == NULL)
+ return (-1);
+ *plugin = '\0'; plugin++;
+
type = strchr (plugin, '/');
if (type == NULL)
return (-1);
}
status = cache_alloc_name (name, sizeof (name),
- plugin, plugin_instance, type, type_instance);
+ hostname, plugin, plugin_instance, type, type_instance);
if (status != 0)
return (-1);