Skip to content

Commit

Permalink
feat: wip - starting on smartbar
Browse files Browse the repository at this point in the history
  • Loading branch information
amunchet committed Sep 17, 2023
1 parent 8c09ff6 commit 469775d
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 45 deletions.
1 change: 1 addition & 0 deletions frontend/labyrinth/src/components/CustomDashboardsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
:style="generateHostStyle(host)"
>
<Host
v-if="host.display != false"
:ip="host.ip"
passed_class="main"
:icon="host.icon"
Expand Down
1 change: 1 addition & 0 deletions frontend/labyrinth/src/components/Host.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export default {
"host",
"monitor",
"monitored_only",
"display"
],
data() {
return {
Expand Down
184 changes: 139 additions & 45 deletions frontend/labyrinth/src/views/Dashboard.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<template>
<div class="dashboard">
<pre
class="text-left"
>{{parsed_data}}</pre>
<b-input v-model="smartbar" lazy />
<!-- Modals -->
<div class="overflow-hidden mb-4 pb-2">
<CreateEditSubnet :inp_subnet="selected_subnet" @update="loadData()" />
</div>
<CreateEditHost
:inp_host="selected_host"
@update="loadData()"
<CreateEditHost
:inp_host="selected_host"
@update="loadData()"
:all_ips="all_ips_computed"
/>
<HostMetric @update="loadData()" :data="selected_metric" />
Expand Down Expand Up @@ -180,7 +178,9 @@

<div class="flexed" v-if="subnet.display != 'summary'">
<Host
v-for="(host, k) in group.hosts"
v-for="(host, k) in group.hosts.filter(
(x) => x.display != false
)"
v-bind:key="k"
:ip="host.ip"
passed_class="main"
Expand All @@ -202,6 +202,7 @@
}
"
:host="host.host"
:display="host.display"
/>
</div>
</div>
Expand All @@ -227,6 +228,7 @@ export default {
data() {
return {
loading: false,
smartbar: "",
offsetTop: [],
full_data: [],
Expand Down Expand Up @@ -265,47 +267,122 @@ export default {
DoughnutChart,
},
computed: {
parsed_data: function(){
let data = this.full_data
parsed_data: function () {
let data = this.full_data;
if (this.smartbar == "") {
return this.sortSubnets(data);
}
let search = {
service: null,
host: null,
tag: [],
field: [],
port: null,
group: null,
ip: null,
invert: false,
};
let searches = [];
let search_parts = this.smartbar.split(" ").map((x) => x.toLowerCase());
search_parts.forEach((part) => {
let temp = JSON.parse(JSON.stringify(search));
let splits = part.split("=");
if (splits.length == 2) {
let left = splits[0];
let right = splits[1];
if (left.indexOf("tag:") != -1) {
let tag_name = left.replace("tag:", "");
temp.tag.push({ tag: tag_name, value: right });
} else if (left.indexOf("field:") != -1) {
let field_name = left.replace("field:", "");
temp.field.push({ field: field_name, value: right });
} else {
switch (left) {
case "service":
temp.service = right;
break;
case "host":
temp.host = right;
break;
case "port":
temp.port = right;
break;
case "group":
temp.group = right;
break;
case "ip":
temp.ip = right;
break;
default:
break;
}
}
searches.push(temp);
}
});
data.forEach((subnet) => {
if (subnet.groups) {
subnet.groups.forEach((group) => {
if (group.hosts) {
group.hosts.forEach((host) => {
if (this.checkHostFilter(host, searches)) {
host.display = true;
} else {
host.display = false;
}
});
}
});
}
});
return this.sortSubnets(data)
return data;
},
all_ips_computed: function(){
let retval = new Set()
this.full_data.forEach(subnet=>{
if(subnet.groups){
subnet.groups.forEach(group=>{
if(group.hosts){
group.hosts.forEach(host=>{
if(host.ip){
retval.add(host.ip)
all_ips_computed: function () {
let retval = new Set();
this.full_data.forEach((subnet) => {
if (subnet.groups) {
subnet.groups.forEach((group) => {
if (group.hosts) {
group.hosts.forEach((host) => {
if (host.ip) {
retval.add(host.ip);
}
})
});
}
})
});
}
})
return retval
}
});
return retval;
},
},
methods: {
capitalize: Helper.capitalize,
convertSubnet(subnet) {
try {
let splits = subnet.split(".");
let splits = subnet.split(".");
if (splits.length != 3) {
return -1;
}
let output = splits[0] * 100000 + splits[1] * 1000 + splits[2] * 10;
let output = splits[0] * 100000 + splits[1] * 1000 + splits[2] * 10;
return output;
} catch (e) {
return -1;
}
},
sortSubnets(all_items) {
// Returns 1 (a after b), 0 (a==b), -1 (b after a)
let temp = JSON.parse(JSON.stringify(all_items));
let temp = JSON.parse(JSON.stringify(all_items));
return temp.sort((a, b) => {
if (a.subnet == undefined || b.subnet == undefined) {
return 0;
Expand All @@ -314,17 +391,35 @@ export default {
if (this.convertSubnet(a.subnet) == this.convertSubnet(b.subnet)) {
return 0;
}
let outcome =
let outcome =
this.convertSubnet(a.subnet) < this.convertSubnet(b.subnet) ? -1 : 1;
return outcome;
});
},
checkHostFilter(host, searches) {
console.log("Host:", host);
console.log("Searches:", searches);
let retval = false;
searches.forEach((search) => {
if (
host.services
.map((x) => x.name.toLowerCase())
.indexOf(search.service.toLowerCase()) != -1
) {
retval = true;
}
if (host.open_ports.indexOf(parseInt(search.port)) != -1) {
retval = true;
}
});
return retval;
},
filterMonitored: function (group, subnet) {
if (!subnet) {
return group;
}
let temp = JSON.parse(JSON.stringify(group));
let temp = JSON.parse(JSON.stringify(group));
return temp.filter((x) => {
if (x.hosts == undefined) {
Expand All @@ -336,13 +431,12 @@ export default {
});
},
parseCommandLine: function(){
parseCommandLine: function () {
// Parses the command line
},
loadThemes: /* istanbul ignore next */ function () {
let auth = this.$auth;
let auth = this.$auth;
Helper.apiCall("themes", "", auth)
.then((res) => {
this.themes = res;
Expand All @@ -352,8 +446,8 @@ export default {
});
},
onDrop: /* istanbul ignore next */ function (name) {
let auth = this.$auth;
let url = this.dragged_ip;
let auth = this.$auth;
let url = this.dragged_ip;
if (name != "") {
url += "/" + name + "/";
}
Expand All @@ -367,12 +461,12 @@ export default {
},
processGroupChart: function (group) {
// Generates the datastructure for the doughnut chart for the group
let output = {};
let output = {};
output.labels = ["OK", "Warning", "Critical"];
let total_green = 0;
let total_orange = 0;
let total_red = 0;
let total_green = 0;
let total_orange = 0;
let total_red = 0;
// Process the group
group.hosts.forEach((host) => {
if (host.services != undefined) {
Expand Down Expand Up @@ -402,8 +496,8 @@ export default {
return output;
},
loadData: /* istanbul ignore next */ async function (showLoading) {
let auth = this.$auth;
let url = "";
let auth = this.$auth;
let url = "";
if (showLoading) {
this.loading = true;
url = "1";
Expand All @@ -422,8 +516,8 @@ export default {
this.originLinks = this.prepareOriginsLinks(this.full_data);
for (let i = 0; i < this.full_data.length; i++) {
let temp = this.full_data[i];
for (let i = 0; i < this.full_data.length; i++) {
let temp = this.full_data[i];
if (temp.groups != undefined) {
// Sort the groups
temp.groups.sort((prev, next) => {
Expand Down Expand Up @@ -457,7 +551,7 @@ export default {
});
},
findClass: function (subnet, isTitle) {
let retval = "";
let retval = "";
// Color
if (subnet.color != undefined && this.themes != []) {
Expand All @@ -481,7 +575,7 @@ export default {
},
prepareOriginsLinks: function (subnets) {
let retval = [];
let retval = [];
const width = 7;
subnets = subnets.filter(
(x) =>
Expand All @@ -494,7 +588,7 @@ export default {
);
subnets.forEach((x, idx) => {
let found = this.themes.find(
let found = this.themes.find(
(y) => x.links.color != undefined && y.name == x.links.color
);
if (!found) {
Expand Down

0 comments on commit 469775d

Please sign in to comment.