init ready for pord
This commit is contained in:
46
root.ps1
Normal file
46
root.ps1
Normal file
@@ -0,0 +1,46 @@
|
||||
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)"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user