Este documento resume malísimamente los pasos y desarrollos realizados hasta la fecha en el proyecto de monitoreo y registro de eventos para hosts y Backup Vaults.
This project consists of a Python Flask API that receives data from an Azure Automation Runbook about backup jobs in an Azure Backup Vault. The API processes this data and inserts it into a MariaDB database.
1. Azure Automation Runbook:
2. Flask API:
The Powershell script retrieves the backup jobs and sends them to the Flask API. Here is a simplified overview:
# Login to Azure (Using Managed Identity)
Connect-AzAccount -Identity
# Get backup jobs from the last 24 hours
$vault = Get-AzRecoveryServicesVault
$backupJobs = Get-AzRecoveryServicesBackupJob -VaultId $vault.ID -From (Get-Date).AddDays(-1).ToUniversalTime()
# Prepare the API request
$uri = "https://api.facundoitest.space/upload"
$headers = @{
"Content-Type" = "application/json"
"Authorization" = "bXktbG9----LongAssBase64String----XN0cmluZw=="
}
# Create the JSON payload
$backupJobsList = $backupJobs | ForEach-Object {
[PSCustomObject]@{
"vmname" = $_.WorkloadName
"creationtime" = $_.StartTime.ToString("o")
"type" = $_.Operation
"result" = $_.Status
}
}
$body = @{
"hostname" = $vault.Name
"restorePoints" = $backupJobsList
} | ConvertTo-Json -Depth 4
# Send the JSON to the API
$response = Invoke-WebRequest -Uri $uri -Method Post -Body $body -Headers $headers -SkipHeaderValidation
The Python API processes the incoming JSON payload and stores the relevant data in MariaDB. Below is an outline of the core logic:
from flask import Flask, request, jsonify
import mysql.connector
app = Flask(__name__)
@app.route('/upload', methods=['POST'])
def upload_data():
data = request.get_json()
hostname = data.get('hostname')
restore_points = data.get('restorePoints')
conn = mysql.connector.connect(host='db_host', user='db_user', password='db_password', database='VeeamReports')
cursor = conn.cursor()
table_name = f"{hostname}_backups"
create_table_query = f\"\"\"
CREATE TABLE IF NOT EXISTS {table_name} (
id INT AUTO_INCREMENT PRIMARY KEY,
vmname VARCHAR(255),
creationtime DATETIME,
type VARCHAR(255),
result VARCHAR(255)
)
\"\"\"
cursor.execute(create_table_query)
for restore_point in restore_points:
vmname = restore_point.get('vmname')
creationtime = restore_point.get('creationtime')
type = restore_point.get('type')
result = restore_point.get('result')
insert_query = f\"\"\"INSERT INTO {table_name} (vmname, creationtime, type, result)
VALUES (%s, %s, %s, %s)\"\"\"
cursor.execute(insert_query, (vmname, creationtime, type, result))
conn.commit()
cursor.close()
conn.close()
return jsonify({"status": "success"}), 200
This setup allows you to monitor your Azure Backup Vault and store backup job data for further analysis or reporting.
├── demoBackups │ ├── app.py │ ├── static │ │ └── styles.css │ └── templates │ ├── admin.html │ ├── client_status.html │ └── index.html