$("#actionsFormField").attr("disabled", true);
}
- function saveActions(callback) {
+ function saveActions(is_cluster) {
var elts = loadActionsFromForm();
// String to array for comparison
var eltsArray = JSON.parse(loadActionsFromForm());
(eltsArray[1] === null || eltsArray[2] < eltsArray[1]) &&
(eltsArray[0] === null || eltsArray[1] < eltsArray[0])
) {
- callback("saveactions", null, null, "POST", {}, {
+ rspamd.query("saveactions", null, null, "POST", {}, {
data: elts,
dataType: "json"
- });
+ }, {}, is_cluster);
} else {
rspamd.alertMessage("alert-modal alert-error", "Incorrect order of metric actions threshold");
}
}
$("#saveActionsBtn").on("click", function () {
- saveActions(rspamd.queryLocal);
+ saveActions();
});
$("#saveActionsClusterBtn").on("click", function () {
- saveActions(rspamd.queryNeighbours);
+ saveActions(true);
});
},
});
var action = $(form).attr("action");
var id = $(form).attr("id");
var data = $("#" + id).find("textarea").val();
- rspamd.queryNeighbours(action, save_map_success, save_map_error, "POST", {
+ rspamd.query(action, save_map_success, save_map_error, "POST", {
Map: id,
}, {
data: data,
graphs.graph = initGraph();
}
- (function (callback) {
- callback("graph",
- function (req_data) {
- if (checked_server !== "All SERVERS") {
- updateWidgets(req_data);
- return;
- }
-
- var neighbours_data = req_data
- .filter(function (d) { return d.status; }) // filter out unavailable neighbours
- .map(function (d) { return d.data; });
+ rspamd.query("graph",
+ function (req_data) {
+ var neighbours_data = req_data
+ .filter(function (d) { return d.status; }) // filter out unavailable neighbours
+ .map(function (d) { return d.data; });
- if (neighbours_data.length > 1) {
- neighbours_data.reduce(function (res, curr) {
- if ((curr[0][0].x !== res[0][0].x) ||
- (curr[0][curr[0].length - 1].x !== res[0][res[0].length - 1].x)) {
- rspamd.alertMessage("alert-error",
- "Neighbours time extents do not match. Check if time is synchronized on all servers.");
- updateWidgets();
- return;
- }
+ if (neighbours_data.length > 1) {
+ neighbours_data.reduce(function (res, curr) {
+ if ((curr[0][0].x !== res[0][0].x) ||
+ (curr[0][curr[0].length - 1].x !== res[0][res[0].length - 1].x)) {
+ rspamd.alertMessage("alert-error",
+ "Neighbours time extents do not match. Check if time is synchronized on all servers.");
+ updateWidgets();
+ return;
+ }
- var data = [];
- curr.forEach(function (action, j) {
- data.push(
- action.map(function (d, i) {
- return {
- x: d.x,
- y: ((res[j][i].y === null) ? d.y : res[j][i].y + d.y)
- };
- })
- );
- });
- updateWidgets(data);
+ var data = [];
+ curr.forEach(function (action, j) {
+ data.push(
+ action.map(function (d, i) {
+ return {
+ x: d.x,
+ y: ((res[j][i].y === null) ? d.y : res[j][i].y + d.y)
+ };
+ })
+ );
});
- } else {
- updateWidgets(neighbours_data[0]);
- }
- },
- function (serv, jqXHR, textStatus, errorThrown) {
- var serv_name = (typeof serv === "string") ? serv : serv.name;
- var alert_status = "alerted_graph_" + serv_name;
+ updateWidgets(data);
+ });
+ } else {
+ updateWidgets(neighbours_data[0]);
+ }
+ },
+ function (serv, jqXHR, textStatus, errorThrown) {
+ var serv_name = (typeof serv === "string") ? serv : serv.name;
+ var alert_status = "alerted_graph_" + serv_name;
- if (!(alert_status in sessionStorage)) {
- sessionStorage.setItem(alert_status, true);
- rspamd.alertMessage("alert-error", "Cannot receive throughput data from " +
- serv_name + ", error: " + errorThrown);
- }
- },
- "GET", {}, {}, {type: type}
- );
- }((checked_server === "All SERVERS") ? rspamd.queryNeighbours : rspamd.queryLocal));
+ if (!(alert_status in sessionStorage)) {
+ sessionStorage.setItem(alert_status, true);
+ rspamd.alertMessage("alert-error", "Cannot receive throughput data from " +
+ serv_name + ", error: " + errorThrown);
+ }
+ },
+ "GET", {}, {}, {type: type}
+ );
};
ui.setup = function () {
};
if (checked_server === "All SERVERS") {
- rspamd.queryNeighbours("history", function (req_data) {
+ rspamd.query("history", function (req_data) {
function differentVersions(neighbours_data) {
var dv = neighbours_data.some(function (e) {
return e.version !== neighbours_data[0].version;
delete ft.errors;
}
- (function (callback) {
- callback("historyreset",
- function () {
- ui.getHistory(rspamd, tables, neighbours, checked_server);
- ui.getErrors(rspamd, tables, neighbours, checked_server);
- },
- function (serv, jqXHR, textStatus, errorThrown) {
- var serv_name = (typeof serv === "string") ? serv : serv.name;
- rspamd.alertMessage("alert-error",
- "Cannot reset history log on " + serv_name + ": " + errorThrown);
- },
- "GET", {}, {}
- );
- }((checked_server === "All SERVERS") ? rspamd.queryNeighbours : rspamd.queryLocal));
+ rspamd.query("historyreset",
+ function () {
+ ui.getHistory(rspamd, tables, neighbours, checked_server);
+ ui.getErrors(rspamd, tables, neighbours, checked_server);
+ },
+ function (serv, jqXHR, textStatus, errorThrown) {
+ var serv_name = (typeof serv === "string") ? serv : serv.name;
+ rspamd.alertMessage("alert-error",
+ "Cannot reset history log on " + serv_name + ": " + errorThrown);
+ },
+ "GET", {}, {}
+ );
});
};
}
});
} else {
- rspamd.queryNeighbours("errors", function (req_data) {
+ rspamd.query("errors", function (req_data) {
var neighbours_data = req_data
.filter(function (d) {
return d.status;
}, 5000);
}
+ function queryServer(neighbours_status, ind, req_url, on_success, on_error, method, headers, params, req_data) {
+ var req_params = {
+ type: typeof method !== "undefined" ? method : "GET",
+ jsonp: false,
+ data: req_data,
+ beforeSend: function (xhr) {
+ xhr.setRequestHeader("Password", getPassword());
+
+ if (headers) {
+ $.each(headers, function (hname, hvalue) {
+ xhr.setRequestHeader(hname, hvalue);
+ });
+ }
+ },
+ url: neighbours_status[ind].url + req_url,
+ success: function (json) {
+ neighbours_status[ind].checked = true;
+
+ if (jQuery.isEmptyObject(json)) {
+ neighbours_status[ind].status = false; // serv does not work
+ } else {
+ neighbours_status[ind].status = true; // serv works
+ neighbours_status[ind].data = json;
+ }
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ neighbours_status[ind].status = false;
+ neighbours_status[ind].checked = true;
+ if (on_error) {
+ on_error(neighbours_status[ind],
+ jqXHR, textStatus, errorThrown);
+ } else {
+ alertMessage("alert-error", "Cannot receive data from " +
+ neighbours_status[ind].host + ": " + errorThrown);
+ }
+ },
+ complete: function () {
+ if (neighbours_status.every(function (elt) { return elt.checked; })) {
+ if (neighbours_status.some(function (elt) { return elt.status; })) {
+ if (on_success) {
+ on_success(neighbours_status);
+ } else {
+ alertMessage("alert-success", "Request completed");
+ }
+ } else {
+ alertMessage("alert-error", "Request failed");
+ }
+ }
+ }
+ };
+ if (params) {
+ $.each(params, function (k, v) {
+ req_params[k] = v;
+ });
+ }
+ $.ajax(req_params);
+ }
+
// Public functions
ui.alertMessage = alertMessage;
ui.setup = function () {
});
};
- ui.queryLocal = function (req_url, on_success, on_error, method, headers, params, req_data) {
- var req_params = {
- type: method,
- jsonp: false,
- data: req_data,
- beforeSend: function (xhr) {
- xhr.setRequestHeader("Password", getPassword());
-
- if (headers) {
- $.each(headers, function (hname, hvalue) {
- xhr.setRequestHeader(hname, hvalue);
- });
- }
- },
- url: neighbours[checked_server].url + req_url,
- success: function (data) {
- if (on_success) {
- on_success(data);
- } else {
- alertMessage("alert-success", "Data saved");
- }
- },
- error: function (jqXHR, textStatus, errorThrown) {
- if (on_error) {
- on_error(checked_server, jqXHR, textStatus, errorThrown);
- } else {
- alertMessage("alert-error", "Cannot receive data: " + errorThrown);
- }
- }
- };
- if (params) {
- $.each(params, function (k, v) {
- req_params[k] = v;
- });
- }
- $.ajax(req_params);
- };
-
- ui.queryNeighbours = function (req_url, on_success, on_error, method, headers, params, req_data) {
- $.ajax({
- dataType: "json",
- type: "GET",
- url: "neighbours",
- jsonp: false,
- beforeSend: function (xhr) {
- xhr.setRequestHeader("Password", getPassword());
- },
- success: function (data) {
- if (jQuery.isEmptyObject(data)) {
- neighbours = {
- local: {
- host: window.location.host,
- url: window.location.href
- }
- };
- } else {
- neighbours = data;
- }
- var neighbours_status = [];
- $.each(neighbours, function (ind) {
- neighbours_status.push({
- name: ind,
- url: neighbours[ind].url,
- host: neighbours[ind].host,
- checked: false,
- data: {},
- status: false,
- });
- });
- $.each(neighbours_status, function (ind) {
- var req_params = {
- type: typeof method !== "undefined" ? method : "GET",
- jsonp: false,
- data: req_data,
- beforeSend: function (xhr) {
- xhr.setRequestHeader("Password", getPassword());
-
- if (headers) {
- $.each(headers, function (hname, hvalue) {
- xhr.setRequestHeader(hname, hvalue);
- });
- }
- },
- url: neighbours_status[ind].url + req_url,
- success: function (json) {
- neighbours_status[ind].checked = true;
-
- if (jQuery.isEmptyObject(json)) {
- neighbours_status[ind].status = false; // serv does not work
- } else {
- neighbours_status[ind].status = true; // serv works
- neighbours_status[ind].data = json;
- }
- },
- error: function (jqXHR, textStatus, errorThrown) {
- neighbours_status[ind].status = false;
- neighbours_status[ind].checked = true;
- if (on_error) {
- on_error(neighbours_status[ind],
- jqXHR, textStatus, errorThrown);
- } else {
- alertMessage("alert-error", "Cannot receive data from " +
- neighbours_status[ind].host + ": " + errorThrown);
- }
- },
- complete: function () {
- if (neighbours_status.every(function (elt) { return elt.checked; })) {
- if (neighbours_status.some(function (elt) { return elt.status; })) {
- if (on_success) {
- on_success(neighbours_status);
- } else {
- alertMessage("alert-success", "Request completed");
- }
- } else {
- alertMessage("alert-error", "Request failed");
- }
- }
- }
- };
- if (params) {
- $.each(params, function (k, v) {
- req_params[k] = v;
- });
- }
- $.ajax(req_params);
- });
- },
- error: function () {
- ui.alertMessage("alert-error", "Cannot receive neighbours data");
- },
- });
- };
-
ui.drawPie = function (object, id, data, conf) {
var obj = object;
if (obj) {
ui.getPassword = getPassword;
+ ui.query = function (req_url, on_success, on_error, method, headers, params, req_data, is_cluster) {
+ if (checked_server === "All SERVERS" || is_cluster) {
+ $.ajax({
+ dataType: "json",
+ type: "GET",
+ url: "neighbours",
+ jsonp: false,
+ beforeSend: function (xhr) {
+ xhr.setRequestHeader("Password", getPassword());
+ },
+ success: function (data) {
+ if (jQuery.isEmptyObject(data)) {
+ neighbours = {
+ local: {
+ host: window.location.host,
+ url: window.location.href
+ }
+ };
+ } else {
+ neighbours = data;
+ }
+ var neighbours_status = [];
+ $.each(neighbours, function (ind) {
+ neighbours_status.push({
+ name: ind,
+ url: neighbours[ind].url,
+ host: neighbours[ind].host,
+ checked: false,
+ data: {},
+ status: false,
+ });
+ });
+ $.each(neighbours_status, function (ind) {
+ queryServer(neighbours_status, ind, req_url, on_success, on_error, method, headers, params, req_data);
+ });
+ },
+ error: function () {
+ ui.alertMessage("alert-error", "Cannot receive neighbours data");
+ },
+ });
+ } else {
+ var neighbours_status = [];
+ neighbours_status[0] = {
+ name: checked_server,
+ url: neighbours[checked_server].url,
+ host: neighbours[checked_server].host,
+ checked: false,
+ data: {},
+ status: false,
+ };
+
+ queryServer(neighbours_status, 0, req_url, on_success, on_error, method, headers, params, req_data);
+ }
+ };
+
return ui;
});
// Public API
var ui = {
statWidgets: function (rspamd, graphs, checked_server) {
- rspamd.queryNeighbours("/auth", function (neighbours_status) {
+ rspamd.query("/auth", function (neighbours_status) {
var neighbours_sum = {
version: neighbours_status[0].data.version,
auth: "ok",
rspamd.alertMessage("alert-error", "Cannot receive stats data from: " +
serv.name + ", error: " + errorThrown);
}
- });
+ }, "GET", {}, {}, {}, true);
},
};
});
});
- (function (callback) {
- callback(url,
- function () {
- rspamd.alertMessage("alert-modal alert-success", "Symbols successfully saved");
- },
- function (serv, jqXHR, textStatus, errorThrown) {
- var serv_name = (typeof serv === "string") ? serv : serv.name;
- rspamd.alertMessage("alert-modal alert-error",
- "Save symbols error on " + serv_name + ": " + errorThrown);
- },
- "POST", {}, {
- data: JSON.stringify(values),
- dataType: "json",
- }
- );
- }((is_cluster) ? rspamd.queryNeighbours : rspamd.queryLocal));
+ rspamd.query(url,
+ function () {
+ rspamd.alertMessage("alert-modal alert-success", "Symbols successfully saved");
+ },
+ function (serv, jqXHR, textStatus, errorThrown) {
+ var serv_name = (typeof serv === "string") ? serv : serv.name;
+ rspamd.alertMessage("alert-modal alert-error",
+ "Save symbols error on " + serv_name + ": " + errorThrown);
+ },
+ "POST", {}, {
+ data: JSON.stringify(values),
+ dataType: "json",
+ }, {}, is_cluster
+ );
}
function decimalStep(number) {
var digits = ((Number(number)).toFixed(20)).replace(/^-?\d*\.?|0+$/g, "").length;