Exemple #1
0
def newDashboard():
    data = json.loads(jimi.api.request.data)
    monitor._monitorWebDashboard().new(
        {
            "ids": [{
                "accessID": jimi.api.g.sessionData["primaryGroup"],
                "read": True,
                "write": True,
                "delete": True
            }]
        }, data["dashboardName"])
    return {}, 200
Exemple #2
0
def mainPage():
    dashboards = monitor._monitorWebDashboard().query(
        sessionData=jimi.api.g.sessionData, query={},
        fields=["name"])["results"]
    return render_template("dashboards.html",
                           dashboards=dashboards,
                           CSRF=jimi.api.g.sessionData["CSRF"])
Exemple #3
0
def dashboardSetImage(dashboardID):
    image = request.args.get('image')
    dashboard = monitor._monitorWebDashboard().getAsClass(
        jimi.api.g.sessionData, id=dashboardID)
    if len(dashboard) == 1:
        dashboard = dashboard[0]
        dashboard.image = image
        dashboard.update(["image"])
        return {}, 200
    return {}, 404
Exemple #4
0
def dashboardPage():
    dashboardID = request.args.get('dashboardID')
    dashboard = monitor._monitorWebDashboard().getAsClass(
        jimi.api.g.sessionData, id=dashboardID)
    if len(dashboard) == 1:
        dashboard = dashboard[0]
        return render_template("dashboard.html",
                               CSRF=jimi.api.g.sessionData["CSRF"],
                               image=dashboard.image)
    return {}, 404
Exemple #5
0
def dashboardDeleteMonitorItem(dashboardID, dashboardObjectId):
    dashboard = monitor._monitorWebDashboard().getAsClass(
        jimi.api.g.sessionData, id=dashboardID)
    if len(dashboard) == 1:
        dashboard = dashboard[0]
    else:
        return {}, 404
    del dashboard.dashboardLayout[dashboardObjectId]
    dashboard.update(["dashboardLayout"])
    return {}, 200
Exemple #6
0
def dashboardDeleteLink(dashboardID, dashboardObjectFrom, dashboardObjectTo):
    dashboard = monitor._monitorWebDashboard().getAsClass(
        jimi.api.g.sessionData, id=dashboardID)
    if len(dashboard) == 1:
        dashboard = dashboard[0]
    else:
        return {}, 404
    linkID = "{0}->{1}".format(dashboardObjectFrom, dashboardObjectTo)
    del dashboard.monitorLinks[linkID]
    dashboard.update(["monitorLinks"])
    return {}, 200
Exemple #7
0
def dashboardMoveMonitorItem(dashboardID, dashboardObjectId, x, y):
    dashboard = monitor._monitorWebDashboard().getAsClass(
        jimi.api.g.sessionData, id=dashboardID)
    if len(dashboard) == 1:
        dashboard = dashboard[0]
    else:
        return {}, 404
    dashboard.dashboardLayout[dashboardObjectId]["x"] = int(x)
    dashboard.dashboardLayout[dashboardObjectId]["y"] = int(y)
    dashboard.update(["dashboardLayout"])
    return {}, 200
Exemple #8
0
def dashboardLinkMonitorItems(dashboardID, dashboardObjectFrom,
                              dashboardObjectTo):
    dashboard = monitor._monitorWebDashboard().getAsClass(
        jimi.api.g.sessionData, id=dashboardID)
    if len(dashboard) == 1:
        dashboard = dashboard[0]
    else:
        return {}, 404
    linkID = "{0}->{1}".format(dashboardObjectFrom, dashboardObjectTo)
    dashboard.monitorLinks[linkID] = {
        "id": linkID,
        "from": dashboardObjectFrom,
        "to": dashboardObjectTo
    }
    dashboard.update(["monitorLinks"])
    return {}, 200
Exemple #9
0
def dashboardAddMonitorItem(dashboardID, itemID, x, y):
    dashboard = monitor._monitorWebDashboard().getAsClass(
        jimi.api.g.sessionData, id=dashboardID)
    if len(dashboard) == 1:
        dashboard = dashboard[0]
    else:
        return {}, 404
    dashboardObjectId = str(uuid.uuid4())
    dashboard.dashboardLayout[dashboardObjectId] = {
        "id": dashboardObjectId,
        "monitorId": itemID,
        "x": x,
        "y": y
    }
    dashboard.update(["dashboardLayout"])
    return {}, 200
