Exemplo n.º 1
0
static int cj_curl_perform(cj_t *db) /* {{{ */
{
  int status;
  long rc;
  char *url;
  url = db->url;

  status = curl_easy_perform (db->curl);
  if (status != CURLE_OK)
  {
    ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
           status, db->curl_errbuf, url);
    return (-1);
  }
  if (db->stats != NULL)
    curl_stats_dispatch (db->stats, db->curl, cj_host (db), "curl_json", db->instance);

  curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url);
  curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc);

  /* The response code is zero if a non-HTTP transport was used. */
  if ((rc != 0) && (rc != 200))
  {
    ERROR ("curl_json plugin: curl_easy_perform failed with "
        "response code %ld (%s)", rc, url);
    return (-1);
  }
  return (0);
} /* }}} int cj_curl_perform */
Exemplo n.º 2
0
Arquivo: curl.c Projeto: brd/collectd
static int cc_read_page (web_page_t *wp) /* {{{ */
{
  int status;
  cdtime_t start = 0;

  if (wp->response_time)
    start = cdtime ();

  wp->buffer_fill = 0;
  status = curl_easy_perform (wp->curl);
  if (status != CURLE_OK)
  {
    ERROR ("curl plugin: curl_easy_perform failed with status %i: %s",
        status, wp->curl_errbuf);
    return (-1);
  }

  if (wp->response_time)
    cc_submit_response_time (wp, cdtime() - start);
  if (wp->stats != NULL)
    curl_stats_dispatch (wp->stats, wp->curl, hostname_g, "curl", wp->instance);

  if(wp->response_code)
  {
    long response_code = 0;
    status = curl_easy_getinfo(wp->curl, CURLINFO_RESPONSE_CODE, &response_code);
    if(status != CURLE_OK) {
      ERROR ("curl plugin: Fetching response code failed with status %i: %s",
        status, wp->curl_errbuf);
    } else {
      cc_submit_response_code(wp, response_code);
    }
  }

  for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next)
  {
    cu_match_value_t *mv;

    status = match_apply (wm->match, wp->buffer);
    if (status != 0)
    {
      WARNING ("curl plugin: match_apply failed.");
      continue;
    }

    mv = match_get_user_data (wm->match);
    if (mv == NULL)
    {
      WARNING ("curl plugin: match_get_user_data returned NULL.");
      continue;
    }

    cc_submit (wp, wm, mv);
    match_value_reset (mv);
  } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */

  return (0);
} /* }}} int cc_read_page */
Exemplo n.º 3
0
static int cx_read(user_data_t *ud) /* {{{ */
{
  if ((ud == NULL) || (ud->data == NULL)) {
    ERROR("curl_xml plugin: cx_read: Invalid user data.");
    return -1;
  }

  long rc;
  char *url;
  cx_t *db = (cx_t *)ud->data;

  db->buffer_fill = 0;

  curl_easy_setopt(db->curl, CURLOPT_URL, db->url);

  int status = curl_easy_perform(db->curl);
  if (status != CURLE_OK) {
    ERROR("curl_xml plugin: curl_easy_perform failed with status %i: %s (%s)",
          status, db->curl_errbuf, db->url);
    return -1;
  }
  if (db->stats != NULL)
    curl_stats_dispatch(db->stats, db->curl, cx_host(db), "curl_xml",
                        db->instance);

  curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url);
  curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc);

  /* The response code is zero if a non-HTTP transport was used. */
  if ((rc != 0) && (rc != 200)) {
    ERROR(
        "curl_xml plugin: curl_easy_perform failed with response code %ld (%s)",
        rc, url);
    return -1;
  }

  status = cx_parse_xml(db, db->buffer);
  db->buffer_fill = 0;

  return status;
} /* }}} int cx_read */
Exemplo n.º 4
0
static int cx_curl_perform(cx_t *db, CURL *curl) /* {{{ */
{
  int status;
  long rc;
  char *ptr;
  char *url;

  db->buffer_fill = 0;

  curl_easy_setopt(db->curl, CURLOPT_URL, db->url);

  status = curl_easy_perform(curl);
  if (status != CURLE_OK) {
    ERROR("curl_xml plugin: curl_easy_perform failed with status %i: %s (%s)",
          status, db->curl_errbuf, db->url);
    return -1;
  }
  if (db->stats != NULL)
    curl_stats_dispatch(db->stats, db->curl, cx_host(db), "curl_xml",
                        db->instance);

  curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
  curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc);

  /* The response code is zero if a non-HTTP transport was used. */
  if ((rc != 0) && (rc != 200)) {
    ERROR(
        "curl_xml plugin: curl_easy_perform failed with response code %ld (%s)",
        rc, url);
    return -1;
  }

  ptr = db->buffer;

  status = cx_parse_stats_xml(BAD_CAST ptr, db);
  db->buffer_fill = 0;

  return status;
} /* }}} int cx_curl_perform */