Table of Contents

Resumen del Proyecto

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.

1. Creación de Tablas por Host/Backup Vault


2. Implementación de Nuevas Columnas para Timestamps


3. Autenticación en la API

Azure Backup Vault Monitoring API

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.

How It Works

1. Azure Automation Runbook:

  1. Connects to Azure using Managed Identity.
  2. Retrieves the latest backup jobs from the specified Azure Backup Vault.
  3. Sends this data as a JSON payload to the Flask API.

2. Flask API:

  1. Receives the JSON payload from the Automation Runbook.
  2. Parses the `hostname` and `restorePoints` from the JSON.
  3. Inserts the backup job data into a dynamically created table in the MariaDB database.

Powershell Script

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

Python Flask API

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.


4. Filtrado de Eventos No Exitosos

Guardado de eventos no exitosos

1. Diseño de la Tabla `unsuccessful_tasks`

2. Proceso de Inserción de Datos

3. Consultas y Reportes

4. Mantenimiento


5. Desarrollo de Script de Monitoreo Automático


6. Optimización de Consultas y Mantenimiento


7. Próximos Pasos


├── demoBackups
│   ├── app.py
│   ├── static
│   │   └── styles.css
│   └── templates
│       ├── admin.html
│       ├── client_status.html
│       └── index.html