ftp list improvements
This commit is contained in:
Vendored
+3
@@ -55,6 +55,9 @@
|
||||
"env": {
|
||||
"PYTHONPATH": "${workspaceFolder}",
|
||||
"INTERVAL": "15",
|
||||
"DCP_INTERVAL" : "300",
|
||||
"DCP_SERVER_FILE": "/home/dcpservers.json",
|
||||
"DCP_NEW_TOPIC": "projmon/newdcp",
|
||||
"LOG_FILE": "/tmp/upsmon.log",
|
||||
"LOG_FILE_LVL": "WARNING",
|
||||
"LOG_CLI_LVL": "DEBUG",
|
||||
|
||||
+20
-19
@@ -98,24 +98,25 @@ def check_new_titles(mqtt: mqtt_client.Client, topic: str, file_path: str, logge
|
||||
first_run = True
|
||||
|
||||
for server in dcp_servers.servers:
|
||||
with server.connect() as ftp_connection:
|
||||
logger.debug("Connected to FTP server %s: %s", server.name, ftp_connection.getwelcome())
|
||||
|
||||
diff_dirs: List[FTPDirInfo] = list_new_directories(server)
|
||||
# do not publish complete list with garbage
|
||||
if first_run:
|
||||
return
|
||||
for d in diff_dirs:
|
||||
logger.info(f"New DCP found on {server.name}: {d.name} (Modified: {d.modified_time}, Unique: {d.unique})")
|
||||
for filter_str in server.notify_filters:
|
||||
if filter_str in d.name:
|
||||
topic = topic
|
||||
notification = NotificationMessage(
|
||||
server=server.name,
|
||||
name=d.name,
|
||||
modified_time=d.modified_time
|
||||
)
|
||||
mqtt.publish(topic, notification.model_dump_json())
|
||||
sleep(1) # Small delay to ensure message is sent
|
||||
# find differences between register and FTP server
|
||||
diff_dirs: List[FTPDirInfo] = list_new_directories(server)
|
||||
# do not publish complete list with garbage
|
||||
if first_run:
|
||||
logger.info("DCP first check on %s, %d DCPs found", server.name, len(diff_dirs))
|
||||
continue
|
||||
for dir in diff_dirs:
|
||||
logger.info(f"New DCP found on {server.name}: {dir.name} (Modified: {dir.modified_time}, Unique: {dir.unique})")
|
||||
for filter_str in server.notify_filters:
|
||||
if filter_str in dir.name:
|
||||
notification = NotificationMessage(
|
||||
server=server.name,
|
||||
name=dir.name,
|
||||
modified_time=dir.modified_time
|
||||
)
|
||||
mqtt.publish(topic, notification.model_dump_json())
|
||||
sleep(1) # Small delay to ensure message is sent
|
||||
|
||||
# Save server information with updated DCP list
|
||||
save_ftp_servers_to_json(dcp_servers, file_path)
|
||||
return
|
||||
|
||||
+6
-2
@@ -39,6 +39,9 @@ def on_shutwown(client: mqtt_client.Client, userdata: Any, msg: mqtt_client.MQTT
|
||||
##################
|
||||
def main() -> int:
|
||||
INTERVAL = int(env['INTERVAL'])
|
||||
DCP_INTERVAL = int(env['DCP_INTERVAL'])
|
||||
DCP_SERVER_FILE = str(env['DCP_SERVER_FILE'])
|
||||
DCP_NEW_TOPIC = str(env['DCP_NEW_TOPIC'])
|
||||
try:
|
||||
mqtt = mqtt_client.Client(CallbackAPIVersion.VERSION2)
|
||||
mqtt.username_pw_set(username=env['MQTT_USER'], password=env['MQTT_PASSWORD'])
|
||||
@@ -312,9 +315,10 @@ def main() -> int:
|
||||
LOGGER.error("Unexpected exception: [%s]", e)
|
||||
return 1
|
||||
|
||||
if now - last_title_check > 300:
|
||||
# Check for new DCP packages in FTP servers
|
||||
if now - last_title_check > DCP_INTERVAL:
|
||||
try:
|
||||
check_new_titles(mqtt, "projmon/ftp", "dcpservers.json", LOGGER)
|
||||
check_new_titles(mqtt, DCP_NEW_TOPIC, DCP_SERVER_FILE, LOGGER)
|
||||
last_title_check = now
|
||||
except Exception as e:
|
||||
LOGGER.error("Failed to check DCP on FTP servers")
|
||||
|
||||
Reference in New Issue
Block a user