Skip to content

Commit

Permalink
initial integration of the netbox api (#8465)
Browse files Browse the repository at this point in the history
* added feature sorting flows by protocol

* changed protocols comparison order

* initial commit for bitmap of server ports

* bitmap added to redis

* added debug string, bitmap not working

* Update alerts_list_per_license.rst

* Update alerts_list_per_license.rst

* initial mitre att&ck standardization

* Update ServerPortsBitmap.h

* updated mitre standardization

* ICMP ping fixes

* added http post method that use an auth token

* initial integration of the netbox api
  • Loading branch information
lucaferret committed Jun 21, 2024
1 parent 0b26270 commit d8955d3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/Mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,20 @@ class Mac : public GenericHashEntry {
#ifdef NTOPNG_PRO
time_t captive_portal_notified;
#endif

/* END Mac data: */

#ifdef NTOPNG_PRO
void dumpAssetsInformations();
#endif
void checkDeviceTypeFromManufacturer();
void readDHCPCache();
void freeMacData();
void deleteMacData();
bool statsResetRequested();
void checkStatsReset();
void dumpToRedis();

public:
Mac(NetworkInterface *_iface, u_int8_t _mac[6]);
~Mac();
Expand Down
2 changes: 2 additions & 0 deletions include/ntop_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@
#define DHCP_CACHE "ntopng.dhcp.%d.cache.%s"
#define DHCP_STORM_QUEUE_NAME "ntopng.dhcp.storm.%d"
#define ASSET_SERVICE_KEY "ntopng.asset.%d.%s" /* ifId.host */
#define ASSET_LIST_INSERTION_KEY "ntopng.asset.insertion.%d" /* take in sync with lua code */
#define ASSET_HASH_CACHE_KEY "ntopng.asset.hash.cache.%d" /* take in sync with lua code */
#define DHCP_STORM_PPS_THSHOLD 2048
#define NTOPNG_TRACE "ntopng.trace"
#define ALERT_TRACE_ERRORS "ntopng.trace_error.alert_queue"
Expand Down
8 changes: 8 additions & 0 deletions scripts/callbacks/system/startup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" .. package
package.path = dirs.installdir .. "/scripts/lua/modules/vulnerability_scan/?.lua;" .. package.path

-- Important: load this before any other alert related module
require "prefs_utils"
local checks = require "checks"
checks.loadChecks()

Expand All @@ -31,6 +32,9 @@ local blog_utils = require("blog_utils")
local vs_utils = require "vs_utils"
local drop_host_pool_utils = require "drop_host_pool_utils"

if ntop.isPro() and isNetBoxEnabled() then
local netbox_api = require("netbox_manager")
end
-- ##################################################################

traceError(TRACE_NORMAL, TRACE_CONSOLE, "Processing startup.lua: please hold on...")
Expand Down Expand Up @@ -245,4 +249,8 @@ vs_utils.restore_host_to_scan()
-- Reload Alert Exclusions
ntop.reloadAlertExclusions()

if ntop.isPro() and isNetBoxEnabled() then
netbox_api.initialization_device_roles()
end

traceError(TRACE_NORMAL, TRACE_CONSOLE, "Completed startup.lua")
34 changes: 34 additions & 0 deletions src/Mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ Mac::Mac(NetworkInterface *_iface, u_int8_t _mac[6])
iface->getNumL2Devices());
#endif

#ifdef NTOPNG_PRO
if (!special_mac && ntop->getPrefs()->is_enterprise_xl_edition()
&& ntop->getPrefs()->isNetBoxEnabled())
dumpAssetsInformations();
#endif

updateHostPool(true /* inline with packet processing */,
true /* first inc */);
}
Expand Down Expand Up @@ -498,3 +504,31 @@ void Mac::dumpToRedis() {

ndpi_term_serializer(&mac_json);
}

/* *************************************** */

#ifdef NTOPNG_PRO
void Mac::dumpAssetsInformations() {
char buf[32], *json_str = NULL;
ndpi_serializer device_json;
u_int32_t json_str_len = 0;

ndpi_init_serializer(&device_json, ndpi_serialization_format_json);

ndpi_serialize_string_string(&device_json, "device", Utils::formatMac(get_mac(), buf, sizeof(buf)));
ndpi_serialize_string_string(&device_json, "source", "traffic");
ndpi_serialize_string_uint32(&device_json, "when", first_seen);
ndpi_serialize_string_string(&device_json, "manufacturer", manuf ? manuf : "N/A");
ndpi_serialize_string_uint32(&device_json, "devtype", device_type);

json_str = ndpi_serializer_get_buffer(&device_json, &json_str_len);

if((json_str != NULL) && (json_str_len > 0)) {
char key[64];
snprintf(key, sizeof(key), ASSET_LIST_INSERTION_KEY, iface->get_id());
ntop->getRedis()->rpush(key, json_str, 1024);
}

ndpi_term_serializer(&device_json);
}
#endif

0 comments on commit d8955d3

Please sign in to comment.