Skip to content

Commit

Permalink
Added netbox functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoBiscosi committed Jun 21, 2024
1 parent 4fbe62a commit f71507f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 25 deletions.
2 changes: 2 additions & 0 deletions include/Prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Prefs {
#ifdef NTOPNG_PRO
ndpi_bitmap* modbus_allowed_function_codes;
u_int modbus_too_many_exceptions;
bool netbox_enabled;
#endif
ServiceAcceptance behaviour_analysis_learning_status_during_learning,
behaviour_analysis_learning_status_post_learning;
Expand Down Expand Up @@ -690,6 +691,7 @@ class Prefs {
inline u_int32_t getIEC60870LearingPeriod() { return (iec60870_learning_period); };
inline u_int32_t getModbusLearingPeriod() { return (modbus_learning_period); };
#ifdef NTOPNG_PRO
inline bool isNetBoxEnabled() { return netbox_enabled; };
inline ndpi_bitmap* getModbusAllowedFunctionCodes() { return (modbus_allowed_function_codes); };
inline void setModbusTooManyExceptionsThreshold(u_int v) { modbus_too_many_exceptions = v; }
inline u_int getModbusTooManyExceptionsThreshold() { return(modbus_too_many_exceptions); }
Expand Down
9 changes: 4 additions & 5 deletions include/ntop_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,11 +759,10 @@
#define CONST_DEFAULT_BEHAVIOUR_ANALYSIS_LEARNING_PERIOD \
7200 // 2 hours by default

#define CONST_PREFS_NETBOX_ACTIVATION_URL \
NTOPNG_PREFS_PREFIX ".netbox_activation_url"

#define CONST_PREFS_NETBOX_PERSONAL_ACCESS_TOKEN \
NTOPNG_PREFS_PREFIX ".netbox_personal_access_token"
#define CONST_PREFS_NETBOX_ENABLED \
NTOPNG_PREFS_PREFIX ".toggle_netbox"
#define CONST_DEFAULT_NETBOX_ENABLED \
0 // disabled by default

#define CONST_PREFS_USE_MAC_IN_FLOW_KEY \
NTOPNG_PREFS_PREFIX ".use_mac_in_flow_key"
Expand Down
4 changes: 2 additions & 2 deletions scripts/locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6861,9 +6861,9 @@ local lang = {
["toggle_active_local_host_cache_enabled_description"] = "Toggle the creation of cache entries for active local hosts. Caching active local hosts periodically can be useful to protect host counters against failures (e.g., power losses). This is particularly important for local hosts that seldomly go idle as it guarantees that their counters will be cached after the specified time interval.",
["toggle_active_local_host_cache_enabled_title"] = "Active Local Hosts Cache",
["toggle_active_monitoring_description"] = "Toggle the Active Monitoring",
["toggle_assets_inventory_description"] = "Toggle Assets Inventory",
["toggle_netbox_description"] = "Toggle NetBox integration",
["toggle_active_monitoring_title"] = "Active Monitoring",
["toggle_assets_inventory_title"] = "Assets Inventory",
["toggle_netbox_title"] = "NetBox",
["toggle_alert_syslog_description"] = "Toggle alerts logging to system syslog.",
["toggle_alert_syslog_title"] = "Toggle Syslog Notification",
["toggle_alerts_notifications_description"] = "Toggle the reporting of alert to third-party endpoints.",
Expand Down
19 changes: 8 additions & 11 deletions scripts/lua/admin/prefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2255,36 +2255,33 @@ if auth.has_capability(auth.capabilities.preferences) then

local elementToSwitch = {"netbox_activation_url", "netbox_personal_access_token"}

if ntop.getPref("ntopng.prefs.toggle_assets_inventory") == "1" then
if ntop.getPref("ntopng.prefs.toggle_netbox") == "1" then
showNetboxConfiguration = true
else
showNetboxConfiguration = false
end

prefsToggleButton(subpage_active, {
field = "toggle_assets_inventory",
field = "toggle_netbox",
default = "0",
pref = "toggle_assets_inventory_title",
pref = "toggle_netbox",
to_switch = elementToSwitch,
disabled = disabled
})

--(label, comment, prekey, key, default_value, _input_type, showEnabled, disableAutocomplete, allowURLs, extra)
prefsInputFieldPrefs(subpage_active.entries["netbox_activation_url"].title,
subpage_active.entries["netbox_activation_url"].description, "ntopng.prefs.netbox_activation_url", "netbox_activation_url",
"", false, nil, nil, nil, {
subpage_active.entries["netbox_activation_url"].description, "ntopng.prefs.", "netbox_activation_url",
"", false, showNetboxConfiguration, nil, nil, {
attributes = {
spellcheck = "false",
},
hidden = not showNetboxConfiguration,
disabled = disabled
})

prefsInputFieldPrefs(subpage_active.entries["netbox_personal_access_token"].title,
subpage_active.entries["netbox_personal_access_token"].description, "ntopng.prefs.netbox_personal_access_token", "netbox_personal_access_token", "",
"", nil, nil, nil, {
hidden = showNetboxConfiguration,
})

subpage_active.entries["netbox_personal_access_token"].description, "ntopng.prefs.", "netbox_personal_access_token", "",
"", showNetboxConfiguration, nil, nil, {})

if (disabled) then
prefsInformativeField(i18n("notes"), i18n("enterpriseOnly"))
Expand Down
4 changes: 2 additions & 2 deletions scripts/lua/modules/http_lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2164,9 +2164,9 @@ local known_parameters = {
["stats"] = validateBool,
["rtt_threshold"] = validateNumber,
["bandwidth_threshold"] = validateNumber,
["toggle_assets_inventory"] = validateBool,
["toggle_netbox"] = validateBool,
["netbox_activation_url"] = validateSingleWord,
["netbox_personal_access_token"] = validateToken,
["netbox_personal_access_token"] = validateSingleWord,

-- Service Map
["service_id"] = validateNumber,
Expand Down
8 changes: 4 additions & 4 deletions scripts/lua/modules/prefs_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ local menu_subpages = {{
label = i18n("prefs.assets_inventory"),
advanced = false,
pro_only = false,
hidden = false,
hidden = not ntop.isEnterpriseXL(),
entries = {
toggle_assets_inventory = {
title = i18n("prefs.toggle_assets_inventory_title"),
description = i18n("prefs.toggle_assets_inventory_description")
toggle_netbox = {
title = i18n("prefs.toggle_netbox_title"),
description = i18n("prefs.toggle_netbox_description")
},
netbox_activation_url = {
title = i18n("prefs.netbox_activation_url_title"),
Expand Down
21 changes: 21 additions & 0 deletions scripts/lua/modules/prefs_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,24 @@ end
function prefsSkipRedis(skip)
skip_redis = skip
end

function isNetBoxEnabled()
if not ntop.isEnterpriseXL() then
return false
end
return (ntop.getPref("ntopng.prefs.toggle_netbox") == "1")
end

function getNetBoxURL()
if not ntop.isEnterpriseXL() or not ntop.getPref("ntopng.prefs.toggle_netbox") == "1" then
return ""
end
return ntop.getPref("ntopng.prefs.netbox_activation_url")
end

function getNetBoxToken()
if not ntop.isEnterpriseXL() or not ntop.getPref("ntopng.prefs.toggle_netbox") == "1" then
return ""
end
return ntop.getPref("ntopng.prefs.netbox_personal_access_token")
end
7 changes: 6 additions & 1 deletion src/Prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Prefs::Prefs(Ntop *_ntop) {
scripts_dir = strdup(CONST_DEFAULT_SCRIPTS_DIR);
callbacks_dir = strdup(CONST_DEFAULT_CALLBACKS_DIR);
#ifdef NTOPNG_PRO
netbox_enabled = CONST_DEFAULT_NETBOX_ENABLED;
pro_callbacks_dir = strdup(CONST_DEFAULT_PRO_CALLBACKS_DIR);
create_labels_logfile = false;
#endif
Expand Down Expand Up @@ -1046,6 +1047,11 @@ void Prefs::reloadPrefsFromRedis() {
refreshDbDumpPrefs();
refreshBehaviourAnalysis();

#ifdef NTOPNG_PRO
netbox_enabled = getDefaultPrefsValue(CONST_PREFS_NETBOX_ENABLED,
CONST_DEFAULT_NETBOX_ENABLED);
#endif

#ifdef PREFS_RELOAD_DEBUG
ntop->getTrace()->traceEvent(TRACE_NORMAL,
"Updated IPs "
Expand Down Expand Up @@ -2780,7 +2786,6 @@ void Prefs::lua(lua_State *vm) {
devices_learning_period);
lua_push_uint64_table_entry(vm, "host_port_learning_period",
host_port_learning_period);

lua_push_str_table_entry(
vm, "safe_search_dns",
Utils::intoaV4(ntohl(safe_search_dns_ip), buf, sizeof(buf)));
Expand Down

0 comments on commit f71507f

Please sign in to comment.