--
-- (C) 2014-15 - ntop.org
--
-- This file contains the description of all functions
-- used to trigger host alerts
local verbose = false
-- notify ntopng upon preference changes
function notifyNtopng(key)
if key == nil then return end
-- notify runtime ntopng configuration changes
if string.starts(key, 'nagios') then
if verbose then io.write('notifying ntopng upon nagios pref change\n') end
ntop.reloadNagiosConfig()
end
end
-- ############################################
-- Runtime preference
function prefsInputField(label, comment, key, value, _input_type)
if(_GET[key] ~= nil) then
k = "ntopng.prefs."..key
v_s = _GET[key]
v = tonumber(v_s)
if(v ~= nil and (v > 0) and (v <= 86400)) then
ntop.setCache(k, tostring(v))
value = v
elseif (v_s ~= nil) then
ntop.setCache(k, v_s)
value = v_s
end
-- least but not last we ascynchronously notify the runtime ntopng instance for changes
notifyNtopng(key)
end
local input_type = "text"
if _input_type ~= nil then input_type = _input_type end
print('
| '..label..' '..comment..' | ')
print [[
|
]]
end
function toggleTableButton(label, comment, on_label, on_value, on_color , off_label, off_value, off_color, submit_field, redis_key, disabled)
if(_GET[submit_field] ~= nil) then
ntop.setCache(redis_key, _GET[submit_field])
value = _GET[submit_field]
notifyNtopng(submit_field)
else
value = ntop.getCache(redis_key)
end
if (disabled == true) then
disabled = 'disabled = ""'
else
disabled = ""
end
-- Read it anyway to
if(value == off_value) then
rev_value = on_value
on_active = "btn-default"
off_active = "btn-"..off_color.." active"
else
rev_value = off_value
on_active = "btn-"..on_color.." active"
off_active = "btn-default"
end
if(label ~= "") then print('| '..label..' '..comment..' | \n') end
print('\n')
if(label ~= "") then print(' |
') end
return(value)
end
function multipleTableButton(label, comment, array_labels, array_values, default_value, selected_color, submit_field, redis_key, disabled)
if(_GET[submit_field] ~= nil) then
ntop.setCache(redis_key, _GET[submit_field])
value = _GET[submit_field]
notifyNtopng(submit_field)
else
value = ntop.getCache(redis_key)
if(value == "") then
if(default_value ~= nil) then
ntop.setCache(redis_key, default_value)
value = default_value
end
end
end
if (disabled == true) then
disabled = 'disabled = ""'
else
disabled = ""
end
if(value ~= nil) then
if(label ~= "") then print('| '..label..' '..comment..' | \n') end
print('\n')
print('\n')
if(label ~= "") then print(' |
') end
end
return(value)
end
function prefsInputFieldWithParamCheck(label, comment, pre_key, key, value, _input_type, js_body_funtion_check)
if(_GET[key] ~= nil) then
k = pre_key.."."..key
v_s = _GET[key]
v = tonumber(v_s)
if(v ~= nil and (v > 0) and (v <= 86400)) then
ntop.setCache(k, tostring(v))
value = v
elseif (v_s ~= nil) then
-- fix for ldap preference
v_s = string.gsub(v_s, "ldaps:__", "ldaps://")
v_s = string.gsub(v_s, "ldap:__", "ldap://")
ntop.setCache(k, v_s)
value = v_s
end
-- least but not last we ascynchronously notify the runtime ntopng instance for changes
notifyNtopng(key)
end
local input_type = "text"
if _input_type ~= nil then input_type = _input_type end
print('| '..label..' '..comment..' | ')
print [[
|
]]
end