Posted to tcl by hypnotoad at Tue Oct 31 16:52:06 GMT 2017view raw
- #! /usr/local/bin/tclsh8.6
- package require http
- source /opt/local/odie/lib/odieutil/mail.tcl
- smtp::init mail.etoyoc.com:2500
- set from "The Blue Fairy <thebluefairy@etoyoc.com>"
- # www.doesnotexist.xyz akupries@shaw.ca
- foreach {url contact} {
- www.etoyoc.com yoda@etoyoc.com
- www.tcl.tk akupries@shaw.ca
- } {
- set error_text {}
- set code [catch {http::geturl http://$url} token errdat]
- if {$code != 0} {
- set error_text $token
- append error_text \n [dict get $errdat -errorinfo]
- } else {
- set status [http::status $token]
- set code [http::code $token]
- set size [http::size $token]
- set html [http::data $token]
- if {[string index $code 0] eq "4"} {
- append error_text "Code: $code" \n
- append error_text "Page Content" \n
- append error_text $html
- }
- }
- if {[string length $error_text]} {
- set message "From: $from"
- append message \n "Subject: \[bluefairy\] Website $url down"
- append message \n
- append message \n "This is an automated warning from thebluefairy@[info host]."
- append message \n "The website http://$url is not responding properly, as of [clock format [clock seconds]]"
- append message \n \n "The information returned from our scan was:"
- append message \n $error_text
- append message \n
- #set token [mime::initialize -canonical text/plain -string $message]
- #catch {smtp::sendmessage $token \
- # -recipients $contact} err errdat
- #puts [dict get $errdat -errorinfo]
- ::smtp::send $contact root@localhost $message
- }
- }