示例#1
0
static int do_check (lcc_connection_t *connection)
{
	gauge_t *values;
	char   **values_names;
	size_t   values_num;
	char ident_str[1024];
	lcc_identifier_t ident;
	size_t i;
	int status;

	snprintf (ident_str, sizeof (ident_str), "%s/%s",
			hostname_g, value_string_g);
	ident_str[sizeof (ident_str) - 1] = 0;

	memset (&ident, 0, sizeof (ident));
	status = lcc_string_to_identifier (connection, &ident, ident_str);
	if (status != 0)
	{
		printf ("ERROR: Creating an identifier failed: %s.\n",
				lcc_strerror (connection));
		LCC_DESTROY (connection);
		return (RET_CRITICAL);
	}

	status = lcc_getval (connection, &ident,
			&values_num, &values, &values_names);
	if (status != 0)
	{
		printf ("ERROR: Retrieving values from the daemon failed: %s.\n",
				lcc_strerror (connection));
		LCC_DESTROY (connection);
		return (RET_CRITICAL);
	}

	LCC_DESTROY (connection);

	status = filter_ds (&values_num, &values, &values_names);
	if (status != RET_OKAY)
		return (status);

	status = RET_UNKNOWN;
	if (consolitation_g == CON_NONE)
		status =  do_check_con_none (values_num, values, values_names);
	else if (consolitation_g == CON_AVERAGE)
		status =  do_check_con_average (values_num, values, values_names);
	else if (consolitation_g == CON_SUM)
		status = do_check_con_sum (values_num, values, values_names);
	else if (consolitation_g == CON_PERCENTAGE)
		status = do_check_con_percentage (values_num, values, values_names);

	free (values);
	if (values_names != NULL)
		for (i = 0; i < values_num; i++)
			free (values_names[i]);
	free (values_names);

	return (status);
} /* int do_check */
示例#2
0
static int flush (
    const char *address,
    const char *plugin,
    const char *ident_str,
    int timeout)
{
  lcc_connection_t *connection;
  lcc_identifier_t ident;

  /* Pointer which is passed to lcc_flush.
   * Either a null pointer or it points to ident */
  lcc_identifier_t *identp;
  int status;

  connection = NULL;
  status = lcc_connect(address, &connection);
  if (status != 0) {
    fprintf (stderr, "ERROR: Connecting to daemon at %s failed: %s.\n",
        address, strerror (errno));
    return 1;
  }

  identp = NULL;
  if (ident_str != NULL && *ident_str != '\0') {
    status = lcc_string_to_identifier (connection, &ident, ident_str);
    if (status != 0) {
      fprintf (stderr, "ERROR: Creating and identifier failed: %s.\n",
          lcc_strerror(connection));
      LCC_DESTROY (connection);

      return 1;
    }
    identp = &ident;
  }

  status = lcc_flush (connection, plugin, identp, timeout);
  if (status != 0) {
    fprintf (stderr, "ERROR: Flushing failed: %s.\n",
        lcc_strerror (connection));
    LCC_DESTROY (connection);

    return 1;
  }

  LCC_DESTROY (connection);

  return 0;
}
示例#3
0
int main (int argc, char **argv) {
  char address[1024] = "unix:"DEFAULT_SOCK;

  lcc_connection_t *c;

  int status;

  while (42) {
    int c;

    c = getopt (argc, argv, "s:h");

    if (c == -1)
      break;

    switch (c) {
      case 's':
        snprintf (address, sizeof (address), "unix:%s", optarg);
        address[sizeof (address) - 1] = '\0';
        break;
      case 'h':
        exit_usage (argv[0], 0);
        break;
      default:
        exit_usage (argv[0], 1);
    }
  }

  if (optind >= argc) {
    fprintf (stderr, "%s: missing command\n", argv[0]);
    exit_usage (argv[0], 1);
  }

  c = NULL;
  status = lcc_connect (address, &c);
  if (status != 0) {
    fprintf (stderr, "ERROR: Failed to connect to daemon at %s: %s.\n",
        address, strerror (errno));
    return (1);
  }

  if (strcasecmp (argv[optind], "getval") == 0)
    status = getval (c, argc - optind, argv + optind);
  else if (strcasecmp (argv[optind], "flush") == 0)
    status = flush (c, argc - optind, argv + optind);
  else if (strcasecmp (argv[optind], "listval") == 0)
    status = listval (c, argc - optind, argv + optind);
  else if (strcasecmp (argv[optind], "putval") == 0)
    status = putval (c, argc - optind, argv + optind);
  else {
    fprintf (stderr, "%s: invalid command: %s\n", argv[0], argv[optind]);
    return (1);
  }

  LCC_DESTROY (c);

  if (status != 0)
    return (status);
  return (0);
} /* main */