mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-15 22:51:37 -07:00
AVAHISCAN / mDNS #815
This commit is contained in:
@@ -41,8 +41,7 @@ def main():
|
|||||||
# timeout = get_setting_value('AVAHI_RUN_TIMEOUT')
|
# timeout = get_setting_value('AVAHI_RUN_TIMEOUT')
|
||||||
timeout = 20
|
timeout = 20
|
||||||
|
|
||||||
# ensure service is running
|
|
||||||
ensure_avahi_running()
|
|
||||||
|
|
||||||
# Create a database connection
|
# Create a database connection
|
||||||
db = DB() # instance of class DB
|
db = DB() # instance of class DB
|
||||||
@@ -66,6 +65,10 @@ def main():
|
|||||||
|
|
||||||
mylog('verbose', [f'[{pluginName}] Unknown devices count: {len(unknown_devices)}'])
|
mylog('verbose', [f'[{pluginName}] Unknown devices count: {len(unknown_devices)}'])
|
||||||
|
|
||||||
|
if len(unknown_devices) > 0:
|
||||||
|
# ensure service is running
|
||||||
|
ensure_avahi_running()
|
||||||
|
|
||||||
for device in unknown_devices:
|
for device in unknown_devices:
|
||||||
domain_name = execute_name_lookup(device['dev_LastIP'], timeout)
|
domain_name = execute_name_lookup(device['dev_LastIP'], timeout)
|
||||||
|
|
||||||
@@ -153,14 +156,14 @@ def ensure_avahi_running():
|
|||||||
# mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to install D-Bus: {e.output}'])
|
# mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to install D-Bus: {e.output}'])
|
||||||
# return
|
# return
|
||||||
|
|
||||||
# Start the D-Bus service
|
# Check rc-status
|
||||||
try:
|
try:
|
||||||
subprocess.run(['rc-service', 'dbus', 'start'], check=True)
|
subprocess.run(['rc-status'], check=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to start D-Bus: {e.output}'])
|
mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to check rc-status: {e.output}'])
|
||||||
return
|
return
|
||||||
|
|
||||||
# Create OpenRC soft level if needed
|
# Create OpenRC soft level
|
||||||
subprocess.run(['touch', '/run/openrc/softlevel'], check=True)
|
subprocess.run(['touch', '/run/openrc/softlevel'], check=True)
|
||||||
|
|
||||||
# Add Avahi daemon to runlevel
|
# Add Avahi daemon to runlevel
|
||||||
@@ -170,6 +173,13 @@ def ensure_avahi_running():
|
|||||||
mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to add Avahi to runlevel: {e.output}'])
|
mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to add Avahi to runlevel: {e.output}'])
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Start the D-Bus service
|
||||||
|
try:
|
||||||
|
subprocess.run(['rc-service', 'dbus', 'start'], check=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to start D-Bus: {e.output}'])
|
||||||
|
return
|
||||||
|
|
||||||
# Start the Avahi daemon
|
# Start the Avahi daemon
|
||||||
try:
|
try:
|
||||||
subprocess.run(['rc-service', 'avahi-daemon', 'start'], check=True)
|
subprocess.run(['rc-service', 'avahi-daemon', 'start'], check=True)
|
||||||
@@ -181,5 +191,6 @@ def ensure_avahi_running():
|
|||||||
status_output = subprocess.run(['rc-service', 'avahi-daemon', 'status'], capture_output=True, text=True)
|
status_output = subprocess.run(['rc-service', 'avahi-daemon', 'status'], capture_output=True, text=True)
|
||||||
mylog('verbose', [f'[{pluginName}] Avahi Daemon Status: {status_output.stdout.strip()}'])
|
mylog('verbose', [f'[{pluginName}] Avahi Daemon Status: {status_output.stdout.strip()}'])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user