Initial Commit

This commit is contained in:
Neill Cox 2024-08-10 14:13:07 +10:00
commit 05c2e5e81f
17 changed files with 1197 additions and 0 deletions

85
ah_tools/check_backups.py Normal file
View file

@ -0,0 +1,85 @@
import argparse
import json
import re
import requests
from ah_tools.helpers import decrypt
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument(
"-s",
"--servers",
type=argparse.FileType("r"),
required=True,
help="path containing the encrypted list of servers"
)
parser.add_argument(
"-p", "--password",
type=str,
required=True,
help="password to decrypt the servers file"
)
parser.add_argument(
"-S", "--salt",
type=str,
required=True,
help="salt for decrypting the servers file"
)
parser.add_argument(
"-d", "--date",
type=str,
required=True,
help="start date for listing backups YYYY-mm-dd"
)
parser.add_argument(
"-f", "--format",
type=str, choices=["text", "json"],
default="text",
help="Output format. Text of json"
)
args = parser.parse_args()
return args
def get_logs(server, port, date, user, password):
url = (
f"https://{server}:{port}/virtual-server/remote.cgi?program=list-backup-logs&"
f"multiline&start={date}&multiline"
)
result = requests.get(url, auth=requests.auth.HTTPBasicAuth(user, password))
backup_details = {}
backup_list = []
for line in result.text.split("\n"):
if re.match("^[0-9]+-[0-9]+-1:$", line):
if backup_details:
backup_list.append(backup_details)
backup_details = {}
else:
if ":" in line:
line = line.strip()
key, value = line.split(":", maxsplit=1)
backup_details[key] = value
for b in backup_list:
print(b["Ended"], b["Final status"])
def main():
args = parse_arguments()
data = args.servers.read()
servers = json.loads(decrypt(args.salt, args.password, data))
for server in servers:
print(server["name"])
get_logs(server["hostname"], 10000, args.date, server["user"], server["password"])
if __name__ == "__main__":
main()