/** The watcher-delete command */ int cmd_watcher_delete (int argc, const char *argv[]) { if (OPTIONS.tenant[0] == 0) { fprintf (stderr, "%% No tenantid provided\n"); return 1; } if (OPTIONS.meter[0] == 0) { fprintf (stderr, "%% No meter provided\n"); return 1; } var *req = var_alloc(); var *apires; if (OPTIONS.host[0]) { apires = api_call ("DELETE", req, "/%s/host/%s/watcher/%s", OPTIONS.tenant, OPTIONS.host, OPTIONS.meter); } else { apires = api_call ("DELETE", req, "/%s/watcher/%s", OPTIONS.tenant, OPTIONS.meter); } var_free (req); var_free (apires); return 0; }
/** The watcher-set command */ int cmd_watcher_set (int argc, const char *argv[]) { if (OPTIONS.tenant[0] == 0) { fprintf (stderr, "%% No tenantid provided\n"); return 1; } if (OPTIONS.meter[0] == 0) { fprintf (stderr, "%% No meter provided\n"); return 1; } if (OPTIONS.match[0] == 0) { fprintf (stderr, "%% No match provided\n"); return 1; } if (OPTIONS.value[0] == 0) { fprintf (stderr, "%% No value provided\n"); return 1; } var *mdef = api_get ("/%s/meter", OPTIONS.tenant); if (! mdef) return 1; var *mdef_m = var_get_dict_forkey (mdef, "meter"); var *mde_meter = var_get_dict_forkey (mdef_m, OPTIONS.meter); const char *inftype = var_get_str_forkey (mde_meter, "type"); var *req = var_alloc(); var *req_watcher = var_get_dict_forkey (req, "watcher"); var *reql = var_get_dict_forkey (req_watcher, OPTIONS.level); if (OPTIONS.host[0] == 0) { var_set_str_forkey (reql, "cmp", OPTIONS.match); } if (strcmp (inftype, "integer") == 0) { var_set_int_forkey (reql, "val", strtoull (OPTIONS.value, NULL, 10)); } else if (strcmp (inftype, "frac") == 0) { var_set_double_forkey (reql, "val", atof (OPTIONS.value)); } else { var_set_str_forkey (reql, "val", OPTIONS.value); } var_set_double_forkey (reql, "weight", atof (OPTIONS.weight)); var *apires; if (OPTIONS.host[0]) { apires = api_call ("POST", req, "/%s/host/%s/watcher/%s", OPTIONS.tenant, OPTIONS.host, OPTIONS.meter); } else { apires = api_call ("POST", req, "/%s/watcher/%s", OPTIONS.tenant, OPTIONS.meter); } var_free (mdef); var_free (req); var_free (apires); return 0; }
void Api::get_notifications(const Remote &r, int n) { if (n < 0) return; ptree request; request.put("n", n); auto response = api_call(r, "get_notifications", request); auto notifications = response.get_child("notifications"); int i = 1; for (auto &n : notifications) { auto nt = (NotificationType)n.second.get<int>("type", 0); auto t = n.second.get<String>("text", ""); auto ts = n.second.get<String>("timestamp", ""); std::cout << i++ << " "; switch (nt) { case NotificationType::Error: std::cout << "E"; break; case NotificationType::Warning: std::cout << "W"; break; case NotificationType::Message: std::cout << "I"; break; case NotificationType::Success: std::cout << "OK"; break; } std::cout << " " << ts << " " << t << "\n"; } }
void Api::remove_project(const Remote &r, ProjectPath p) { check_relative(r, p); ptree request; request.put("project", p.toString()); api_call(r, "remove_project", request); }
/** The meter-create command */ int cmd_meter_create (int argc, const char *argv[]) { if (OPTIONS.tenant[0] == 0) { fprintf (stderr, "%% No tenantid provided\n"); return 1; } if (OPTIONS.meter[0] == 0) { fprintf (stderr, "%% No meter provided\n"); return 1; } var *req = var_alloc(); var *req_meter = var_get_dict_forkey (req, "meter"); var_set_str_forkey (req_meter, "type", OPTIONS.type); if (OPTIONS.description[0]) { var_set_str_forkey (req_meter, "description", OPTIONS.description); } if (OPTIONS.unit[0]) { var_set_str_forkey (req_meter, "unit", OPTIONS.unit); } var *apires = api_call ("POST",req,"/%s/meter/%s", OPTIONS.tenant, OPTIONS.meter); var_free (req); var_free (apires); return 0; }
void Api::remove_version(const Remote &r, ProjectPath p, const Version &v) { check_relative(r, p); ptree request; request.put("project", p.toString()); request.put("version", v.toString()); api_call(r, "remove_version", request); }
void Api::add_version(const Remote &r, ProjectPath p, const String &cppan) { check_relative(r, p); ptree request; request.put("project", p.toString()); request.put("cppan", cppan); api_call(r, "add_version", request); }
void Api::add_project(const Remote &r, ProjectPath p, ProjectType t) { check_relative(r, p); ptree request; request.put("project", p.toString()); request.put("type", toIndex(t)); api_call(r, "add_project", request); }
/* our own functions */ static int __init mod_init(void) { int i; /* call api_call 10 times */ for (i = 0; i < 10; i++) { api_call(); msleep(2000); } return 0; }
/** The tenant-delete command */ int cmd_tenant_delete (int argc, const char *argv[]) { /* Avoid using the default tenant in this case */ disregard_default_tenant(); if (OPTIONS.tenant[0] == 0) { fprintf (stderr, "%% No tenantid provided\n"); return 1; } var *req = var_alloc(); var *apires = api_call ("DELETE", req, "/%s", OPTIONS.tenant); var_free (req); var_free (apires); return 0; }
/** The meter-delete command */ int cmd_meter_delete (int argc, const char *argv[]) { if (OPTIONS.tenant[0] == 0) { fprintf (stderr, "%% No tenantid provided\n"); return 1; } if (OPTIONS.meter[0] == 0) { fprintf (stderr, "%% No meter provided\n"); return 1; } var *p = var_alloc(); var *apires = api_call ("DELETE", p, "/%s/meter/%s", OPTIONS.tenant, OPTIONS.meter); var_free (p); var_free (apires); return 0; }
/** The tenant-create command */ int cmd_tenant_create (int argc, const char *argv[]) { uuid tenant; /* Avoid using the default tenant in this case */ disregard_default_tenant(); if (OPTIONS.tenant[0] == 0) { tenant = uuidgen(); OPTIONS.tenant = (const char *) malloc (40); uuid2str (tenant, (char *) OPTIONS.tenant); } else { tenant = mkuuid (OPTIONS.tenant); } var *req = var_alloc(); var *req_tenant = var_get_dict_forkey (req, "tenant"); if (OPTIONS.key[0]) { var_set_str_forkey (req_tenant, "key", OPTIONS.key); } if (OPTIONS.name[0]) { var_set_str_forkey (req_tenant, "name", OPTIONS.name); } var *apires = api_call ("POST", req, "/%s", OPTIONS.tenant); if (apires) { var *r = var_get_dict_forkey (apires, "tenant"); printf ("Tenant created:\n" "---------------------------------------------" "-----------------------------------\n" " Name: %s\n" " UUID: %s\n" " AES Key: %s\n" "---------------------------------------------" "-----------------------------------\n", var_get_str_forkey (r, "name"), OPTIONS.tenant, var_get_str_forkey (r, "key")); } var_free (req); var_free (apires); return 0; }
/** The tenant-set-metadata command */ int cmd_tenant_set_metadata (int argc, const char *argv[]) { if (argc < 4) { fprintf (stderr, "%% Missing key and value arguments\n"); return 1; } const char *key = argv[2]; const char *val = argv[3]; if (OPTIONS.tenant[0] == 0) { fprintf (stderr, "%% No tenantid provided\n"); return 1; } var *api_meta = api_get ("/%s/meta", OPTIONS.tenant); var *meta = var_get_dict_forkey (api_meta, "metadata"); var_set_str_forkey (meta, key, val); var *res = api_call ("POST", api_meta, "/%s/meta", OPTIONS.tenant); var_free (api_meta); var_free (res); return 0; }
void Api::clear_notifications(const Remote &r) { ptree request; api_call(r, "clear_notifications", request); }