diff --git a/zabbix-agent-scripts/get_fts_indexing_status.py b/zabbix-agent-scripts/get_fts_indexing_status.py index 52d1906..3731879 100644 --- a/zabbix-agent-scripts/get_fts_indexing_status.py +++ b/zabbix-agent-scripts/get_fts_indexing_status.py @@ -39,6 +39,9 @@ import os +import xml.etree.ElementTree as ET + + logging.basicConfig(stream=sys.stdout, level=logging.INFO) params = json.load(open("/var/lib/zabbix/params.json","r")) @@ -167,7 +170,7 @@ logging.info("ok") ################### -# clean-up, delete {file_test_fts_check} locally and on Nextcloud +# clean-up, delete {file_test_fts_check} locally and on Nextcloud, also from the trashbin ################### logging.info(f"removing {file_test_fts_check} from Nextcloud") @@ -178,6 +181,36 @@ logging.info("ok") +nc_trashbin_url = f"http://{nc_usr}:{nc_app_pwd}@127.0.0.1:80/remote.php/dav/trashbin/{nc_usr}/trash" + +cmd_get_files_in_trashbin = f"curl --request PROPFIND {nc_trashbin_url}" + +get_files_in_trashbin = subprocess.check_output(cmd_get_files_in_trashbin.split()).decode() + +root = ET.fromstring(get_files_in_trashbin) + +namespaces = {"d": "DAV:"} + +responses = root.findall(".//d:response", namespaces) + +for response in responses: + + file_name = response.find("./d:href", {"d": "DAV:"}).text + + file_name = os.path.basename(file_name) + + logging.info(file_name) + + if ".".join(file_name.split(".")[:2]) == "file_test_fts_check.pdf": + + logging.info("detected file generated by the FTS check. Deleting it.") + + delete_from_trashbin_cmd = f"curl --request DELETE {nc_trashbin_url}/{file_test_fts_check}" + + delete_from_trashbin = subprocess.check_output(delete_from_trashbin_cmd.split()).decode() + + logging.info("ok") + logging.info(f"removing {file_test_fts_check} from the local temporary folder") os.remove(f"/tmp/{file_test_fts_check}")