コード例 #1
0
ファイル: client.c プロジェクト: nkazzaz/collectd-freeswitch
int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */
{
  char ident_str[6 * LCC_NAME_LEN];
  char ident_esc[12 * LCC_NAME_LEN];
  char command[1024] = "";
  lcc_response_t res;
  int status;
  size_t i;

  if ((c == NULL) || (vl == NULL) || (vl->values_len < 1)
      || (vl->values == NULL) || (vl->values_types == NULL))
  {
    lcc_set_errno (c, EINVAL);
    return (-1);
  }

  status = lcc_identifier_to_string (c, ident_str, sizeof (ident_str),
      &vl->identifier);
  if (status != 0)
    return (status);

  SSTRCATF (command, "PUTVAL %s",
      lcc_strescape (ident_esc, ident_str, sizeof (ident_esc)));

  if (vl->interval > 0)
    SSTRCATF (command, " interval=%i", vl->interval);

  if (vl->time > 0)
    SSTRCATF (command, "%u", (unsigned int) vl->time);
  else
    SSTRCAT (command, "N");

  for (i = 0; i < vl->values_len; i++)
  {
    if (vl->values_types[i] == LCC_TYPE_COUNTER)
      SSTRCATF (command, ":%"PRIu64, vl->values[i].counter);
    else if (vl->values_types[i] == LCC_TYPE_GAUGE)
    {
      if (isnan (vl->values[i].gauge))
        SSTRCPY (command, ":U");
      else
        SSTRCATF (command, ":%g", vl->values[i].gauge);
    }
  } /* for (i = 0; i < vl->values_len; i++) */

  status = lcc_sendreceive (c, command, &res);
  if (status != 0)
    return (status);

  if (res.status != 0)
  {
    LCC_SET_ERRSTR (c, "Server error: %s", res.message);
    lcc_response_free (&res);
    return (-1);
  }

  lcc_response_free (&res);
  return (0);
} /* }}} int lcc_putval */
コード例 #2
0
ファイル: client.c プロジェクト: QualityUnit/collectd
int lcc_flush (lcc_connection_t *c, const char *plugin, /* {{{ */
    lcc_identifier_t *ident, int timeout)
{
  char command[1024] = "";
  lcc_response_t res;
  int status;

  if (c == NULL)
  {
    lcc_set_errno (c, EINVAL);
    return (-1);
  }

  SSTRCPY (command, "FLUSH");

  if (timeout > 0)
    SSTRCATF (command, " timeout=%i", timeout);

  if (plugin != NULL)
  {
    char buffer[2 * LCC_NAME_LEN];
    SSTRCATF (command, " plugin=%s",
        lcc_strescape (buffer, plugin, sizeof (buffer)));
  }

  if (ident != NULL)
  {
    char ident_str[6 * LCC_NAME_LEN];
    char ident_esc[12 * LCC_NAME_LEN];

    status = lcc_identifier_to_string (c, ident_str, sizeof (ident_str), ident);
    if (status != 0)
      return (status);

    SSTRCATF (command, " identifier=%s",
        lcc_strescape (ident_esc, ident_str, sizeof (ident_esc)));
  }

  status = lcc_sendreceive (c, command, &res);
  if (status != 0)
    return (status);

  if (res.status != 0)
  {
    LCC_SET_ERRSTR (c, "Server error: %s", res.message);
    lcc_response_free (&res);
    return (-1);
  }

  lcc_response_free (&res);
  return (0);
} /* }}} int lcc_flush */