From 9a4f3fba990de73ce1d90dcd6009e3bb9e41e397 Mon Sep 17 00:00:00 2001 From: Chester Enright Date: Mon, 18 Sep 2023 13:51:03 -0500 Subject: [PATCH] feat: wip - working tags and fields --- backend/serve.py | 8 ++++- frontend/labyrinth/src/views/Dashboard.vue | 41 ++++++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/backend/serve.py b/backend/serve.py index b8ec33b..d837bda 100755 --- a/backend/serve.py +++ b/backend/serve.py @@ -1436,7 +1436,13 @@ def find_service(name): watcher.send_alert(alert_name, metric_name, host_name, summary=summary) rc.set(key_name, time.time()) - service_results[service] = {"name": service, "state": result} + + service_results[service] = { + "name": service, + "state": result, + "found_service" : found_service, + "latest_metric" : latest_metric + } for item in service_results: host["services"] = [service_results[x] for x in service_results] diff --git a/frontend/labyrinth/src/views/Dashboard.vue b/frontend/labyrinth/src/views/Dashboard.vue index e9127b2..b78643f 100644 --- a/frontend/labyrinth/src/views/Dashboard.vue +++ b/frontend/labyrinth/src/views/Dashboard.vue @@ -407,10 +407,9 @@ export default { }); }, checkHostFilter(host, searches) { - console.log("Host:", host); - console.log("Searches:", searches); let retval = false; searches.forEach((search) => { + // Services Search if ( host.services .map((x) => (x ? x.name.toLowerCase() : "")) @@ -418,9 +417,47 @@ export default { ) { retval = true; } + // Open Ports Search if (host.open_ports.indexOf(parseInt(search.port)) != -1) { retval = true; } + + // Tags Search + try{ + search.tag.forEach(tag=>{ + host.services.map(x=>x.latest_metric).forEach(field=>{ + if (field["tags"] != undefined && [tag["tag"]] != undefined && String(field.tags[tag["tag"]]) == String(tag["value"])){ + retval = true + } + }) + }) + }catch(e){ + console.log("Tags parse failed") + console.log(e) + } + + // Fields Search + try{ + search.field.forEach(search_field=>{ + host.services.map(x=>x.latest_metric).forEach(field=>{ + if (field["fields"] != undefined && [search_field["fields"]] != undefined && String(field.fields[search_field["field"]]) == String(search_field["value"])){ + retval = true + } + }) + }) + }catch(e){ + console.log("Fields parse failed") + console.log(e) + } + + // Other search + const names = ["ip", "group", "host"] + names.forEach(found_name => { + if(host[found_name] == search[found_name]){ + retval = true + } + }) + }); return retval; },