Add fileserver context and map controls
This commit is contained in:
@@ -245,26 +245,31 @@ def organization(organization_id):
|
||||
)
|
||||
|
||||
|
||||
def load_network_flows():
|
||||
def load_network_flows(days=14):
|
||||
days = max(1, min(days, 90))
|
||||
with db_connection() as connection, connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT machine_name, received_at, payload
|
||||
FROM ocsentinel.current_device_status
|
||||
WHERE received_at >= now() - interval '14 days'
|
||||
"""
|
||||
WHERE received_at >= now() - (%s * interval '1 day')
|
||||
""",
|
||||
(days,),
|
||||
)
|
||||
reports = cursor.fetchall()
|
||||
|
||||
flows = {}
|
||||
for machine_name, received_at, payload in reports:
|
||||
ninja_context = (payload or {}).get("NinjaOne") or {}
|
||||
organization_id = str(ninja_context.get("OrganizationId") or "unknown")
|
||||
organization_name = ninja_context.get("OrganizationName") or "Organisation unbekannt"
|
||||
for event in (payload or {}).get("Events", []):
|
||||
source_ip = event.get("SourceIp") or ""
|
||||
if not source_ip or source_ip in {"-", "127.0.0.1", "::1"}:
|
||||
continue
|
||||
account = event.get("Username") or "[unbekannt]"
|
||||
target = event.get("Target") or "Anmeldung"
|
||||
key = (source_ip, machine_name, account, target)
|
||||
key = (source_ip, machine_name, account, target, organization_id)
|
||||
entry = flows.setdefault(
|
||||
key,
|
||||
{
|
||||
@@ -272,6 +277,8 @@ def load_network_flows():
|
||||
"machine_name": machine_name,
|
||||
"account": account,
|
||||
"target": target,
|
||||
"organization_id": organization_id,
|
||||
"organization_name": organization_name,
|
||||
"count": 0,
|
||||
"last_seen": received_at,
|
||||
},
|
||||
@@ -290,19 +297,24 @@ def load_network_flows():
|
||||
|
||||
@app.get("/network")
|
||||
def network():
|
||||
flows, _, source_count, target_count = load_network_flows()
|
||||
days = request.args.get("days", 14, type=int)
|
||||
flows, _, source_count, target_count = load_network_flows(days)
|
||||
return render_template(
|
||||
"network.html",
|
||||
source_count=source_count,
|
||||
target_count=target_count,
|
||||
total_events=sum(entry["count"] for entry in flows),
|
||||
path_count=len(flows),
|
||||
days=max(1, min(days, 90)),
|
||||
organizations=sorted({(entry["organization_id"], entry["organization_name"]) for entry in flows}, key=lambda item: item[1]),
|
||||
event_types=sorted({entry["target"] for entry in flows}),
|
||||
)
|
||||
|
||||
|
||||
@app.get("/api/network")
|
||||
def network_api():
|
||||
flows, max_count, source_count, target_count = load_network_flows()
|
||||
days = request.args.get("days", 14, type=int)
|
||||
flows, max_count, source_count, target_count = load_network_flows(days)
|
||||
nodes = {}
|
||||
edges = []
|
||||
for index, flow in enumerate(flows):
|
||||
@@ -321,6 +333,8 @@ def network_api():
|
||||
"event_type": flow["target"],
|
||||
"last_seen": str(flow["last_seen"] or "-"),
|
||||
"machine_name": flow["machine_name"],
|
||||
"organization_id": flow["organization_id"],
|
||||
"organization_name": flow["organization_name"],
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user