Sign in to follow this  
Followers 0
TomTheGeek

SiteMonitor

12 posts in this topic

Here's a pretty simple app I built to monitor our company's website. I in charge of the site so if it goes down I need to know. Right now it can only monitor one site and just gives you a notification bubble if it goes down. I want to add the ability to monitor more than one site, change the tray icon depending on status and enable e-mail notifications.

This isn't just a ping utility, that doesn't tell me if the site is actually available. It actually downloads a page from the server.

Requires latest v3 to compile. Comments are welcome.

Opt("GuiOnEventMode",1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1); no default tray menuitems
#NoTrayIcon
#include <GUIConstants.au3>

Global $infolabel
Global $sleepTime
Global $pause = 1

;---------------Tray event values----------------

Global $TRAY_EVENT_SHOWICON         = -3
Global $TRAY_EVENT_HIDEICON         = -4
Global $TRAY_EVENT_FLASHICON        = -5
Global $TRAY_EVENT_NOFLASHICON      = -6
Global $TRAY_EVENT_PRIMARYDOWN      = -7
Global $TRAY_EVENT_PRIMARYUP        = -8
Global $TRAY_EVENT_SECONDARYDOWN    = -9
Global $TRAY_EVENT_SECONDARYUP      = -10
Global $TRAY_EVENT_MOUSEOVER        = -11
Global $TRAY_EVENT_MOUSEOUT         = -12
Global $TRAY_EVENT_PRIMARYDOUBLE    = -13
Global $TRAY_EVENT_SECONDARYDOUBLE  = -14
    
;---------------Build UI----------------
TraySetClick(16)

$runitem = TrayCreateItem("Check Now")
TrayItemSetOnEvent(-1,"CheckNow")
TrayCreateItem("")
$runitem = TrayCreateItem("Options")
TrayItemSetOnEvent(-1,"SetOptions")
$infoitem = TrayCreateItem("About")
TrayItemSetOnEvent(-1,"DisplayAbout")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitEvent")

TraySetIcon(@AutoItExe)

TraySetState()
TraySetToolTip("SiteMonitor ")

;---------------Set initial variables----------------

