Reputation: 11
I need a push notification on gotify for veeam backup agent, for this i made this script:
# Set the console output encoding to UTF-8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Function Send-Gotify {
Param([Parameter(Mandatory=$true)][String]$Message)
$GotifyServer = "censored"
$GotifyPort = "censored" # Replace with your Gotify port
$GotifyToken = "censored"
$CustomText = "Test"
$RequestBody = @{
title = "$GotifyTitle $CustomText"
message = $Message
} | ConvertTo-Json
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
try {
$Uri = "$GotifyServer`:$GotifyPort/message"
Write-Host "Sending Gotify message to $Uri"
$Response = Invoke-RestMethod -Uri $Uri -Method Post -Headers @{
"X-Gotify-Key" = $GotifyToken
} -Body $RequestBody -ContentType 'application/json'
Write-Host "Gotify message sent successfully. Response: $($Response | ConvertTo-Json -Depth 5)"
} catch {
Write-Host "Failed to send Gotify message. Error: $_"
}
}
# Get the last event with ID 190
$A = Get-WinEvent -MaxEvents 1 -FilterHashTable @{Logname = "Veeam Agent"; ID = 190}
if ($A) {
$Message = $A.Message
$EventTime = $A.TimeCreated
# Format the event date (not time)
$FormattedEventDate = $EventTime.ToString("dd-MM-yyyy")
# Check if the event message contains "Success", "Failed", or "Warning"
if ($Message -match "Success") {
$GotifyTitle = "[V] $CustomText" # Checkmark ASCII code
} elseif ($Message -match "Failed") {
$GotifyTitle = "[X] $CustomText" # Cross ASCII code
} elseif ($Message -match "Warning") {
$GotifyTitle = "[!] $CustomText" # Warning ASCII code
}
# Check if the event date is equal to the current date
if ($FormattedEventDate -eq (Get-Date).ToString("dd-MM-yyyy")) {
$EventTimeString = "Event Time: $($EventTime.ToString("dd-MM-yyyy HH:mm:ss"))"
# Check if the event is older than 10 minutes
$TimeDifference = (Get-Date) - $EventTime
if ($TimeDifference.TotalMinutes -gt 10) {
exit
}
# Concatenate custom string, event time, and message
$MessageToSend = "$EventTimeString`r`n$Message"
# Send the message via Gotify
Send-Gotify $MessageToSend
} else {
exit
}
} else {
exit
}
The problem are i need emoji for fast check the status of the backup but no one solution i tried works I need red circle for fail, orange for warning, green for backup success, anyone can help me pls?
I tried html entities but not work
Upvotes: 0
Views: 11