File: behavior_utils.lua

package info (click to toggle)
ntopng 5.2.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 121,832 kB
  • sloc: javascript: 143,431; cpp: 71,175; ansic: 11,108; sh: 4,687; makefile: 911; python: 587; sql: 512; pascal: 234; perl: 118; ruby: 52; exp: 4
file content (104 lines) | stat: -rw-r--r-- 2,733 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
--
-- (C) 2020-22 - ntop.org
--

local rest_utils = require("rest_utils")
local json = require("dkjson")
local callback_utils = require("callback_utils")

local behavior_utils = {}
local redis_key = "changed_behavior_learning_setup"
local behavior_maps_key = "ntopng.prefs.is_behaviour_analysis_enabled"
local behavior_mac_ip_mapping = "ntopng.cache.mac_ip_mapping_ifid"

-- ##############################################

local behavior_table = {
   asn = {
      page_path = "/lua/as_details.lua",
      timeseries_id = "asn",
      schema_id = "asn",
      page = "historical",
   },
   network = {
      page_path = "/lua/network_details.lua",
      timeseries_id = "network",
      schema_id = "subnet",
      page = "historical",
   },
   l7 = {
      page_path = "/lua/if_stats.lua",
      schema_id = "iface",
      page = "historical",
      type_of_behavior = "ndpi",
   }
}

-- ##############################################

function behavior_utils.get_behavior_timeseries_utils(family_key)
   return behavior_table[family_key]
end

-- ##############################################

function behavior_utils.change_behavior_learning_status()
   -- Set the redis key for the restart
   ntop.setCache(redis_key, true)
   rest_utils.answer(rest_utils.consts.success.ok, res)
end

-- ##############################################

function behavior_utils.restart_required()
    if ntop.getCache(redis_key) == '' then
        return false
    end

    return true
end

-- ##############################################

function behavior_utils.reset()
    if ntop.getCache(redis_key) ~= '' then
        ntop.delCache(redis_key)
    end
end

local maps_utils = {}

-- ##############################################

local function areMapsEnabled()
   local res = (ntop.isEnterpriseL() or ntop.isnEdgeEnterprise()) and (ntop.getPref(behavior_maps_key) == "1")

   return res
end

-- ##############################################

-- Returns two bools value, one for service map and the other for periodicity map
function behavior_utils.mapsAvailable()
    local service_map_available = false
    local periodic_map_available = false  

    if areMapsEnabled() then
        local service_map = interface.serviceMap(nil, nil, nil, nil, nil, nil) or {}
        local periodicity_map = interface.periodicityMap(nil, nil, nil, nil, nil, nil) or {}

        if service_map and (table.len(service_map) > 0) then
            service_map_available = true
        end

        if periodicity_map and (table.len(periodicity_map) > 0) then
            periodic_map_available = true
        end
    end

    return service_map_available, periodic_map_available
end

-- ##############################################

return behavior_utils