]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Use common query functions to get graph data 2364/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Sun, 22 Jul 2018 16:25:01 +0000 (19:25 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Sun, 22 Jul 2018 16:25:01 +0000 (19:25 +0300)
interface/js/app/graph.js
interface/js/app/stats.js

index bb643105688e56f864f53c798e6ba14e0f757fe5..356b006f7e06d42dc8ce6dde6d07345cf55361c8 100644 (file)
@@ -212,72 +212,58 @@ define(["jquery", "d3evolution", "footable"],
                 graphs.graph = initGraph();
             }
 
-            if (checked_server === "All SERVERS") {
-                rspamd.queryNeighbours("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; });
+            (function (callback) {
+                callback("graph",
+                    function (req_data) {
+                        if (checked_server !== "All SERVERS") {
+                            updateWidgets(req_data);
+                            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 neighbours_data = req_data
+                            .filter(function (d) { return d.status; }) // filter out unavailable neighbours
+                            .map(function (d) { return d.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)
-                                        };
-                                    })
-                                );
-                            });
-                            updateWidgets(data);
-                        });
-                    } else {
-                        updateWidgets(neighbours_data[0]);
-                    }
-                },
-                function (serv, jqXHR, textStatus, errorThrown) {
-                    var alert_status = serv.name + "_alerted";
+                        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 (!(alert_status in sessionStorage)) {
-                        sessionStorage.setItem(alert_status, true);
-                        rspamd.alertMessage("alert-error", "Cannot receive RRD data from: " +
-                        serv.name + ", error: " + errorThrown);
-                    }
-                }, "GET", {}, {}, {
-                    type: type
-                });
-                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);
+                            });
+                        } 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;
 
-            $.ajax({
-                dataType: "json",
-                type: "GET",
-                url: neighbours[checked_server].url + "graph",
-                jsonp: false,
-                data: {
-                    type: type
-                },
-                beforeSend: function (xhr) {
-                    xhr.setRequestHeader("Password", rspamd.getPassword());
-                },
-                success: function (data) {
-                    updateWidgets(data);
-                },
-                error: function (jqXHR, textStatus, errorThrown) {
-                    rspamd.alertMessage("alert-error", "Cannot receive throughput data: " +
-                    textStatus + " " + jqXHR.status + " " + errorThrown);
-                }
-            });
+                        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));
         };
 
         ui.setup = function () {
index c419342000f54a57dbaa907f827d54fda4b41433..8ef7e25d603081a6b4a8460343d970f7216f775d 100644 (file)
@@ -220,7 +220,7 @@ define(["jquery", "d3pie", "humanize"],
                     graphs.chart = getChart(rspamd, graphs.chart, checked_server);
                 },
                 function (serv, jqXHR, textStatus, errorThrown) {
-                    var alert_status = serv.name + "_alerted";
+                    var alert_status = "alerted_stats_" + serv.name;
 
                     if (!(alert_status in sessionStorage)) {
                         sessionStorage.setItem(alert_status, true);