Posted to tcl by hypnotoad at Tue Oct 31 16:52:06 GMT 2017view raw

  1. #! /usr/local/bin/tclsh8.6
  2. package require http
  3. source /opt/local/odie/lib/odieutil/mail.tcl
  4. smtp::init mail.etoyoc.com:2500
  5. set from "The Blue Fairy <thebluefairy@etoyoc.com>"
  6. # www.doesnotexist.xyz akupries@shaw.ca
  7. foreach {url contact} {
  8. www.etoyoc.com yoda@etoyoc.com
  9. www.tcl.tk akupries@shaw.ca
  10. } {
  11. set error_text {}
  12. set code [catch {http::geturl http://$url} token errdat]
  13. if {$code != 0} {
  14. set error_text $token
  15. append error_text \n [dict get $errdat -errorinfo]
  16. } else {
  17. set status [http::status $token]
  18. set code [http::code $token]
  19. set size [http::size $token]
  20. set html [http::data $token]
  21. if {[string index $code 0] eq "4"} {
  22. append error_text "Code: $code" \n
  23. append error_text "Page Content" \n
  24. append error_text $html
  25. }
  26. }
  27. if {[string length $error_text]} {
  28. set message "From: $from"
  29. append message \n "Subject: \[bluefairy\] Website $url down"
  30. append message \n
  31. append message \n "This is an automated warning from thebluefairy@[info host]."
  32. append message \n "The website http://$url is not responding properly, as of [clock format [clock seconds]]"
  33. append message \n \n "The information returned from our scan was:"
  34. append message \n $error_text
  35. append message \n
  36. #set token [mime::initialize -canonical text/plain -string $message]
  37. #catch {smtp::sendmessage $token \
  38. # -recipients $contact} err errdat
  39. #puts [dict get $errdat -errorinfo]
  40. ::smtp::send $contact root@localhost $message
  41. }
  42. }