Files
OnlineTester-NTFY/root.ps1
2025-08-08 18:26:32 +02:00

46 lines
1.1 KiB
PowerShell

Remove-Module log
Import-Module "$PSScriptRoot\log.psm1"
Write-init -ProductName "OnlineTester-NTFY" -lifetime 7
# Define path to CSV file
$csvPath = "$PSScriptRoot\list.csv"
# Import CSV and iterate through each URL
$websites = Import-Csv -Path $csvPath
function Send-NTFY {
param (
$text
)
$Request = @{
Method = "POST"
URI = "https://ntfy.spaeth-bayern.de/Availability"
Headers = @{
Title = "Website down!"
Priority = "urgent"
Tags = "warning,skull"
}
Body = "$text"
}
Invoke-RestMethod @Request
}
foreach ($site in $websites) {
$url = $site.Url
try {
# Create a WebRequest object
$request = [System.Net.HttpWebRequest]::Create($url)
$request.Method = "HEAD"
$request.Timeout = 5000 # 5 seconds timeout
$request.AllowAutoRedirect = $true
# Get the response
$response = $request.GetResponse()
Write-Log "$url is reachable (Status: $($response.StatusCode))"
$response.Close()
}
catch {
Write-Warning "$url is NOT reachable. Error: $($_.Exception.Message)"
Send-NTFY "$url is NOT reachable. Error: $($_.Exception.Message)"
}
}