mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 01:26:11 -08:00
MQTT rework v0.4, install scripts rework, Traefik docs 📦
This commit is contained in:
@@ -18,8 +18,12 @@ CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
||||
LOG_FILE = os.path.join(CUR_PATH, 'script.log')
|
||||
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log')
|
||||
|
||||
|
||||
pluginName= 'DHCPLSS'
|
||||
|
||||
# -------------------------------------------------------------
|
||||
def main():
|
||||
mylog('verbose', ['[DHCPLSS] In script'])
|
||||
mylog('verbose', [f'[{pluginName}] In script'])
|
||||
last_run_logfile = open(RESULT_FILE, 'a')
|
||||
last_run_logfile.write("")
|
||||
|
||||
@@ -32,42 +36,49 @@ def main():
|
||||
if values.paths:
|
||||
for path in values.paths.split('=')[1].split(','):
|
||||
plugin_objects = get_entries(path, plugin_objects)
|
||||
mylog('verbose', [f'[DHCPLSS] {len(plugin_objects)} Entries found in "{path}"'])
|
||||
mylog('verbose', [f'[{pluginName}] {len(plugin_objects)} Entries found in "{path}"'])
|
||||
|
||||
plugin_objects.write_result_file()
|
||||
|
||||
# -------------------------------------------------------------
|
||||
def get_entries(path, plugin_objects):
|
||||
if 'pihole' in path:
|
||||
|
||||
|
||||
with open(path, 'r') as f:
|
||||
for line in f:
|
||||
row = line.rstrip().split()
|
||||
if len(row) == 5:
|
||||
plugin_objects.add_object(
|
||||
primaryId = handleEmpty(row[1]),
|
||||
secondaryId = handleEmpty(row[2]),
|
||||
watched1 = handleEmpty('True'),
|
||||
watched2 = handleEmpty(row[3]),
|
||||
watched3 = handleEmpty(row[4]),
|
||||
watched4 = handleEmpty('True'),
|
||||
extra = handleEmpty(path),
|
||||
foreignKey = handleEmpty(row[1])
|
||||
)
|
||||
|
||||
# Check if the path exists
|
||||
if os.path.exists(path) == False:
|
||||
mylog('none', [f'[{pluginName}] Error: "{path}" does not exist.'])
|
||||
else:
|
||||
leases = DhcpLeases(path)
|
||||
leasesList = leases.get()
|
||||
for lease in leasesList:
|
||||
plugin_objects.add_object(
|
||||
primaryId = handleEmpty(lease.ethernet),
|
||||
secondaryId = handleEmpty(lease.ip),
|
||||
watched1 = handleEmpty(lease.active),
|
||||
watched2 = handleEmpty(lease.hostname),
|
||||
watched3 = handleEmpty(lease.hardware),
|
||||
watched4 = handleEmpty(lease.binding_state),
|
||||
extra = handleEmpty(path),
|
||||
foreignKey = handleEmpty(lease.ethernet)
|
||||
)
|
||||
# Handle pihole specific dhcp.leases files
|
||||
if 'pihole' in path:
|
||||
|
||||
with open(path, 'r') as f:
|
||||
for line in f:
|
||||
row = line.rstrip().split()
|
||||
if len(row) == 5:
|
||||
plugin_objects.add_object(
|
||||
primaryId = handleEmpty(row[1]),
|
||||
secondaryId = handleEmpty(row[2]),
|
||||
watched1 = handleEmpty('True'),
|
||||
watched2 = handleEmpty(row[3]),
|
||||
watched3 = handleEmpty(row[4]),
|
||||
watched4 = handleEmpty('True'),
|
||||
extra = handleEmpty(path),
|
||||
foreignKey = handleEmpty(row[1])
|
||||
)
|
||||
else:
|
||||
# Handle generic dhcp.leases files
|
||||
leases = DhcpLeases(path)
|
||||
leasesList = leases.get()
|
||||
for lease in leasesList:
|
||||
plugin_objects.add_object(
|
||||
primaryId = handleEmpty(lease.ethernet),
|
||||
secondaryId = handleEmpty(lease.ip),
|
||||
watched1 = handleEmpty(lease.active),
|
||||
watched2 = handleEmpty(lease.hostname),
|
||||
watched3 = handleEmpty(lease.hardware),
|
||||
watched4 = handleEmpty(lease.binding_state),
|
||||
extra = handleEmpty(path),
|
||||
foreignKey = handleEmpty(lease.ethernet)
|
||||
)
|
||||
return plugin_objects
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user