extern int registry_request_access_json(struct web_client *w, char *person_guid, char *machine_guid, char *url, char *name, time_t when);
extern int registry_request_delete_json(struct web_client *w, char *person_guid, char *machine_guid, char *url, char *delete_url, time_t when);
extern int registry_request_search_json(struct web_client *w, char *person_guid, char *machine_guid, char *url, char *request_machine, time_t when);
+extern int registry_json_redirect(struct web_client *w);
extern int registry_init(void);
extern void registry_free(void);
extern void registry_statistics(void);
+
#endif /* NETDATA_REGISTRY_H */
if(!strcmp(name, "action")) {
if(!strcmp(value, "access")) action = 'A';
+ else if(!strcmp(value, "hello")) action = 'H';
else if(!strcmp(value, "delete")) action = 'D';
else if(!strcmp(value, "search")) action = 'S';
}
}
}
- if((!action || !machine_guid || !machine_url) || (action == 'A' && !url_name) || (action == 'D' && !delete_url) || (action == 'S' && !search_machine_guid)) {
+ if(action == 'A' && (!machine_guid || !machine_url || !url_name)) {
buffer_flush(w->response.data);
- buffer_sprintf(w->response.data, "Invalid registry request - required parameters missing.");
+ buffer_sprintf(w->response.data, "Invalid registry request - access requires these parameters: machine ('%s'), url ('%s'), name ('%s')",
+ machine_guid?machine_guid:"UNSET", machine_url?machine_url:"UNSET", url_name?url_name:"UNSET");
+ return 400;
+ }
+ else if(action == 'D' && (!machine_guid || !machine_url || !delete_url)) {
+ buffer_flush(w->response.data);
+ buffer_sprintf(w->response.data, "Invalid registry request - delete requires these parameters: machine ('%s'), url ('%s'), delete_url ('%s')",
+ machine_guid?machine_guid:"UNSET", machine_url?machine_url:"UNSET", delete_url?delete_url:"UNSET");
+ return 400;
+ }
+ else if(action == 'S' && (!machine_guid || !machine_url || !search_machine_guid)) {
+ buffer_flush(w->response.data);
+ buffer_sprintf(w->response.data, "Invalid registry request - search requires these parameters: machine ('%s'), url ('%s'), for ('%s')",
+ machine_guid?machine_guid:"UNSET", machine_url?machine_url:"UNSET", search_machine_guid?search_machine_guid:"UNSET");
return 400;
}
+ /*
+ * No, this is not right
+ if(action != 'H' && !person_guid[0]) {
+ buffer_flush(w->response.data);
+ buffer_sprintf(w->response.data, "Invalid registry request - you need to send your cookie for this action.");
+ return 400;
+ }
+ */
+
switch(action) {
case 'A':
return registry_request_access_json(w, person_guid, machine_guid, machine_url, url_name, time(NULL));
case 'S':
return registry_request_search_json(w, person_guid, machine_guid, machine_url, search_machine_guid, time(NULL));
+
+ case 'H':
+ return registry_json_redirect(w);
+
+ default:
+ buffer_flush(w->response.data);
+ buffer_sprintf(w->response.data, "Invalid registry request - you need to set an action: hello, access, delete, search");
+ return 400;
}
buffer_flush(w->response.data);
NETDATA.loadRequiredCSS(++index);
};
+ NETDATA.registry = {
+ host: null,
+ machine_guid: null,
+ urls: null,
+
+ init: function() {
+ NETDATA.registry.hello(function() {
+ console.log('hello completed');
+ NETDATA.registry.access(function() {
+ console.log('access completed');
+ console.log(NETDATA.registry);
+ })
+ });
+ },
+
+ hello: function(callback) {
+ $.ajax({
+ url: NETDATA.serverDefault + '/api/v1/registry?action=hello',
+ async: true,
+ cache: false,
+ xhrFields: { withCredentials: true }
+ })
+ .done(function(data) {
+ NETDATA.registry.host = data.registry;
+ NETDATA.registry.machine_guid = data.machine_guid;
+
+ if(typeof callback === 'function')
+ callback();
+ })
+ .fail(function() {
+ console.log('failed to hello (registry) netdata server: ' + NETDATA.serverDefault);
+ });
+ },
+
+ access: function(callback) {
+ $.ajax({
+ url: NETDATA.registry.host + '/api/v1/registry?action=access&machine=' + NETDATA.registry.machine_guid + '&name=test&url=' + document.location,
+ async: true,
+ cache: false,
+ xhrFields: { withCredentials: true }
+ })
+ .done(function(data) {
+ NETDATA.registry.urls = data.urls;
+
+ if(typeof callback === 'function')
+ callback();
+ })
+ .fail(function() {
+ console.log('failed to access (registry) netdata server: ' + NETDATA.registry.host);
+ });
+ }
+
+ };
+
NETDATA.errorReset();
NETDATA.loadRequiredCSS(0);
if(NETDATA.options.debug.main_loop === true)
console.log('starting chart refresh thread');
+ setTimeout(NETDATA.registry.init, 500);
+
NETDATA.start();
}
});