Exemplo n.º 1
0
void
influxdb_put(const char *id, double value)
{
  char url[1024];
  cfg_root(root);

  const char *urlprefix = cfg_get_str(root, CFG("influxdb", "url"), NULL);
  const char *db        = cfg_get_str(root, CFG("influxdb", "db"), NULL);
  const char *username  = cfg_get_str(root, CFG("influxdb", "username"), NULL);
  const char *password  = cfg_get_str(root, CFG("influxdb", "password"), NULL);
  if(urlprefix == NULL || db == NULL || username == NULL || password == NULL)
    return;

  snprintf(url, sizeof(url), "%s/db/%s/series?u=%s&p=%s",
           urlprefix, db, username, password);

  htsmsg_t *doc = htsmsg_create_list();
  htsmsg_t *item = htsmsg_create_map();

  htsmsg_add_str(item, "name", id);

  htsmsg_t *columns = htsmsg_create_list();
  htsmsg_add_str(columns, NULL, "value");
  htsmsg_add_msg(item, "columns", columns);

  htsmsg_t *points = htsmsg_create_list();
  htsmsg_t *point = htsmsg_create_list();
  htsmsg_add_dbl(point, NULL, value);
  htsmsg_add_msg(points, NULL, point);
  htsmsg_add_msg(item, "points", points);

  htsmsg_add_msg(doc, NULL, item);

  char *data = htsmsg_json_serialize_to_str(doc, 0);
  htsmsg_destroy(doc);

  size_t len = strlen(data);

  FILE *f = fmemopen(data, len, "r");

  CURL *curl = curl_easy_init();
  curl_easy_setopt(curl, CURLOPT_URL, url);
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &libsvc_curl_waste_output);
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
  curl_easy_setopt(curl, CURLOPT_READDATA, (void *)f);
  curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)len);

  CURLcode result = curl_easy_perform(curl);

  curl_easy_cleanup(curl);

  if(result)
    trace(LOG_ERR, "CURL Failed %s error %d", url, result);
  fclose(f);
  free(data);
}
Exemplo n.º 2
0
static int
dotdoozer_parse(job_t *j, htsmsg_t *target)
{
  SHA_CTX ctx;
  uint8_t digest[20];

  const char *buildenv = htsmsg_get_str(target, "buildenv");
  if(buildenv == NULL)
    return 0;

  cfg_root(root);
  const char *source = cfg_get_str(root, CFG("buildenvs", buildenv, "source"),
                                   NULL);
  if(source == NULL) {
    snprintf(j->errmsg, sizeof(j->errmsg), "Don't know about buildenv: %s",
             buildenv);
    return DOOZER_PERMANENT_FAIL;
  }

  // We are going to build in a chroot
  j->projectdir_internal = "/project";

  j->buildenv_source = tstrdup(source);

  // Compute SHA1 of source URL, this is the source ID

  SHA1((void *)source, strlen(source), digest);
  bin2hex(j->buildenv_source_id, sizeof(j->buildenv_source_id),
          digest, sizeof(digest));

  // Compute SHA1 of source URL + all build deps, this is the modified ID

  SHA1_Init(&ctx);
  SHA1_Update(&ctx, source, strlen(source));
  htsmsg_t *builddeps = htsmsg_get_list(target, "builddeps");
  if(builddeps != NULL) {

    htsmsg_field_t *f;

    int count = 0;
    HTSMSG_FOREACH(f, builddeps) {
      if(f->hmf_type != HMF_STR) {
        snprintf(j->errmsg, sizeof(j->errmsg),
                 "Not all builddeps are strings");
        return DOOZER_PERMANENT_FAIL;
      }
      count++;
    }

    j->num_builddeps = count;

    const char **bds = talloc_zalloc(count * sizeof(char *));
    count = 0;
    HTSMSG_FOREACH(f, builddeps) {
      bds[count++] = tstrdup(f->hmf_str);
      SHA1_Update(&ctx, f->hmf_str, strlen(f->hmf_str));
    }
Exemplo n.º 3
0
static void
create_heaps(void)
{
  cfg_root(root);
  const char *d;

  d = cfg_get_str(root, CFG("projectdir"), NULL);
  if(d == NULL) {
    trace(LOG_ERR, "No 'projectdir' configured, giving up");
    exit(1);
  }
  project_heap_mgr = create_heap(d);

  d = cfg_get_str(root, CFG("buildenvdir"), NULL);
  if(d == NULL) {
    trace(LOG_ERR, "No 'buildenvdir' configured, giving up");
    exit(1);
  }
  buildenv_heap_mgr = create_heap(d);
}
Exemplo n.º 4
0
static void
get_uid_gid(void)
{
  cfg_root(root);

  const char *user  = cfg_get_str(root, CFG("user"),  "nobody");
  const char *group = cfg_get_str(root, CFG("group"), "nogroup");

  const struct passwd *p = getpwnam(user);
  if(p == NULL) {
    trace(LOG_ERR, "Unable to find UID for user %s. Exiting", user);
    exit(1);
  }
  build_uid = p->pw_uid;

  const struct group *g = getgrnam(group);
  if(g == NULL) {
    trace(LOG_ERR, "Unable to find GID for group %s. Exiting", group);
    exit(1);
  }
  build_gid = g->gr_gid;
}