$PreviousSetting = RegRead("HKEY_CURRENT_USER\SOFTWARE\TomTheGeek\SiteMonitor\", "Timeout")
If $PreviousSetting <> "" Then
    $sleepTime = $PreviousSetting
Else
    $sleepTime = 1000 * 60 * 10; = default setting is 10 minutes.
EndIf
$PreviousURL = RegRead("HKEY_CURRENT_USER\SOFTWARE\TomTheGeek\SiteMonitor\", "URL")
If $PreviousURL <> "" Then
    $URL = $PreviousURL
Else
    $URL = ""
    SetOptions()
EndIf


;---------------Main loop----------------

While 1 
    CheckSite()
    Sleep($sleepTime)
WEnd

Exit

;---------------Functions----------------

Func CheckSite()
    If $URL <> "" Then
        if InetGet($URL, @TempDir & "\SiteMonitor.htm", 1) = 0 then
            TrayTip("SiteMonitor", $URL & " is down! Panic!!", 30, 19) 
        else
           ;TrayTip("SiteMonitor", $URL & " is up.", 30, 17)
        EndIF
    EndIf
EndFunc

Func CheckNow()
    if InetGet($URL, @TempDir & "\SiteMonitor.htm", 1) then
        TrayTip("SiteMonitor", $URL & " is up.", 10, 17) 
    else
        TrayTip("SiteMonitor", $URL & " is down! Panic!!", 30, 19)
    EndIF
EndFunc

Func SetOptions()
    GuiCreate("Options", 392, 144,(@DesktopWidth-392)/2, (@DesktopHeight-144)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    GUISetIcon(@AutoItExe)

    $Label_2 = GuiCtrlCreateLabel("Enter the URL you wish to monitor (Don't forget 'http://')", 20, 20, 330, 20)
    $Input_URL = GuiCtrlCreateInput($URL, 20, 40, 330, 20)
    
    $Label_4 = GuiCtrlCreateLabel("Minutes to wait between checks:", 20, 73, 160, 20)
    $InputTimeout = GuiCtrlCreateInput($sleepTime/60/1000, 180, 70, 50, 20)
    $timeoutID = GUICtrlCreateUpdown ($InputTimeout, $UDS_ARROWKEYS)
    GUICtrlSetLimit ( $timeoutID, 9999, 1)
    
    $SaveID = GuiCtrlCreateButton("Save", 130, 110, 60, 20)
    GUICtrlSetOnEvent($SaveID,"OnSave")
    
    $CancelID = GuiCtrlCreateButton("Cancel", 210, 110, 60, 20)
    GUICtrlSetOnEvent($CancelID,"OnClose")
    
    GUISetOnEvent($GUI_EVENT_CLOSE,"OnClose")
    

    
    GUISetState() ; display the GUI
EndFunc

Func DisplayAbout()
    GuiCreate("About", 256, 258,(@DesktopWidth-256)/2, (@DesktopHeight-258)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    GUISetIcon(@AutoItExe)
    
    $Icon_1 = GuiCtrlCreateIcon(@AutoItExe, 0, 10, 10, 32, 32)
    $Label_2 = GuiCtrlCreateLabel("SiteMonitor v1.0 by Tom Beighley", 60, 10, 100, 30)
    $Button_3 = GuiCtrlCreateButton("OK", 100, 220, 60, 30)
    $Label_4 = GuiCtrlCreateLabel("An application that monitors whatever site you set and notifies you if it goes down.", 60, 50, 190, 50)
    $Label_5 = GuiCtrlCreateLabel("Support Info: TomTheGeek@gmail.com www.TomTheGeek.com", 60, 160, 130, 40)
    $Label_6 = GuiCtrlCreateLabel("Written using AutoIt v3. www.autoitscript.com", 60, 120, 120, 30)
    
    GUICtrlSetOnEvent($Button_3,"OnClose")
    
    GUISetOnEvent($GUI_EVENT_CLOSE,"OnClose")
    
    GUISetState() ; display the GUI 
EndFunc

;Save settings 
Func OnSave()
    $errors = 0
    
    $URL = ControlGetText("Options", "", "Edit1")
    If $URL <> "" Then
        RegWrite("HKEY_CURRENT_USER\SOFTWARE\TomTheGeek\SiteMonitor\", "URL", "REG_SZ", $URL)
    Else
        MsgBox(48,"Incorrect Data","Please enter a URL to check.")
        $errors = 1
    EndIF
    
    $Timeout = Number(ControlGetText("Options", "", "Edit2"))
    If $Timeout > 0 Then
        $sleepTime = $Timeout * 60 * 1000
        RegWrite("HKEY_CURRENT_USER\SOFTWARE\TomTheGeek\SiteMonitor\", "Timeout", "REG_DWORD", $sleepTime)
    Else
        MsgBox(48,"Incorrect Data","Please enter non-zero numerical data only for the timeout value.")
        $errors = 1
    EndIF
    
    If $errors = 0 Then
        GUIDelete()
        CheckNow()
    EndIf
EndFunc

;Function for exiting the app
Func ExitEvent()
    Exit
EndFunc

;Close last GUI window
Func OnClose()
    GUIDelete()
EndFunc

Attached is the compiled version.

SiteMonitor.zip


www.TomTheGeek.com - All the geeky stuff that gets me hot

Share this post


Link to post
Share on other sites



I didn't look closely, but are you taking steps to ensure that your url is _really_ being downloaded from the server ( and not loaded from browser cache or your friendly proxy server?).


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

I didn't look closely, but are you taking steps to ensure that your url is _really_ being downloaded from the server ( and not loaded from browser cache or your friendly proxy server?).

I'm using InetGet with this option: reload 1 = Forces a reload from the remote site.

www.TomTheGeek.com - All the geeky stuff that gets me hot

Share this post


Link to post
Share on other sites

Here's a pretty simple app I built to monitor our company's website. I in charge of the site so if it goes down I need to know. Right now it can only monitor one site and just gives you a notification bubble if it goes down. I want to add the ability to monitor more than one site, change the tray icon depending on status and enable e-mail notifications.

This isn't just a ping utility, that doesn't tell me if the site is actually available. It actually downloads a page from the server.

Requires latest v3 to compile. Comments are welcome.

Opt("GuiOnEventMode",1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1); no default tray menuitems
#NoTrayIcon
#include <GUIConstants.au3>

Global $infolabel
Global $sleepTime
Global $pause = 1

;---------------Tray event values----------------

Global $TRAY_EVENT_SHOWICON         = -3
Global $TRAY_EVENT_HIDEICON         = -4
Global $TRAY_EVENT_FLASHICON        = -5
Global $TRAY_EVENT_NOFLASHICON      = -6
Global $TRAY_EVENT_PRIMARYDOWN      = -7
Global $TRAY_EVENT_PRIMARYUP        = -8
Global $TRAY_EVENT_SECONDARYDOWN    = -9
Global $TRAY_EVENT_SECONDARYUP      = -10
Global $TRAY_EVENT_MOUSEOVER        = -11
Global $TRAY_EVENT_MOUSEOUT         = -12
Global $TRAY_EVENT_PRIMARYDOUBLE    = -13
Global $TRAY_EVENT_SECONDARYDOUBLE  = -14
    
;---------------Build UI----------------
TraySetClick(16)

$runitem = TrayCreateItem("Check Now")
TrayItemSetOnEvent(-1,"CheckNow")
TrayCreateItem("")
$runitem = TrayCreateItem("Options")
TrayItemSetOnEvent(-1,"SetOptions")
$infoitem = TrayCreateItem("About")
TrayItemSetOnEvent(-1,"DisplayAbout")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitEvent")

TraySetIcon(@AutoItExe)

TraySetState()
TraySetToolTip("SiteMonitor ")

;---------------Set initial variables----------------

$PreviousSetting = RegRead("HKEY_CURRENT_USER\SOFTWARE\TomTheGeek\SiteMonitor\", "Timeout")
If $PreviousSetting <> "" Then
    $sleepTime = $PreviousSetting
Else
    $sleepTime = 1000 * 60 * 10; = default setting is 10 minutes.
EndIf
$PreviousURL = RegRead("HKEY_CURRENT_USER\SOFTWARE\TomTheGeek\SiteMonitor\", "URL")
If $PreviousURL <> "" Then
    $URL = $PreviousURL
Else
    $URL = ""
    SetOptions()
EndIf
;---------------Main loop----------------

While 1 
    CheckSite()
    Sleep($sleepTime)
WEnd

Exit

;---------------Functions----------------

Func CheckSite()
    If $URL <> "" Then
        if InetGet($URL, @TempDir & "\SiteMonitor.htm", 1) = 0 then
            TrayTip("SiteMonitor", $URL & " is down! Panic!!", 30, 19) 
        else
          ;TrayTip("SiteMonitor", $URL & " is up.", 30, 17)
        EndIF
    EndIf
EndFunc

Func CheckNow()
    if InetGet($URL, @TempDir & "\SiteMonitor.htm", 1) then
        TrayTip("SiteMonitor", $URL & " is up.", 10, 17) 
    else
        TrayTip("SiteMonitor", $URL & " is down! Panic!!", 30, 19)
    EndIF
EndFunc

Func SetOptions()
    GuiCreate("Options", 392, 144,(@DesktopWidth-392)/2, (@DesktopHeight-144)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    GUISetIcon(@AutoItExe)

    $Label_2 = GuiCtrlCreateLabel("Enter the URL you wish to monitor (Don't forget 'http://')", 20, 20, 330, 20)
    $Input_URL = GuiCtrlCreateInput($URL, 20, 40, 330, 20)
    
    $Label_4 = GuiCtrlCreateLabel("Minutes to wait between checks:", 20, 73, 160, 20)
    $InputTimeout = GuiCtrlCreateInput($sleepTime/60/1000, 180, 70, 50, 20)
    $timeoutID = GUICtrlCreateUpdown ($InputTimeout, $UDS_ARROWKEYS)
    GUICtrlSetLimit ( $timeoutID, 9999, 1)
    
    $SaveID = GuiCtrlCreateButton("Save", 130, 110, 60, 20)
    GUICtrlSetOnEvent($SaveID,"OnSave")
    
    $CancelID = GuiCtrlCreateButton("Cancel", 210, 110, 60, 20)
    GUICtrlSetOnEvent($CancelID,"OnClose")
    
    GUISetOnEvent($GUI_EVENT_CLOSE,"OnClose")
    

    
    GUISetState(); display the GUI
EndFunc

Func DisplayAbout()
    GuiCreate("About", 256, 258,(@DesktopWidth-256)/2, (@DesktopHeight-258)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
    GUISetIcon(@AutoItExe)
    
    $Icon_1 = GuiCtrlCreateIcon(@AutoItExe, 0, 10, 10, 32, 32)
    $Label_2 = GuiCtrlCreateLabel("SiteMonitor v1.0 by Tom Beighley", 60, 10, 100, 30)
    $Button_3 = GuiCtrlCreateButton("OK", 100, 220, 60, 30)
    $Label_4 = GuiCtrlCreateLabel("An application that monitors whatever site you set and notifies you if it goes down.", 60, 50, 190, 50)
    $Label_5 = GuiCtrlCreateLabel("Support Info: TomTheGeek@gmail.com www.TomTheGeek.com", 60, 160, 130, 40)
    $Label_6 = GuiCtrlCreateLabel("Written using AutoIt v3. www.autoitscript.com", 60, 120, 120, 30)
    
    GUICtrlSetOnEvent($Button_3,"OnClose")
    
    GUISetOnEvent($GUI_EVENT_CLOSE,"OnClose")
    
    GUISetState(); display the GUI  
EndFunc

;Save settings 
Func OnSave()
    $errors = 0
    
    $URL = ControlGetText("Options", "", "Edit1")
    If $URL <> "" Then
        RegWrite("HKEY_CURRENT_USER\SOFTWARE\TomTheGeek\SiteMonitor\", "URL", "REG_SZ", $URL)
    Else
        MsgBox(48,"Incorrect Data","Please enter a URL to check.")
        $errors = 1
    EndIF
    
    $Timeout = Number(ControlGetText("Options", "", "Edit2"))
    If $Timeout > 0 Then
        $sleepTime = $Timeout * 60 * 1000
        RegWrite("HKEY_CURRENT_USER\SOFTWARE\TomTheGeek\SiteMonitor\", "Timeout", "REG_DWORD", $sleepTime)
    Else
        MsgBox(48,"Incorrect Data","Please enter non-zero numerical data only for the timeout value.")
        $errors = 1
    EndIF
    
    If $errors = 0 Then
        GUIDelete()
        CheckNow()
    EndIf
EndFunc

;Function for exiting the app
Func ExitEvent()
    Exit
EndFunc

;Close last GUI window
Func OnClose()
    GUIDelete()
EndFunc

Attached is the compiled version.

Tom,

I think I would use iniRead and iniwrite to store settings rather than the registry. You can set a section called servers and then just loop through all of the keys in that section to get multiple servers and pass the server as a parameter from the loop to the checksite function.

I would also put an error loop in so that if a server wasn't rechable on the first try, it would try another time or two before alerting, just in case it was a case of too many hops and not the server being down.

You may also consider testing an asp page or php/perl rather than html because if the process hangs, your server still for all intents and purposes will not be fully reachable due to high cpu/memory consumption, even though it may return an html page.

Jusy my 2bits worth :lmao:

Share this post


Link to post
Share on other sites

I'd rather not use an ini file because it make the program less portable. I will probably do something similar with the registry though.

I may have it check again if it fails the first time but it would have nothing to do with how many hops there are.

The page is only being saved as an HTML file, it works with any type of dynamic web page. The site I built this to monitor is a JSP page.


www.TomTheGeek.com - All the geeky stuff that gets me hot

Share this post


Link to post
Share on other sites

I'd rather not use an ini file because it make the program less portable. I will probably do something similar with the registry though.

I may have it check again if it fails the first time but it would have nothing to do with how many hops there are.

The page is only being saved as an HTML file, it works with any type of dynamic web page. The site I built this to monitor is a JSP page.

Take a look at this freeware link http://www.protect-me.com/freeware_2.html - the software is called active server watch and I believe it is what you are trying to do. It works well, and may give you some ideas for your script.

Share this post


Link to post
Share on other sites

Thaks, it look's like that would be a pretty good match for what I am looking for.


www.TomTheGeek.com - All the geeky stuff that gets me hot

Share this post


Link to post
Share on other sites

this is quite usefull, ty

Share this post


Link to post
Share on other sites

I'd rather not use an ini file because it make the program less portable.

How so? FileInstall() the default ini at app installation if not already present. - I iterate through several locations , ending up in TEMP if need be - It also works well if installing an update of a deployed program, if any new parameters are added they can be written to the ini when updated. Of course, the same options are also avail through the registry.

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

This is such a simple program I can't justify having extra files around to worry about. For me the registry is just simpler.


www.TomTheGeek.com - All the geeky stuff that gets me hot

Share this post


Link to post
Share on other sites

This is such a simple program I can't justify having extra files around to worry about. For me the registry is just simpler.

Does scribbling in all the registries wherever you go leave less footprints to clean up than writing one ini file? You missed the 'cleanup after myself' button...

Share this post


Link to post
Share on other sites

True, I should probably have some sort of uninstall option.

I found the code to add e-mail functionality so I will be adding that soon. In fact since this is getting a little more complicated I may end up switching to a INI file, I'm not sure yet though.


www.TomTheGeek.com - All the geeky stuff that gets me hot

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0