mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
🔌UNIFI work
This commit is contained in:
@@ -59,6 +59,24 @@ def rmBadChars(input):
|
||||
|
||||
return input
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# check if this is a router IP
|
||||
def is_typical_router_ip(ip_address):
|
||||
# List of common default gateway IP addresses
|
||||
common_router_ips = [
|
||||
"192.168.0.1", "192.168.1.1", "192.168.1.254", "192.168.0.254",
|
||||
"10.0.0.1", "10.1.1.1", "192.168.2.1", "192.168.10.1", "192.168.11.1",
|
||||
"192.168.100.1", "192.168.101.1", "192.168.123.254", "192.168.223.1",
|
||||
"192.168.31.1", "192.168.8.1", "192.168.254.254", "192.168.50.1",
|
||||
"192.168.3.1", "192.168.4.1", "192.168.5.1", "192.168.9.1",
|
||||
"192.168.15.1", "192.168.16.1", "192.168.20.1", "192.168.30.1",
|
||||
"192.168.42.1", "192.168.62.1", "192.168.178.1", "192.168.1.1",
|
||||
"192.168.1.254", "192.168.0.1", "192.168.0.10", "192.168.0.100",
|
||||
"192.168.0.254"
|
||||
]
|
||||
|
||||
return ip_address in common_router_ips
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Check if a valid MAC address
|
||||
def is_mac(input):
|
||||
|
||||
@@ -19,7 +19,7 @@ from pyunifi.controller import Controller
|
||||
INSTALL_PATH="/app"
|
||||
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
|
||||
|
||||
from plugin_helper import Plugin_Object, Plugin_Objects, rmBadChars
|
||||
from plugin_helper import Plugin_Object, Plugin_Objects, rmBadChars, is_typical_router_ip
|
||||
from logger import mylog
|
||||
from helper import timeNowTZ, get_setting_value
|
||||
import conf
|
||||
@@ -158,11 +158,17 @@ def collect_details(device_type, devices, online_macs, processed_macs, plugin_ob
|
||||
for device in devices:
|
||||
mylog('verbose', [f'{json.dumps(device)}'])
|
||||
|
||||
# try extracting variables from teh json
|
||||
name = get_name(get_unifi_val(device, 'name'), get_unifi_val(device, 'hostname'))
|
||||
ipTmp = get_ip(get_unifi_val(device, 'last_ip'), get_unifi_val(device, 'fixed_ip'), get_unifi_val(device, 'ip'))
|
||||
ipTmp = get_ip(get_unifi_val(device, 'lan_ip'), get_unifi_val(device, 'last_ip'), get_unifi_val(device, 'fixed_ip'), get_unifi_val(device, 'ip'))
|
||||
macTmp = device['mac']
|
||||
status = 1 if macTmp in online_macs else device.get('state', 0)
|
||||
deviceType = device_type.get(device.get('type'), '')
|
||||
parentMac = get_parent_mac(get_unifi_val(device, 'uplink_mac'), get_unifi_val(device, 'ap_mac'), get_unifi_val(device, 'sw_mac'))
|
||||
|
||||
# override parent MAC if this is a router
|
||||
if parentMac == 'null' and is_typical_router_ip(ipTmp):
|
||||
parentMac = 'Internet'
|
||||
|
||||
# Add object only if not processed
|
||||
if macTmp not in processed_macs:
|
||||
@@ -175,7 +181,7 @@ def collect_details(device_type, devices, online_macs, processed_macs, plugin_ob
|
||||
watched4=status,
|
||||
extra=get_unifi_val(device, 'connection_network_name', ''),
|
||||
foreignKey="",
|
||||
helpVal1=get_parent_mac(get_unifi_val(device, 'uplink_mac'), get_unifi_val(device, 'ap_mac'), get_unifi_val(device, 'sw_mac')),
|
||||
helpVal1=parentMac,
|
||||
helpVal2=get_port(get_unifi_val(device, 'sw_port'), get_unifi_val(device, 'uplink_remote_port')),
|
||||
helpVal3=device_label,
|
||||
helpVal4="",
|
||||
|
||||
Reference in New Issue
Block a user