--
-- (C) 2013-17 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
if(ntop.isPro()) then
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path
require "snmp_utils"
end
require "lua_utils"
require "graph_utils"
require "alert_utils"
local network = _GET["network"]
local page = _GET["page"]
interface.select(ifname)
ifstats = interface.getStats()
ifId = ifstats.id
local network_name = ntop.getNetworkNameById(tonumber(network))
local network_vlan = tonumber(_GET["vlan"])
if network_vlan == nil then network_vlan = 0 end
sendHTTPHeader('text/html; charset=iso-8859-1')
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc")
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
if(network == nil) then
print("
Network parameter is missing (internal error ?)
")
return
end
rrdname = dirs.workingdir .. "/" .. ifId .. "/subnetstats/" .. getPathFromKey(network_name) .. "/bytes.rrd"
if(not ntop.exists(rrdname)) then
print("
No available stats for network "..network_name.."
")
return
end
--[[
Process form data
--]]
if(_POST["flow_rate_alert_threshold"] ~= nil) then
if (tonumber(_POST["flow_rate_alert_threshold"]) ~= nil) then
page = "config"
local val = ternary(_POST["flow_rate_alert_threshold"] ~= "0", _POST["flow_rate_alert_threshold"], "25")
ntop.setCache('ntopng.prefs.'..network_name..':'..tostring(network_vlan)..'.flow_rate_alert_threshold', val)
-- interface.loadHostAlertPrefs(network_name, network_vlan) TODO: decide to implement it for networks
end
end
if(_POST["syn_alert_threshold"] ~= nil) then
if (tonumber(_POST["syn_alert_threshold"]) ~= nil) then
page = "config"
val = ternary(_POST["syn_alert_threshold"] ~= "0", _POST["syn_alert_threshold"], "10")
ntop.setCache('ntopng.prefs.'..network_name..':'..tostring(network_vlan)..'.syn_alert_threshold', val)
-- interface.loadHostAlertPrefs(network_name, network_vlan) TODO: decide to implement it for networks
end
end
if(_POST["flows_alert_threshold"] ~= nil) then
if (tonumber(_POST["flows_alert_threshold"]) ~= nil) then
page = "config"
val = ternary(_POST["flows_alert_threshold"] ~= "0", _POST["flows_alert_threshold"], "32768")
ntop.setCache('ntopng.prefs.'..network_name..':'..tostring(network_vlan)..'.flows_alert_threshold', val)
-- interface.loadHostAlertPrefs(network_name, network_vlan) TODO: decide to implement it for networks
end
end
if _POST["re_arm_minutes"] ~= nil then
page = "config"
ntop.setHashCache(get_re_arm_alerts_hash_name(), get_re_arm_alerts_hash_key(ifId, network_name), _POST["re_arm_minutes"])
end
--[[
Create Menu Bar with buttons
--]]
local nav_url = ntop.getHttpPrefix().."/lua/network_details.lua?network="..tonumber(network)
print [[
]]
--[[
Selectively render information pages
--]]
if page == "historical" then
if(_GET["rrd_file"] == nil) then
rrdfile = "bytes.rrd"
else
rrdfile=_GET["rrd_file"]
end
host_url = ntop.getHttpPrefix()..'/lua/network_details.lua?ifname='..ifId..'&network='..network..'&page=historical'
drawRRD(ifId, 'net:'..network_name, rrdfile, _GET["graph_zoom"], host_url, 1, _GET["epoch"], nil, makeTopStatsScriptsArray())
elseif (page == "config") then
local re_arm_minutes = ""
if(isAdministrator()) then
trigger_alerts = _POST["trigger_alerts"]
if(trigger_alerts ~= nil) then
if(trigger_alerts == "true") then
ntop.delHashCache(get_alerts_suppressed_hash_name(ifname), network_name)
else
ntop.setHashCache(get_alerts_suppressed_hash_name(ifname), network_name, trigger_alerts)
end
end
end
re_arm_minutes = ntop.getHashCache(get_re_arm_alerts_hash_name(), get_re_arm_alerts_hash_key(ifId, network_name))
if re_arm_minutes == "" then re_arm_minutes=default_re_arm_minutes end
local flow_rate_alter_thresh = ntop.getCache('ntopng.prefs.'..network_name..':'..tostring(network_vlan)..'.flow_rate_alert_threshold')
local syn_alert_thresh = ntop.getCache('ntopng.prefs.'..network_name..':'..tostring(network_vlan)..'.syn_alert_threshold')
local flows_alert_thresh = ntop.getCache('ntopng.prefs.'..network_name..':'..tostring(network_vlan)..'.flows_alert_threshold')
if (flow_rate_alter_thresh == nil or flow_rate_alter_thresh == "") then flow_rate_alter_thresh = 25 end
if (syn_alert_thresh == nil or syn_alert_thresh == "") then syn_alert_thresh = 10 end
if (flows_alert_thresh == nil or flows_alert_thresh == "") then flows_alert_thresh = 32768 end
print("
\n")
print("
Network Flow Alert Threshold
\n")
print [[
]]
print[[
Max number of new flows/sec over which the network is considered to be flooding (Experimental). Default: 25.
]]
print[[
]]
print("
Network SYN Alert Threshold
\n")
print [[
]]
print[[
Max number of sent TCP SYN packets/sec over which the network is considered to be flooding (Experimental). Default: 10.
]]
print[[
]]
print("
Network Flows Threshold
\n")
print [[
]]
print[[
Max number of flows over which the network is considered to be flooding (Experimental). Default: 32768.
]]
print[[
]]
local suppressAlerts = ntop.getHashCache(get_alerts_suppressed_hash_name(ifname), network_name)
if((suppressAlerts == "") or (suppressAlerts == nil) or (suppressAlerts == "true")) then
alerts_checked = 'checked="checked"'
alerts_value = "false" -- Opposite
else
alerts_checked = ""
alerts_value = "true" -- Opposite
end
print [[
Network Alerts
')
print('
')
print [[
]]
print[[
]]
print("
")
elseif(page == "alerts") then
drawAlertSourceSettings(network_name,
i18n("show_alerts.network_delete_config_btn"), i18n("show_alerts.network_delete_config_confirm"),
"network_details.lua", {network=network})
elseif page == "traffic_report" then
dofile(dirs.installdir .. "/pro/scripts/lua/enterprise/traffic_report.lua")
end
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")