From e34281045dd94b324e55b97a1c734d331de12c01 Mon Sep 17 00:00:00 2001 From: KayJay7 <31775749+KayJay7@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:14:22 +0000 Subject: [PATCH] Fixed offline detection in IPNEIGH --- front/plugins/ipneigh/README.md | 2 +- front/plugins/ipneigh/config.json | 2 +- front/plugins/ipneigh/ipneigh.py | 29 ++++++++--------------------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/front/plugins/ipneigh/README.md b/front/plugins/ipneigh/README.md index c65ea050..715ccce9 100755 --- a/front/plugins/ipneigh/README.md +++ b/front/plugins/ipneigh/README.md @@ -14,7 +14,7 @@ To set up the plugin correctly, make sure to add in the plugin settings the name ### Usage - Head to **Settings** > **IP Neigh** to add the interfaces you want to scan to the `IPNEIGH_interfaces` option -- The interface list must be formatted without whitespaces and comma separated +- The interface list must be formatted without whitespaces and comma separated e.g. `eth0,wl1,tap0` ### Notes diff --git a/front/plugins/ipneigh/config.json b/front/plugins/ipneigh/config.json index 64b73ead..93c2059e 100755 --- a/front/plugins/ipneigh/config.json +++ b/front/plugins/ipneigh/config.json @@ -126,7 +126,7 @@ ] }, "maxLength": 150, - "default_value": "", + "default_value": "eth0", "options": [], "localized": [ "name", diff --git a/front/plugins/ipneigh/ipneigh.py b/front/plugins/ipneigh/ipneigh.py index 4194dcee..467da993 100755 --- a/front/plugins/ipneigh/ipneigh.py +++ b/front/plugins/ipneigh/ipneigh.py @@ -47,27 +47,20 @@ def main(): raw_neighbors = get_neighbors(interfaces) neighbors = parse_neighbors(raw_neighbors) - - #mylog('verbose', [f'[{pluginName}] Found neighbors: {neighbors}']) # Process the data into native application tables if len(neighbors) > 0: - # insert devices into the lats_result.log - # make sure the below mapping is mapped in config.json, for example: - #"database_column_definitions": [ - # { - # "column": "Object_PrimaryID", <--------- the value I save into primaryId - # "mapped_to_column": "cur_MAC", <--------- gets inserted into the CurrentScan DB table column cur_MAC - # for device in neighbors: plugin_objects.add_object( primaryId = device['mac'], secondaryId = device['ip'], - watched1 = handleEmpty(device['hostname']), # empty - watched2 = handleEmpty(device['vendor']), # empty - watched3 = handleEmpty(device['device_type']), # empty - watched4 = handleEmpty(device['last_seen']), # sometime empty + watched4 = device['last_seen'], + + # The following are always unknown + watched1 = device['hostname'], # don't use these --> handleEmpty(device['hostname']), + watched2 = device['vendor'], # handleEmpty(device['vendor']), + watched3 = device['device_type'], # handleEmpty(device['device_type']), extra = '', foreignKey = "" #device['mac'] # helpVal1 = "Something1", # Optional Helper values to be passed for mapping into the app @@ -86,7 +79,7 @@ def main(): def parse_neighbors(raw_neighbors: list[str]): neighbors = [] for line in raw_neighbors: - if "lladdr" in line: + if "lladdr" in line and "REACHABLE" in line: # Known data fields = line.split() @@ -95,18 +88,12 @@ def parse_neighbors(raw_neighbors: list[str]): neighbor = {} neighbor['ip'] = fields[0] neighbor['mac'] = fields[2] - neighbor['reachability'] = fields[3] + neighbor['last_seen'] = datetime.now() # Unknown data neighbor['hostname'] = '(unknown)' neighbor['vendor'] = '(unknown)' neighbor['device_type'] = '(unknown)' - - # Last seen now if reachable - if neighbor['reachability'] == "REACHABLE": - neighbor['last_seen'] = datetime.now() - else: - neighbor['last_seen'] = "" neighbors.append(neighbor)