diff --git a/zabbix-agent-scripts/get_fts_indexing_status.py b/zabbix-agent-scripts/get_fts_indexing_status.py index 3731879..c82f662 100644 --- a/zabbix-agent-scripts/get_fts_indexing_status.py +++ b/zabbix-agent-scripts/get_fts_indexing_status.py @@ -87,7 +87,7 @@ upload_cmd = f"curl --location --request PUT {nc_url} --header OCS-APIRequest: true --header Destination: {nc_url} --form file=@/tmp/{file_test_fts_check}" upload_file = subprocess.check_output(upload_cmd.split() - , stderr=subprocess.STDOUT) + , stderr=subprocess.STDOUT) # give the system the time to index the file time.sleep(10) @@ -96,7 +96,7 @@ search_cmd = f"occ fulltextsearch:search --output json {nc_usr} {test_string}" search_file = subprocess.check_output(search_cmd.split() - , stderr=subprocess.STDOUT) + , stderr=subprocess.STDOUT) # check that there is a single entry in the result set search_result_set = json.loads(search_file.decode())["files"] @@ -119,11 +119,11 @@ try: conn = mariadb.connect( user=params["nc_db_usr"], - password=params["nc_db_pwd"], - host=params["nc_db_host"], - port=params["nc_db_port"], - database=params["nc_db"] - ) + password=params["nc_db_pwd"], + host=params["nc_db_host"], + port=params["nc_db_port"], + database=params["nc_db"] + ) except mariadb.Error as e: logging.info(f"Error connecting to database: {e}") @@ -132,11 +132,11 @@ cur = conn.cursor() cur.execute( - f""" - select fileid from oc_filecache - where path = 'files/{file_test_fts_check}' - and storage = (select numeric_id from oc_storages where id = 'home::{nc_usr}') - """ + f""" + select fileid from oc_filecache + where path = 'files/{file_test_fts_check}' + and storage = (select numeric_id from oc_storages where id = 'home::{nc_usr}') + """ ) # check that there is a single entry in the result set @@ -177,8 +177,8 @@ delete_cmd = f"curl --location --request DELETE {nc_url} --header OCS-APIRequest: true --header Destination: {nc_url}" delete_file = subprocess.check_output(delete_cmd.split() - , stderr=subprocess.STDOUT) - + , stderr=subprocess.STDOUT) + 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" @@ -194,22 +194,22 @@ 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") + + 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]) == f"{file_test_fts_check}": + + logging.info("detected file generated by the FTS check. Deleting it.") + + delete_from_trashbin_cmd = f"curl --request DELETE {nc_trashbin_url}/{file_name}" + + 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")