mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 07:59:35 +00:00
Added hosts explored on the main menu
This commit is contained in:
parent
c458948354
commit
ec4d55ff04
3 changed files with 146 additions and 30 deletions
|
|
@ -15,33 +15,88 @@ local info = ntop.getInfo()
|
|||
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
||||
page_utils.print_header(i18n("about.about_x", { product=info.product }))
|
||||
page_utils.print_header("Host Explorer")
|
||||
|
||||
active_page = "about"
|
||||
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
|
||||
|
||||
print("<hr /><h2>Host Explorer</h2>")
|
||||
|
||||
-- https://www.d3-graph-gallery.com/graph/bubble_template.html
|
||||
|
||||
|
||||
local modes = {
|
||||
{ mode = 0, label = "All Flows" },
|
||||
{ mode = 1, label = "Unreacheable Flows" },
|
||||
{ mode = 2, label = "Anomalous Flows" },
|
||||
{ mode = 3, label = "DNS Queries vs Replies" },
|
||||
}
|
||||
|
||||
|
||||
local show_remote = true
|
||||
local local_hosts = { }
|
||||
local remote_hosts = {}
|
||||
local max_r = 0
|
||||
local remote_hosts = { }
|
||||
local max_r = 0
|
||||
local local_label = "Local Hosts"
|
||||
local remote_label = "Remote Hosts"
|
||||
local x_label
|
||||
local y_label
|
||||
local bubble_mode = tonumber(_GET["bubble_mode"]) or 0
|
||||
|
||||
if(bubble_mode == 0) then
|
||||
x_label = 'Flows as Server'
|
||||
y_label = 'Flows as Client'
|
||||
elseif(bubble_mode == 1) then
|
||||
x_label = 'Unreachable Flows as Server'
|
||||
y_label = 'Unreachable Flows as Client'
|
||||
elseif(bubble_mode == 2) then
|
||||
x_label = 'Anomalous Flows as Server'
|
||||
y_label = 'Anomalous Flows as Client'
|
||||
elseif(bubble_mode == 3) then
|
||||
x_label = 'Positive DNS Replies Received'
|
||||
y_label = 'DNS Queries Sent'
|
||||
end
|
||||
|
||||
function string.starts(String,Start)
|
||||
return string.sub(String,1,string.len(Start))==Start
|
||||
end
|
||||
|
||||
function processHost(hostname, host)
|
||||
-- io.write("================================\n")
|
||||
-- io.write(hostname.."\n")
|
||||
-- tprint(host)
|
||||
local line = nil
|
||||
|
||||
local host_name = hostinfo2hostkey(host)
|
||||
--io.write("================================\n")
|
||||
--io.write(hostname.."\n")
|
||||
--tprint(host)
|
||||
|
||||
local label = hostinfo2hostkey(host)
|
||||
|
||||
if((host_name == nil) or (host_name == "")) then host_name = hostname end
|
||||
local line = { link = hostname, label = host_name, x = host["total_flows.as_server"], y = host["total_flows.as_client"], r = host["bytes.sent"]+host["bytes.rcvd"] }
|
||||
if(line.r > max_r) then max_r = line.r end
|
||||
|
||||
if(host.localhost) then
|
||||
table.insert(local_hosts, line)
|
||||
else
|
||||
table.insert(remote_hosts, line)
|
||||
if((label == nil) or (string.len(label) == 0) or string.starts(label, "@")) then label = hostname end
|
||||
|
||||
if(bubble_mode == 0) then
|
||||
line = { link = hostname, label = label, x = host["active_flows.as_server"], y = host["active_flows.as_client"], r = host["bytes.sent"]+host["bytes.rcvd"] }
|
||||
elseif(bubble_mode == 1) then
|
||||
if(host["unreachable_flows.as_server"] + host["unreachable_flows.as_client"] > 0) then
|
||||
line = { link = hostname, label = label, x = host["unreachable_flows.as_server"], y = host["unreachable_flows.as_client"], r = host["bytes.sent"]+host["bytes.rcvd"] }
|
||||
end
|
||||
elseif(bubble_mode == 2) then
|
||||
if(host["anomalous_flows.as_server"] + host["anomalous_flows.as_client"] > 0) then
|
||||
line = { link = hostname, label = label, x = host["anomalous_flows.as_server"], y = host["anomalous_flows.as_client"], r = host["bytes.sent"]+host["bytes.rcvd"] }
|
||||
end
|
||||
elseif(bubble_mode == 3) then
|
||||
-- if(hostname == "192.168.1.65") then tprint(host) end
|
||||
if((host["dns"] ~= nil) and ((host["dns"]["sent"]["num_queries"]+host["dns"]["rcvd"]["num_queries"]) > 0)) then
|
||||
line = { link = hostname, label = label, x = host["dns"]["rcvd"]["num_replies_ok"], y = host["dns"]["sent"]["num_queries"], r = host["dns"]["rcvd"]["num_replies_error"] }
|
||||
end
|
||||
end
|
||||
|
||||
if(line ~= nil) then
|
||||
if(line.r > max_r) then max_r = line.r end
|
||||
|
||||
if(host.localhost) then
|
||||
table.insert(local_hosts, line)
|
||||
else
|
||||
table.insert(remote_hosts, line)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -64,9 +119,25 @@ end
|
|||
local local_js = json.encode(local_hosts)
|
||||
local remote_js = json.encode(remote_hosts)
|
||||
|
||||
print [[
|
||||
print [[
|
||||
|
||||
<script type="text/javascript" src="/js/Chart.bundle.min.js"></script>
|
||||
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Visualization
|
||||
<span class="caret"></span></button>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
|
||||
]]
|
||||
|
||||
for i,v in pairs(modes) do
|
||||
print('<li role="presentation"><a role="menuitem" tabindex="-1" href="?bubble_mode='..tostring(i-1)..'">'..v.label..'</a></li>\n')
|
||||
end
|
||||
|
||||
print [[
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript" src="/js/Chart.bundle.min.js"></script>
|
||||
|
||||
<div class="container" width="200" height="200>
|
||||
<div class="row">
|
||||
|
|
@ -77,21 +148,55 @@ print [[
|
|||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
var chartColors = {
|
||||
red: 'rgb(255, 99, 132)',
|
||||
orange: 'rgb(255, 159, 64)',
|
||||
yellow: 'rgb(255, 205, 86)',
|
||||
green: 'rgb(75, 192, 192)',
|
||||
blue: 'rgb(54, 162, 235)',
|
||||
purple: 'rgb(153, 102, 255)',
|
||||
grey: 'rgb(201, 203, 207)'
|
||||
};
|
||||
|
||||
var ctx = document.getElementById("canvas");
|
||||
var data = {
|
||||
datasets: [{
|
||||
label: 'Local Hosts',
|
||||
label: ']] print(local_label) print [[',
|
||||
data: ]] print(local_js) print [[,
|
||||
backgroundColor: "#FF6384"
|
||||
backgroundColor: chartColors.purple,
|
||||
borderWidth: function(context) {
|
||||
return Math.min(Math.max(1, context.datasetIndex + 1), 8);
|
||||
},
|
||||
hoverBackgroundColor: 'transparent',
|
||||
hoverBackgroundColor: 'transparent',
|
||||
hoverBorderColor: function(context) {
|
||||
return chartColors[context.datasetIndex];
|
||||
},
|
||||
hoverBorderWidth: function(context) {
|
||||
var value = context.dataset.data[context.dataIndex];
|
||||
return Math.round(8 * value.v / 1000);
|
||||
},
|
||||
},
|
||||
]]
|
||||
|
||||
if(show_remote == true) then
|
||||
print [[
|
||||
{
|
||||
label: 'Remote Hosts',
|
||||
label: ']] print(remote_label) print [[',
|
||||
data: ]] print(remote_js) print [[,
|
||||
backgroundColor: "#63FF84"
|
||||
backgroundColor: chartColors.orange,
|
||||
borderWidth: function(context) {
|
||||
return Math.min(Math.max(1, context.datasetIndex + 1), 8);
|
||||
},
|
||||
hoverBackgroundColor: 'transparent',
|
||||
hoverBorderColor: function(context) {
|
||||
return chartColors[context.datasetIndex];
|
||||
},
|
||||
hoverBorderWidth: function(context) {
|
||||
var value = context.dataset.data[context.dataIndex];
|
||||
return Math.round(8 * value.v / 1000);
|
||||
},
|
||||
}
|
||||
]]
|
||||
end
|
||||
|
|
@ -104,15 +209,15 @@ print [[
|
|||
data: data,
|
||||
type: "bubble",
|
||||
options: {
|
||||
scales: { xAxes: [{ display: true, scaleLabel: { display: true, labelString: 'Flows as Server' } }],
|
||||
yAxes: [{ display: true, scaleLabel: { display: true, labelString: 'Flows as Client' } }]
|
||||
scales: { xAxes: [{ display: true, scaleLabel: { display: true, labelString: ']] print(x_label) print [[' } }],
|
||||
yAxes: [{ display: true, scaleLabel: { display: true, labelString: ']] print(y_label) print [[' } }]
|
||||
},
|
||||
|
||||
elements: {
|
||||
points: {
|
||||
borderWidth: 1,
|
||||
borderColor: 'rgb(0, 0, 0)'
|
||||
}
|
||||
borderWidth: 1,
|
||||
borderColor: 'rgb(0, 0, 0)'
|
||||
}
|
||||
},
|
||||
onClick: function(e) {
|
||||
var element = this.getElementAtEvent(e);
|
||||
|
|
@ -134,13 +239,17 @@ tooltips: {
|
|||
},
|
||||
|
||||
label: function(tooltipItem, data) {
|
||||
var dataset = data['datasets'][0];
|
||||
var host = dataset['data'][tooltipItem['index'] ];
|
||||
return(host.label);
|
||||
var dataset = data['datasets'][tooltipItem.datasetIndex];
|
||||
var idx = tooltipItem['index'];
|
||||
var host = dataset['data'][idx];
|
||||
if(host)
|
||||
return(host.label);
|
||||
else
|
||||
return('');
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue