35 cursor = conn_integrity.cursor()
36 cursor.execute(
"INSERT INTO integrity_check(type_id, storage_id, check_date, file_count) VALUES (%s, %s, %s, %s) RETURNING check_id", [check_type, storage, check_date, file_count])
37 check_id = cursor.fetchone()[0]
38 conn_integrity.commit()
43def failed_record(conn_integrity, check_id, error_id, file_path, error_details):
44 cursor = conn_integrity.cursor()
45 cursor.execute(
"INSERT INTO failed_record(check_id, error_id, file_path, error_details) VALUES (%s, %s, %s, %s)", [check_id, error_id, file_path, error_details])
46 conn_integrity.commit()
51 for i
in range(count):
52 path_to_file=str(records[i][0]).strip()
53 if (path_to_file.__contains__(
'/') !=
True):
56 if (path_to_file.strip()[-1] ==
'/'):
59 if(str(records[i][1]).strip() ==
"None"):
60 found_errors=found_errors+1
63 hash_md5 = hashlib.md5()
65 with open(path_to_file,
'rb')
as fp:
66 for chunk
in iter(
lambda: fp.read(8192), b
""):
67 hash_md5.update(chunk)
68 except FileNotFoundError
as e:
69 found_errors=found_errors+1
71 except BaseException
as e:
72 found_errors=found_errors+1
73 e = re.sub(
": '"+path_to_file+
"'",
"", str(e))
76 if (str(records[i][1]).strip() != hash_md5.hexdigest()):
77 found_errors=found_errors+1
81 conn_integrity = psycopg2.connect(dbname=
"*", user=
"*", password=
"*", host=
"*", port=
"5432")
82 check_date = datetime.datetime.now().strftime(
"%Y-%m-%d %H:%M:%S")
85 inspection(count, conn_integrity, check_id, records)
86 finish_date = datetime.datetime.now().strftime(
"%Y-%m-%d %H:%M:%S")
87 cursor = conn_integrity.cursor()
88 cursor.execute(
"UPDATE integrity_check SET complete_date=%s WHERE check_id=%s", [finish_date, check_id])
89 conn_integrity.commit()
91 conn_integrity.close()
93 sendmail_location =
"/usr/sbin/sendmail"
94 p = os.popen(
"%s -t" % sendmail_location,
"w")
95 p.write(
"From: %s\n" %
"NCX Inspector < * >")
96 p.write(
"To: %s\n" % mail_adress)
97 p.write(
"Subject: NCX Inspector Robot\n")
99 p.write(
"Inspection of the * files has been completed.")
101 p.write(
"Operating time: " + check_date +
" - " + finish_date)
103 p.write(
"Number of errors: " + str(found_errors))
integrity_check(conn_integrity, check_date)
connection_integrity_database()
inspection(count, conn_integrity, check_id, records)
connection_bmn_database()
failed_record(conn_integrity, check_id, error_id, file_path, error_details)