Fixed empty settings
This commit is contained in:
@@ -150,12 +150,12 @@ def print_log (pText):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Current Time
|
# Current Time
|
||||||
log_timestamp2 = datetime.datetime.now()
|
log_timestamp2 = datetime.datetime.now().replace(microsecond=0)
|
||||||
|
|
||||||
# Print line + time + elapsed time + text
|
# Print line + time + elapsed time + text
|
||||||
file_print ('[LOG_LEVEL=debug] ',
|
file_print ('[LOG_LEVEL=debug] ',
|
||||||
log_timestamp2, ' ',
|
log_timestamp2, ' ',
|
||||||
log_timestamp2 - log_timestamp, ' ',
|
log_timestamp2.replace(microsecond=0) - log_timestamp.replace(microsecond=0), ' ',
|
||||||
pText)
|
pText)
|
||||||
|
|
||||||
# Save current time to calculate elapsed time until next log
|
# Save current time to calculate elapsed time until next log
|
||||||
@@ -277,7 +277,7 @@ def commitDB ():
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Log
|
# Log
|
||||||
print_log ('Commiting DB changes')
|
# print_log ('Commiting DB changes')
|
||||||
|
|
||||||
# Commit changes to DB
|
# Commit changes to DB
|
||||||
sql_connection.commit()
|
sql_connection.commit()
|
||||||
@@ -332,9 +332,6 @@ def importConfigs ():
|
|||||||
global NMAP_ACTIVE, NMAP_TIMEOUT, NMAP_RUN, NMAP_RUN_SCHD, NMAP_ARGS
|
global NMAP_ACTIVE, NMAP_TIMEOUT, NMAP_RUN, NMAP_RUN_SCHD, NMAP_ARGS
|
||||||
# API
|
# API
|
||||||
global API_RUN, API_RUN_SCHD, API_RUN_INTERVAL, API_CUSTOM_SQL
|
global API_RUN, API_RUN_SCHD, API_RUN_INTERVAL, API_CUSTOM_SQL
|
||||||
|
|
||||||
mySettings = [] # reset settings
|
|
||||||
mySettingsSQLsafe = [] # same as aboverr but safe to be passed into a SQL query
|
|
||||||
|
|
||||||
# get config file
|
# get config file
|
||||||
config_file = Path(fullConfPath)
|
config_file = Path(fullConfPath)
|
||||||
@@ -342,6 +339,9 @@ def importConfigs ():
|
|||||||
# Skip import if last time of import is NEWER than file age
|
# Skip import if last time of import is NEWER than file age
|
||||||
if (os.path.getmtime(config_file) < lastTimeImported) :
|
if (os.path.getmtime(config_file) < lastTimeImported) :
|
||||||
return
|
return
|
||||||
|
|
||||||
|
mySettings = [] # reset settings
|
||||||
|
mySettingsSQLsafe = [] # same as aboverr but safe to be passed into a SQL query
|
||||||
|
|
||||||
# load the variables from pialert.conf
|
# load the variables from pialert.conf
|
||||||
code = compile(config_file.read_text(), config_file.name, "exec")
|
code = compile(config_file.read_text(), config_file.name, "exec")
|
||||||
@@ -498,6 +498,8 @@ def importConfigs ():
|
|||||||
collect_lang_strings(set, pref + "_" + set["function"])
|
collect_lang_strings(set, pref + "_" + set["function"])
|
||||||
# -----------------
|
# -----------------
|
||||||
# Plugins END
|
# Plugins END
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
plugins_once_run = False
|
plugins_once_run = False
|
||||||
|
|
||||||
@@ -565,6 +567,8 @@ def main ():
|
|||||||
# re-load user configuration and plugins
|
# re-load user configuration and plugins
|
||||||
importConfigs()
|
importConfigs()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Handle plugins executed ONCE
|
# Handle plugins executed ONCE
|
||||||
if plugins_once_run == False:
|
if plugins_once_run == False:
|
||||||
run_plugin_scripts('once')
|
run_plugin_scripts('once')
|
||||||
@@ -578,7 +582,7 @@ def main ():
|
|||||||
|
|
||||||
last_API_update = time_started
|
last_API_update = time_started
|
||||||
update_api()
|
update_api()
|
||||||
|
|
||||||
# proceed if 1 minute passed
|
# proceed if 1 minute passed
|
||||||
if last_run + datetime.timedelta(minutes=1) < time_started :
|
if last_run + datetime.timedelta(minutes=1) < time_started :
|
||||||
|
|
||||||
@@ -659,7 +663,7 @@ def main ():
|
|||||||
if run:
|
if run:
|
||||||
apiSchedule.last_run = datetime.datetime.now(tz).replace(microsecond=0)
|
apiSchedule.last_run = datetime.datetime.now(tz).replace(microsecond=0)
|
||||||
update_api()
|
update_api()
|
||||||
|
|
||||||
# Perform a network scan via arp-scan or pihole
|
# Perform a network scan via arp-scan or pihole
|
||||||
if last_network_scan + datetime.timedelta(minutes=SCAN_CYCLE_MINUTES) < time_started:
|
if last_network_scan + datetime.timedelta(minutes=SCAN_CYCLE_MINUTES) < time_started:
|
||||||
last_network_scan = time_started
|
last_network_scan = time_started
|
||||||
@@ -693,7 +697,7 @@ def main ():
|
|||||||
|
|
||||||
# Commit SQL
|
# Commit SQL
|
||||||
commitDB()
|
commitDB()
|
||||||
|
|
||||||
# Final message
|
# Final message
|
||||||
if cycle != "":
|
if cycle != "":
|
||||||
action = str(cycle)
|
action = str(cycle)
|
||||||
@@ -701,7 +705,7 @@ def main ():
|
|||||||
action = "network_scan"
|
action = "network_scan"
|
||||||
mylog('verbose', ['[', timeNow(), '] Last action: ', action])
|
mylog('verbose', ['[', timeNow(), '] Last action: ', action])
|
||||||
cycle = ""
|
cycle = ""
|
||||||
|
|
||||||
# Footer
|
# Footer
|
||||||
updateState("Process: Wait")
|
updateState("Process: Wait")
|
||||||
mylog('verbose', ['[', timeNow(), '] Process: Wait'])
|
mylog('verbose', ['[', timeNow(), '] Process: Wait'])
|
||||||
@@ -3528,10 +3532,15 @@ def handle_test(testType):
|
|||||||
# Return whole setting touple
|
# Return whole setting touple
|
||||||
def get_setting(key):
|
def get_setting(key):
|
||||||
result = None
|
result = None
|
||||||
# mySettings.append((key, name, desc, inputtype, options, regex, str(result), group, str(events)))
|
# index order: key, name, desc, inputtype, options, regex, result, group, events
|
||||||
for set in mySettings:
|
for set in mySettings:
|
||||||
if set[0] == key:
|
if set[0] == key:
|
||||||
result = set
|
result = set
|
||||||
|
|
||||||
|
if result is None:
|
||||||
|
mylog('info', [' Error - setting_missing - Setting not found for key: ', key])
|
||||||
|
mylog('info', [' Error - logging the settings into file: ', logPath + '/setting_missing.json'])
|
||||||
|
write_file (logPath + '/setting_missing.json', json.dumps({ 'data' : mySettings}))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -3692,7 +3701,7 @@ def execute_plugin(plugin):
|
|||||||
|
|
||||||
|
|
||||||
# ------- prepare params --------
|
# ------- prepare params --------
|
||||||
# prepare command from plugin settings, custom parameters TODO HERE
|
# prepare command from plugin settings, custom parameters
|
||||||
command = resolve_wildcards(set_CMD, params).split()
|
command = resolve_wildcards(set_CMD, params).split()
|
||||||
|
|
||||||
# Execute command
|
# Execute command
|
||||||
@@ -3728,18 +3737,18 @@ def execute_plugin(plugin):
|
|||||||
append_line_to_file (pluginsPath + '/plugin.log', line +'\n')
|
append_line_to_file (pluginsPath + '/plugin.log', line +'\n')
|
||||||
|
|
||||||
# build SQL query parameters to insert into the DB
|
# build SQL query parameters to insert into the DB
|
||||||
params = []
|
sqlParams = []
|
||||||
|
|
||||||
for line in newLines:
|
for line in newLines:
|
||||||
columns = line.split("|")
|
columns = line.split("|")
|
||||||
# There has to be always 8 columns
|
# There has to be always 8 columns
|
||||||
if len(columns) == 8:
|
if len(columns) == 8:
|
||||||
params.append((plugin["unique_prefix"], columns[0], columns[1], columns[2], columns[3], columns[4], columns[5], columns[6], columns[7]))
|
sqlParams.append((plugin["unique_prefix"], columns[0], columns[1], columns[2], columns[3], columns[4], columns[5], columns[6], columns[7]))
|
||||||
else:
|
else:
|
||||||
mylog('none', [' [Plugins]: Skipped invalid line in the output: ', line])
|
mylog('none', [' [Plugins]: Skipped invalid line in the output: ', line])
|
||||||
|
|
||||||
if len(params) > 0:
|
if len(sqlParams) > 0:
|
||||||
sql.executemany ("""INSERT INTO Plugins_State ("Plugin", "Object_PrimaryID", "Object_SecondaryID", "DateTime", "Watched_Value1", "Watched_Value2", "Watched_Value3", "Watched_Value4", "Extra") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""", params)
|
sql.executemany ("""INSERT INTO Plugins_State ("Plugin", "Object_PrimaryID", "Object_SecondaryID", "DateTime", "Watched_Value1", "Watched_Value2", "Watched_Value3", "Watched_Value4", "Extra") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""", sqlParams)
|
||||||
commitDB ()
|
commitDB ()
|
||||||
|
|
||||||
|
|
||||||
@@ -3750,6 +3759,8 @@ def resolve_wildcards(command, params):
|
|||||||
mylog('debug', [' [Plugins]: Pre-Resolved CMD: ', command])
|
mylog('debug', [' [Plugins]: Pre-Resolved CMD: ', command])
|
||||||
|
|
||||||
for param in params:
|
for param in params:
|
||||||
|
mylog('debug', [' [Plugins]: key : {', param[0], '}'])
|
||||||
|
mylog('debug', [' [Plugins]: resolved: ', param[1]])
|
||||||
command = command.replace('{' + param[0] + '}', param[1])
|
command = command.replace('{' + param[0] + '}', param[1])
|
||||||
|
|
||||||
mylog('debug', [' [Plugins]: Resolved CMD: ', command])
|
mylog('debug', [' [Plugins]: Resolved CMD: ', command])
|
||||||
@@ -3760,8 +3771,8 @@ def resolve_wildcards(command, params):
|
|||||||
# Flattens a setting to make it passable to a script
|
# Flattens a setting to make it passable to a script
|
||||||
def plugin_param_from_glob_set(globalSetting):
|
def plugin_param_from_glob_set(globalSetting):
|
||||||
|
|
||||||
setVal = globalSetting[6]
|
setVal = globalSetting[6] # setting value
|
||||||
setTyp = globalSetting[3]
|
setTyp = globalSetting[3] # setting type
|
||||||
|
|
||||||
|
|
||||||
noConversion = ['text', 'integer', 'boolean', 'password', 'readonly', 'selectinteger', 'selecttext' ]
|
noConversion = ['text', 'integer', 'boolean', 'password', 'readonly', 'selectinteger', 'selecttext' ]
|
||||||
|
|||||||
@@ -510,7 +510,7 @@ the arp-scan will take hours to complete instead of seconds.
|
|||||||
'INCLUDED_SECTIONS_name' => 'Notify on',
|
'INCLUDED_SECTIONS_name' => 'Notify on',
|
||||||
'INCLUDED_SECTIONS_description' => 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (<code>CTRL + Click</code> to select / deselect).',
|
'INCLUDED_SECTIONS_description' => 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (<code>CTRL + Click</code> to select / deselect).',
|
||||||
'SCAN_CYCLE_MINUTES_name' => 'Scan cycle delay',
|
'SCAN_CYCLE_MINUTES_name' => 'Scan cycle delay',
|
||||||
'SCAN_CYCLE_MINUTES_description' => 'The delay between scans. If using arp-scan, the scan time itself depends on the number of IP addresses to check. This is influenced by the network mask set in the <a href="#SCAN_SUBNETS"><code>SCAN_SUBNETS</code> setting</a> at the top. Every IP takes a couple seconds to scan.',
|
'SCAN_CYCLE_MINUTES_description' => 'The delay between scans in minutes. If using arp-scan, the scan time itself depends on the number of IP addresses to check. This is influenced by the network mask set in the <a href="#SCAN_SUBNETS"><code>SCAN_SUBNETS</code> setting</a> at the top. Every IP takes a couple seconds to scan.',
|
||||||
'DAYS_TO_KEEP_EVENTS_name' => 'Delete events older than',
|
'DAYS_TO_KEEP_EVENTS_name' => 'Delete events older than',
|
||||||
'DAYS_TO_KEEP_EVENTS_description' => 'This is a maintenance setting. This specifies the number of days worth of event entries that will be kept. All older events will be deleted periodically.',
|
'DAYS_TO_KEEP_EVENTS_description' => 'This is a maintenance setting. This specifies the number of days worth of event entries that will be kept. All older events will be deleted periodically.',
|
||||||
'REPORT_DASHBOARD_URL_name' => 'Pi.Alert URL',
|
'REPORT_DASHBOARD_URL_name' => 'Pi.Alert URL',
|
||||||
|
|||||||
Reference in New Issue
Block a user