mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-28 23:19:33 +00:00
Users scripts api changes and initial documentation
This commit is contained in:
parent
e05f9aa4f4
commit
ffd3b4c1ee
57 changed files with 489 additions and 872 deletions
|
|
@ -931,7 +931,7 @@ end
|
|||
-- An alert check function which performs threshold checks of a value
|
||||
-- against a configured threshold and generates a threshold_cross alert
|
||||
-- if the value is above the threshold.
|
||||
-- A check_module (see check_modules.lua) must implement:
|
||||
-- A user script (see user_scripts.lua) must implement:
|
||||
-- get_threshold_value(granularity, entity_info)
|
||||
-- A function, which returns the current value to be compared agains the threshold
|
||||
-- The check_module may implement an additional threshold_type_builder function which
|
||||
|
|
@ -1042,97 +1042,6 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
function alerts_api.threshold_cross_input_builder(gui_conf, input_id, value)
|
||||
value = value or {}
|
||||
local gt_selected = ternary((value.operator or gui_conf.field_operator) == "gt", ' selected="selected"', '')
|
||||
local lt_selected = ternary((value.operator or gui_conf.field_operator) == "lt", ' selected="selected"', '')
|
||||
local input_op = "op_" .. input_id
|
||||
local input_val = "value_" .. input_id
|
||||
|
||||
return(string.format([[<select name="%s">
|
||||
<option value="gt"%s ]] .. (ternary(gui_conf.field_operator == "lt", "hidden", "")) .. [[>></option>
|
||||
<option value="lt"%s ]] .. (ternary(gui_conf.field_operator == "gt", "hidden", "")) .. [[><</option>
|
||||
</select> <input type="number" class="text-right form-control" min="%s" max="%s" step="%s" style="display:inline; width:12em;" name="%s" value="%s"/> <span>%s</span>]],
|
||||
input_op, gt_selected, lt_selected,
|
||||
gui_conf.field_min or "0", gui_conf.field_max or "", gui_conf.field_step or "1",
|
||||
input_val, value.edge, i18n(gui_conf.i18n_field_unit))
|
||||
)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local function build_on_off_toggle(submit_field, active)
|
||||
local on_value = "on"
|
||||
local off_value = "off"
|
||||
local value
|
||||
local on_color = "success"
|
||||
local off_color = "danger"
|
||||
|
||||
local on_active
|
||||
local off_active
|
||||
|
||||
if active then
|
||||
|
||||
value = on_value
|
||||
on_active = "btn-"..on_color.." active"
|
||||
off_active = "btn-default"
|
||||
else
|
||||
value = off_value
|
||||
on_active = "btn-default"
|
||||
off_active = "btn-"..off_color.." active"
|
||||
end
|
||||
|
||||
return [[
|
||||
<div class="btn-group btn-toggle">
|
||||
<button type="button" onclick="]]..submit_field..[[_on_fn()" id="]]..submit_field..[[_on_id" class="btn btn-sm ]]..on_active..[[">On</button>
|
||||
<button type="button" onclick="]]..submit_field..[[_off_fn()" id="]]..submit_field..[[_off_id" class="btn btn-sm ]]..off_active..[[">Off</button>
|
||||
</div>
|
||||
<input type=hidden id="]]..submit_field..[[_input" name="]]..submit_field..[[" value="]]..value..[["/>
|
||||
<script>
|
||||
|
||||
|
||||
function ]]..submit_field..[[_on_fn() {
|
||||
var class_on = document.getElementById("]]..submit_field..[[_on_id");
|
||||
var class_off = document.getElementById("]]..submit_field..[[_off_id");
|
||||
class_on.removeAttribute("class");
|
||||
class_off.removeAttribute("class");
|
||||
class_on.setAttribute("class", "btn btn-sm btn-]]..on_color..[[ active");
|
||||
class_off.setAttribute("class", "btn btn-sm btn-default");
|
||||
$("#]]..submit_field..[[_input").val("]]..on_value..[[").trigger('change');
|
||||
}
|
||||
|
||||
function ]]..submit_field..[[_off_fn() {
|
||||
var class_on = document.getElementById("]]..submit_field..[[_on_id");
|
||||
var class_off = document.getElementById("]]..submit_field..[[_off_id");
|
||||
class_on.removeAttribute("class");
|
||||
class_off.removeAttribute("class");
|
||||
class_on.setAttribute("class", "btn btn-sm btn-default");
|
||||
class_off.setAttribute("class", "btn btn-sm btn-]]..off_color..[[ active");
|
||||
$("#]]..submit_field..[[_input").val("]]..off_value..[[").trigger('change');
|
||||
}
|
||||
</script>
|
||||
]]
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function alerts_api.checkbox_input_builder(gui_conf, input_id, value)
|
||||
local built = build_on_off_toggle(input_id, value == 1)
|
||||
|
||||
return built
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function alerts_api.flow_checkbox_input_builder(check_module)
|
||||
local input_id = string.format("enabled_%s", check_module.key)
|
||||
local built = build_on_off_toggle(input_id, check_module.enabled)
|
||||
|
||||
return built
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local function getEntityDisabledAlertsBitmapKey(ifid, entity, entity_val)
|
||||
return string.format("ntopng.prefs.alerts.ifid_%d.disabled_alerts.__%s__%s", ifid, entity, entity_val)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue