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 ());
} /* 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);