Last active
August 23, 2021 06:40
-
-
Save the-takeo/c27228a0ab600c9181429f042caeaf02 to your computer and use it in GitHub Desktop.
WebMonitoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#********************************** | |
# 監視URLを指定してください。 | |
#********************************** | |
$Urls = New-Object System.Collections.Generic.List[string] | |
$Urls.Add("https://test1.co.jp") | |
$Urls.Add("https://test2.co.jp") | |
#********************************** | |
# メールの送信情報を設定してください。 | |
#********************************** | |
$smtpServer = "111.111.111.111" | |
$to = "Warning@Warning.co.jp" | |
$from = "Warning@Warning.co.jp" | |
$subject = "サーバー異常検知" | |
$body = "状態異常を検知しました。サーバーを確認してください。" | |
#********************************** | |
# 以下、処理本体です。変更不要です。 | |
#********************************** | |
function Check($Url) { | |
try { | |
Invoke-RestMethod $Url | |
} catch { | |
$message = $body + $Url | |
Send-MailMessage -To $to -From $from -SmtpServer $smtpServer -Subject $subject -Body $message -Encoding UTF8 | |
} | |
} | |
foreach($Url in $Urls) { | |
Check $Url | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment