Skip to content

Instantly share code, notes, and snippets.

@the-takeo
Last active August 23, 2021 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-takeo/c27228a0ab600c9181429f042caeaf02 to your computer and use it in GitHub Desktop.
Save the-takeo/c27228a0ab600c9181429f042caeaf02 to your computer and use it in GitHub Desktop.
WebMonitoring
#**********************************
# 監視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