Fixed offline detection in IPNEIGH

This commit is contained in:
KayJay7
2024-11-28 10:14:22 +00:00
parent d92ebc24de
commit e34281045d
3 changed files with 10 additions and 23 deletions

View File

@@ -14,7 +14,7 @@ To set up the plugin correctly, make sure to add in the plugin settings the name
### Usage ### Usage
- Head to **Settings** > **IP Neigh** to add the interfaces you want to scan to the `IPNEIGH_interfaces` option - 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 ### Notes

View File

@@ -126,7 +126,7 @@
] ]
}, },
"maxLength": 150, "maxLength": 150,
"default_value": "", "default_value": "eth0",
"options": [], "options": [],
"localized": [ "localized": [
"name", "name",

View File

@@ -48,26 +48,19 @@ def main():
neighbors = parse_neighbors(raw_neighbors) neighbors = parse_neighbors(raw_neighbors)
#mylog('verbose', [f'[{pluginName}] Found neighbors: {neighbors}'])
# Process the data into native application tables # Process the data into native application tables
if len(neighbors) > 0: 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: for device in neighbors:
plugin_objects.add_object( plugin_objects.add_object(
primaryId = device['mac'], primaryId = device['mac'],
secondaryId = device['ip'], secondaryId = device['ip'],
watched1 = handleEmpty(device['hostname']), # empty watched4 = device['last_seen'],
watched2 = handleEmpty(device['vendor']), # empty
watched3 = handleEmpty(device['device_type']), # empty # The following are always unknown
watched4 = handleEmpty(device['last_seen']), # sometime empty 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 = '', extra = '',
foreignKey = "" #device['mac'] foreignKey = "" #device['mac']
# helpVal1 = "Something1", # Optional Helper values to be passed for mapping into the app # 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]): def parse_neighbors(raw_neighbors: list[str]):
neighbors = [] neighbors = []
for line in raw_neighbors: for line in raw_neighbors:
if "lladdr" in line: if "lladdr" in line and "REACHABLE" in line:
# Known data # Known data
fields = line.split() fields = line.split()
@@ -95,19 +88,13 @@ def parse_neighbors(raw_neighbors: list[str]):
neighbor = {} neighbor = {}
neighbor['ip'] = fields[0] neighbor['ip'] = fields[0]
neighbor['mac'] = fields[2] neighbor['mac'] = fields[2]
neighbor['reachability'] = fields[3] neighbor['last_seen'] = datetime.now()
# Unknown data # Unknown data
neighbor['hostname'] = '(unknown)' neighbor['hostname'] = '(unknown)'
neighbor['vendor'] = '(unknown)' neighbor['vendor'] = '(unknown)'
neighbor['device_type'] = '(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) neighbors.append(neighbor)
return neighbors return neighbors