Exemple #10
0
def dashboardSizeMonitorItem(dashboardID, dashboardObjectId, size):
    dashboard = monitor._monitorWebDashboard().getAsClass(
        jimi.api.g.sessionData, id=dashboardID)
    if len(dashboard) == 1:
        dashboard = dashboard[0]
    else:
        return {}, 404
    try:
        if size == "+":
            dashboard.dashboardLayout[dashboardObjectId]["size"] += 1
        elif size == "-":
            dashboard.dashboardLayout[dashboardObjectId]["size"] -= 1
        if dashboard.dashboardLayout[dashboardObjectId]["size"] < 1:
            dashboard.dashboardLayout[dashboardObjectId]["size"] = 1
    except KeyError:
        dashboard.dashboardLayout[dashboardObjectId]["size"] = 3
    dashboard.update(["dashboardLayout"])
    return {}, 200
Exemple #11
0
def getDashboard(dashboardID):
    def getIcon(itemType, up):
        if itemType == "firewall":
            if up:
                return "/plugin/monitor/includes/firewall-up.svg"
            else:
                return "/plugin/monitor/includes/firewall-down.svg"
        elif itemType == "router":
            if up:
                return "/plugin/monitor/includes/router-up.svg"
            else:
                return "/plugin/monitor/includes/router-down.svg"
        elif itemType == "switch":
            if up:
                return "/plugin/monitor/includes/switch-up.svg"
            else:
                return "/plugin/monitor/includes/switch-down.svg"
        elif itemType == "loadbalancer":
            if up:
                return "/plugin/monitor/includes/loadbalancer-up.svg"
            else:
                return "/plugin/monitor/includes/loadbalancer-down.svg"
        elif itemType == "user":
            if up:
                return "/plugin/monitor/includes/user-up.svg"
            else:
                return "/plugin/monitor/includes/user-down.svg"
        elif itemType == "server":
            if up:
                return "/plugin/monitor/includes/server-up.svg"
            else:
                return "/plugin/monitor/includes/server-down.svg"
        elif itemType == "computer":
            if up:
                return "/plugin/monitor/includes/computer-up.svg"
            else:
                return "/plugin/monitor/includes/computer-down.svg"
        elif itemType == "ap":
            if up:
                return "/plugin/monitor/includes/ap-up.svg"
            else:
                return "/plugin/monitor/includes/ap-down.svg"
        elif itemType == "building":
            if up:
                return "/plugin/monitor/includes/building-up.svg"
            else:
                return "/plugin/monitor/includes/building-down.svg"
        elif itemType == "vpn":
            if up:
                return "/plugin/monitor/includes/vpn-up.svg"
            else:
                return "/plugin/monitor/includes/vpn-down.svg"
        elif itemType == "cloud":
            return "/plugin/monitor/includes/cloud.svg"
        return None

    dashboard = monitor._monitorWebDashboard().getAsClass(
        jimi.api.g.sessionData, id=dashboardID)
    if len(dashboard) == 1:
        dashboard = dashboard[0]
    else:
        return {}, 404
    data = json.loads(jimi.api.request.data)

    flowchartOperators = data["operators"]
    flowchartLinks = data["links"]

    flowchartResponse = {
        "operators": {
            "delete": {},
            "create": {},
            "update": {}
        },
        "links": {
            "delete": {},
            "create": {},
            "update": {}
        }
    }

    monitorItemsList = [
        jimi.db.ObjectId(y["monitorId"])
        for x, y in dashboard.dashboardLayout.items()
    ]

    monitorItems = monitor._monitor().query(
        query={"_id": {
            "$in": monitorItemsList
        }})["results"]
    monitorItemsDict = {}
    for monitorItem in monitorItems:
        monitorItemsDict[monitorItem["_id"]] = monitorItem

    for dashboardID, dashboardItem in dashboard.dashboardLayout.items():
        flowchartResponseType = "create"
        if dashboardID in flowchartOperators:
            # If it already exits then its an update
            flowchartResponseType = "update"
        # Setting position if it has changed since last pollTime
        name = monitorItemsDict[dashboardItem["monitorId"]]["name"]
        up = monitorItemsDict[dashboardItem["monitorId"]]["up"]
        try:
            size = dashboardItem["size"]
            if size < 1:
                size = 1
        except KeyError:
            size = 3
        node = {}
        color = "green"
        if not up:
            color = "red"
        if flowchartResponseType == "create":
            node["x"] = dashboardItem["x"]
            node["y"] = dashboardItem["y"]
            node["shape"] = "dot"
            try:
                node["image"] = getIcon(
                    monitorItemsDict[dashboardItem["monitorId"]]["itemType"],
                    up)
                if node["image"] == None:
                    del node["image"]
                else:
                    node["shape"] = "image"
            except KeyError:
                pass
            node["borderWidth"] = 1
            node["borderWidthSelected"] = 2.5
            node["font"] = {"size": 4 * size, "color": "#ddd", "multi": True}
            node["shadow"] = {
                "enabled": True,
                "color": 'rgba(0, 0, 0, 0.12)',
                "size": 10,
                "x": 5,
                "y": 5
            }
            node["label"] = name
            node["color"] = {
                "border": "#2e6da4",
                "background": color,
                "highlight": {
                    "background": "#2a2a2a"
                },
                "hover": {
                    "background": color
                }
            }
            node["size"] = 5 * size
        else:
            if dashboardItem["x"] != flowchartOperators[dashboardID]["node"][
                    "x"] or dashboardItem["y"] != flowchartOperators[
                        dashboardID]["node"]["y"]:
                node["x"] = dashboardItem["x"]
                node["y"] = dashboardItem["y"]
            if name != flowchartOperators[dashboardID]["name"]:
                node["label"] = name
            if color != flowchartOperators[dashboardID]["node"]["color"][
                    "background"]:
                try:
                    node["image"] = getIcon(
                        monitorItemsDict[dashboardItem["monitorId"]]
                        ["itemType"], up)
                    if node["image"] == None:
                        del node["image"]
                except KeyError:
                    pass
                node["color"] = {
                    "border": "#2e6da4",
                    "background": color,
                    "highlight": {
                        "background": "#2a2a2a"
                    },
                    "hover": {
                        "background": color
                    }
                }
            if 5 * size != flowchartOperators[dashboardID]["node"]["size"]:
                node["font"] = {
                    "size": 4 * size,
                    "color": "#ddd",
                    "multi": True
                }
                node["size"] = 5 * size
        if node:
            flowchartResponse["operators"][flowchartResponseType][
                dashboardID] = {
                    "_id": dashboardID,
                    "flowID": dashboardID,
                    "name": name,
                    "node": node
                }

        # Do any links need to be created
        linkPopList = []
        for linkKey, linkValue in dashboard.monitorLinks.items():
            if linkKey not in flowchartLinks.keys():
                if linkValue["to"] in flowchartOperators and linkValue[
                        "from"] in flowchartOperators:
                    flowchartResponse["links"]["create"][linkKey] = {
                        "from": linkValue["from"],
                        "to": linkValue["to"],
                        "color": "#3dbeff"
                    }
                else:
                    linkPopList.append(linkKey)
            elif flowchartLinks[linkKey]["color"] != color:
                flowchartResponse["links"]["update"][linkKey] = {
                    "from": linkValue["from"],
                    "to": linkValue["to"],
                    "color": "#3dbeff"
                }
        for link in linkPopList:
            del dashboard.monitorLinks[link]

    # Checking for deleted operators
    for flowchartOperator in flowchartOperators:
        if flowchartOperator not in dashboard.dashboardLayout:
            flowchartResponse["operators"]["delete"][flowchartOperator] = {
                "flowID": flowchartOperator
            }
    # Checking for deleted links
    for flowchartLink in flowchartLinks.keys():
        if flowchartLink not in dashboard.monitorLinks:
            flowchartResponse["links"]["delete"][flowchartLink] = {
                "linkName": flowchartLink
            }

    return flowchartResponse, 200
Exemple #12
0
def deleteDashboard():
    data = json.loads(jimi.api.request.data)
    monitor._monitorWebDashboard().api_delete(id=data["id"])
    return {}, 200