Backup-Monitoring per Powershell-Skript

steke88

New Member
Mar 12, 2024
1
0
1
Servus zusammen,

ich teste gerade den Proxmox-VM-Server und den Backup-Server.
Was mir noch wichtig wäre ist, dass wir die Backups monitoren können...
Wir nutzen als Monitorings-Software die Riversuite von Riverbird.
Riverbird hat mir nur ein Standard-Skript gegeben (Powershell) das die Backups abrufen kann (ohne Gewähr). Keiner kann mir sagen, ob das funktioniert...
Ich scheitere mit dem Skript schon bei der Anmeldung...
Da ich auch neu im Thema Skript und API bin habe ich mich in das Thema API reingelesen, einen Token generiert, Rechte drauf gegeben aber ich komme immer noch nicht per API auf den Server...
Kann mir hier wer helfen?
Hier ist mein Skript:

# Proxmox API information
$proxmoxApiUrl = "https://your-proxmox-server:8006/api2/json"
$proxmoxUsername = "your-username"
$proxmoxPassword = "your-password"
# Function to authenticate with Proxmox API
function Authenticate-Proxmox {
param (
[string]$username,
[string]$password
)
$authUrl = "$proxmoxApiUrl/access/ticket"
$authBody = @{
username = $username
password = $password
}
$authResponse = Invoke-RestMethod -Uri $authUrl -Method Post -Body $authBody -SessionVariable session
return $authResponse
}
# Function to get information about Proxmox backups
function Get-ProxmoxBackups {
param (
[string]$apiUrl,
[string]$ticket
)
$backupUrl = "$apiUrl/cluster/backup"
$backupResponse = Invoke-RestMethod -Uri $backupUrl -Method Get -Headers @{ "CSRFPreventionToken" = $ticket } -WebSession $session
return $backupResponse.data
}
# Authenticate with Proxmox API
$authResult = Authenticate-Proxmox -username $proxmoxUsername -password $proxmoxPassword
# Check if authentication is successful
if ($authResult.ticket) {
Write-Host "Authentication successful."
# Get Proxmox backup information
$backups = Get-ProxmoxBackups -apiUrl $proxmoxApiUrl -ticket $authResult.ticket
$backupFailed = $false
# Display backup information
foreach ($backup in $backups) {
Write-Host "Backup ID: $($backup.id)"
Write-Host "Status: $($backup.status)"
Write-Host "Node: $($backup.node)"
Write-Host "StartTime: $($backup.starttime)"
Write-Host "EndTime: $($backup.endtime)"
Write-Host "--------------------------"
# Check if any backup has failed
if ($backup.status -ne "OK") {
$backupFailed = $true
}
}
# Exit with appropriate exit code
if ($backupFailed) {
Write-Host "At least one backup has failed. Exiting with exit code 1."
exit 1
} else {
Write-Host "All backups are successful. Exiting with exit code 0."
exit 0
}
} else {
Write-Host "Authentication failed. Please check your credentials."
exit 1
}



MFG Stephan Kern
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!