|
10 | 10 | INSTALL_PATH = os.getenv('NETALERTX_APP', '/app') |
11 | 11 | sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) |
12 | 12 |
|
13 | | -from plugin_helper import Plugin_Objects # noqa: E402 [flake8 lint suppression] |
| 13 | +from plugin_helper import Plugin_Objects, parse_scan_subnets # noqa: E402 [flake8 lint suppression] |
14 | 14 | from logger import mylog, Logger # noqa: E402 [flake8 lint suppression] |
15 | 15 | from utils.datetime_utils import timeNowUTC # noqa: E402 [flake8 lint suppression] |
16 | 16 | from const import logPath # noqa: E402 [flake8 lint suppression] |
@@ -38,14 +38,14 @@ def main(): |
38 | 38 | mylog('verbose', [f'[{pluginName}] In script']) |
39 | 39 |
|
40 | 40 | # Retrieve configuration settings |
41 | | - SCAN_SUBNETS = get_setting_value('SCAN_SUBNETS') |
| 41 | + scan_subnets = get_setting_value('SCAN_SUBNETS') |
42 | 42 |
|
43 | | - mylog('verbose', [f'[{pluginName}] SCAN_SUBNETS value: {SCAN_SUBNETS}']) |
| 43 | + parsed = parse_scan_subnets(scan_subnets) |
44 | 44 |
|
45 | | - # Extract interfaces from SCAN_SUBNETS |
46 | | - interfaces = ','.join( |
47 | | - entry.split('--interface=')[-1].strip() for entry in SCAN_SUBNETS if '--interface=' in entry |
48 | | - ) |
| 45 | + interfaces = [] |
| 46 | + for entry in parsed: |
| 47 | + if entry.resolved_interface and entry.resolved_interface not in interfaces: |
| 48 | + interfaces.append(entry.resolved_interface) |
49 | 49 |
|
50 | 50 | mylog('verbose', [f'[{pluginName}] Interfaces value: "{interfaces}"']) |
51 | 51 |
|
@@ -117,27 +117,28 @@ def get_neighbors(interfaces): |
117 | 117 |
|
118 | 118 | results = [] |
119 | 119 |
|
120 | | - for interface in interfaces.split(","): |
| 120 | + for interface in interfaces: |
121 | 121 | try: |
122 | 122 |
|
123 | | - # Ping all IPv6 devices in multicast to trigger NDP |
124 | | - |
125 | 123 | mylog('verbose', [f'[{pluginName}] Pinging on interface: "{interface}"']) |
126 | 124 | command = f"ping ff02::1%{interface} -c 2".split() |
127 | 125 | subprocess.run(command) |
128 | | - mylog('verbose', [f'[{pluginName}] Pinging completed: "{interface}"']) |
129 | | - |
130 | | - # Check the neighbourhood tables |
131 | 126 |
|
132 | | - mylog('verbose', [f'[{pluginName}] Scanning interface: "{interface}"']) |
| 127 | + mylog('verbose', [f'[{pluginName}] Pinging completed, now scanning interface: "{interface}"']) |
| 128 | + |
133 | 129 | command = f"ip neighbor show nud all dev {interface}".split() |
134 | | - output = subprocess.check_output(command, universal_newlines=True) |
| 130 | + |
| 131 | + output = subprocess.check_output( |
| 132 | + command, |
| 133 | + universal_newlines=True |
| 134 | + ) |
| 135 | + |
135 | 136 | results += output.split("\n") |
136 | 137 |
|
137 | 138 | mylog('verbose', [f'[{pluginName}] Scanning interface succeded: "{interface}"']) |
| 139 | + |
138 | 140 | except subprocess.CalledProcessError as e: |
139 | | - # An error occurred, handle it |
140 | | - error_type = type(e).__name__ # Capture the error type |
| 141 | + error_type = type(e).__name__ |
141 | 142 | mylog('verbose', [f'[{pluginName}] Scanning interface failed: "{interface}" ({error_type})']) |
142 | 143 |
|
143 | 144 | return results |
|
0 commit comments