Sign in to follow this  
Followers 0
Digi

Server ping responce time out

4 posts in this topic

Hey there Guys / Girls

I was looking around for a PING responce applet and I managed to find this post by mbknows Online and Offline servers ping or not to ping!

there were 2 or 3 errors I had and managed to correct.

The problem I'm having though is I cant add multiple Email addresses to the applet.

the other thing I want to do is only get it to mail out once it has 4 or 5 consecutive none responce pings.

Thanks to anyone that can help out :P

And even more so if anyone has a better applet :( hehehehe

Heres the Coding Im using now.

#include <file.au3>
#include <INet.au3>
#include <Array.au3>

Dim $Pulltxtfilelist, $num, $CurrentOffline, $RunForever, $Body[1]

$INIFULLPATH = @ScriptDir & "\Settings.ini"
$TMPDATSTORE = @ScriptDir & "\temp.dat"
FileDelete($TMPDATSTORE)
IniWrite($TMPDATSTORE, "Offline", "","")
IniWrite($TMPDATSTORE, "Online", "","")


$SmtpServer = IniRead($INIFULLPATH, "Email Setup", "SMTPServer", "Default")
$FromName = IniRead($INIFULLPATH, "Email Setup", "EmailFromName", "Default")
$FromAddress = IniRead($INIFULLPATH, "Email Setup", "EmailFromAddress", "Default")
$ToAddress = IniRead($INIFULLPATH, "Email Setup", "EmailToAddress", "Default")
$Subject = IniRead($INIFULLPATH, "Email Setup", "EmailSubject", "Default")
$Delay = IniRead($INIFULLPATH, "Setup", "EmailOutDelaySeconds", "30")



If Not _FileReadToArray(@ScriptDir & "\ServerList.txt", $Pulltxtfilelist) Then
    MsgBox(4096, "Error", "ServersList.txt is not found please create and restart service.  error:" & @error)
    Exit
EndIf
For $x = 1 To $Pulltxtfilelist[0]
    $num = $num + 1
    $pingerror = Ping($Pulltxtfilelist[$x])
    If $pingerror Then
        IniWrite($TMPDATSTORE, "Online", $num, $Pulltxtfilelist[$x])
    EndIf
    
    If $pingerror = 0 Then
        IniWrite($TMPDATSTORE, "Offline", $num, $Pulltxtfilelist[$x])
        Dim $Body[1]
        $Body[0] = $Pulltxtfilelist[$x] & " Server has not responded on last Ping. Please note that this is Just a test."
        $Response = _INetSmtpMail($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, "", -1)
    EndIf

Next

Do
    Sleep($Delay)
    $OfflineCheck = IniReadSection($TMPDATSTORE, "Offline")
    If @error Then
    Else
        For $i = 1 To $OfflineCheck[0][0]
            $pingerror = Ping($OfflineCheck[$i][1])
            If $pingerror = 0 Then
            Else
                IniDelete($TMPDATSTORE, "Offline", $OfflineCheck[$i][0])
                IniWrite($TMPDATSTORE, "Online", $OfflineCheck[$i][0], $OfflineCheck[$i][1])
                $Body[0] = $OfflineCheck[$i][1] & " Server is responding to Pings once again."
                $Response = _INetSmtpMail($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, "", -1)
            EndIf
        Next
    EndIf

    $CurrentOffline = ""
    For $l = 1 To $OfflineCheck[0][0]
        $CurrentOffline = $CurrentOffline & @CRLF & $OfflineCheck[$l][1]
    Next

    $OnlineCheck = IniReadSection($TMPDATSTORE, "Online")
    If @error Then
    Else
        For $i = 1 To $OnlineCheck[0][0]
            $pingerror = Ping($OnlineCheck[$i][1])
            If $pingerror = 0 Then
                Sleep(1000)
                $pingerror2 = Ping($OnlineCheck[$i][1])
;                msgbox(4096, "", $pingerror2)
                If $pingerror2 = 0 Then
                    IniDelete($TMPDATSTORE, "Online", $OnlineCheck[$i][0])
                    IniWrite($TMPDATSTORE, "Offline", $OnlineCheck[$i][0], $OnlineCheck[$i][1])
                    Dim $Body[3]
                    $Body[0] = $OnlineCheck[$i][1] & " Server has not responded on last Ping. Please note that this is Just a test."
                    $CurrentOffline = $CurrentOffline & @CRLF & $OnlineCheck[$i][1]
                    $Body[1] = @CRLF
                    $Body[2] = "Server Outage List:" & @CRLF & $CurrentOffline
                    $Response = _INetSmtpMail($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, "", -1)
                EndIf
            EndIf
        Next
    EndIf
    
Until $RunForever = 100

Saru Mo Ki Kara Ochiru[u]Direct Translation[/u]: Even monkeys will fall from trees.[u]I.E.:[/u] To Error is HumanMy Splash Screen applet: Splash Screen Coding

Share this post


Link to post
Share on other sites



Hey there Guys / Girls

I was looking around for a PING responce applet and I managed to find this post by mbknows Online and Offline servers ping or not to ping!

there were 2 or 3 errors I had and managed to correct.

The problem I'm having though is I cant add multiple Email addresses to the applet.

the other thing I want to do is only get it to mail out once it has 4 or 5 consecutive none responce pings.

Thanks to anyone that can help out :P

And even more so if anyone has a better applet :( hehehehe

Heres the Coding Im using now.

#include <file.au3>
#include <INet.au3>
#include <Array.au3>

Dim $Pulltxtfilelist, $num, $CurrentOffline, $RunForever, $Body[1]

$INIFULLPATH = @ScriptDir & "\Settings.ini"
$TMPDATSTORE = @ScriptDir & "\temp.dat"
FileDelete($TMPDATSTORE)
IniWrite($TMPDATSTORE, "Offline", "","")
IniWrite($TMPDATSTORE, "Online", "","")


$SmtpServer = IniRead($INIFULLPATH, "Email Setup", "SMTPServer", "Default")
$FromName = IniRead($INIFULLPATH, "Email Setup", "EmailFromName", "Default")
$FromAddress = IniRead($INIFULLPATH, "Email Setup", "EmailFromAddress", "Default")
$ToAddress = IniRead($INIFULLPATH, "Email Setup", "EmailToAddress", "Default")
$Subject = IniRead($INIFULLPATH, "Email Setup", "EmailSubject", "Default")
$Delay = IniRead($INIFULLPATH, "Setup", "EmailOutDelaySeconds", "30")



If Not _FileReadToArray(@ScriptDir & "\ServerList.txt", $Pulltxtfilelist) Then
    MsgBox(4096, "Error", "ServersList.txt is not found please create and restart service.  error:" & @error)
    Exit
EndIf
For $x = 1 To $Pulltxtfilelist[0]
    $num = $num + 1
    $pingerror = Ping($Pulltxtfilelist[$x])
    If $pingerror Then
        IniWrite($TMPDATSTORE, "Online", $num, $Pulltxtfilelist[$x])
    EndIf
    
    If $pingerror = 0 Then
        IniWrite($TMPDATSTORE, "Offline", $num, $Pulltxtfilelist[$x])
        Dim $Body[1]
        $Body[0] = $Pulltxtfilelist[$x] & " Server has not responded on last Ping. Please note that this is Just a test."
        $Response = _INetSmtpMail($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, "", -1)
    EndIf

Next

Do
    Sleep($Delay)
    $OfflineCheck = IniReadSection($TMPDATSTORE, "Offline")
    If @error Then
    Else
        For $i = 1 To $OfflineCheck[0][0]
            $pingerror = Ping($OfflineCheck[$i][1])
            If $pingerror = 0 Then
            Else
                IniDelete($TMPDATSTORE, "Offline", $OfflineCheck[$i][0])
                IniWrite($TMPDATSTORE, "Online", $OfflineCheck[$i][0], $OfflineCheck[$i][1])
                $Body[0] = $OfflineCheck[$i][1] & " Server is responding to Pings once again."
                $Response = _INetSmtpMail($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, "", -1)
            EndIf
        Next
    EndIf

    $CurrentOffline = ""
    For $l = 1 To $OfflineCheck[0][0]
        $CurrentOffline = $CurrentOffline & @CRLF & $OfflineCheck[$l][1]
    Next

    $OnlineCheck = IniReadSection($TMPDATSTORE, "Online")
    If @error Then
    Else
        For $i = 1 To $OnlineCheck[0][0]
            $pingerror = Ping($OnlineCheck[$i][1])
            If $pingerror = 0 Then
                Sleep(1000)
                $pingerror2 = Ping($OnlineCheck[$i][1])
;                msgbox(4096, "", $pingerror2)
                If $pingerror2 = 0 Then
                    IniDelete($TMPDATSTORE, "Online", $OnlineCheck[$i][0])
                    IniWrite($TMPDATSTORE, "Offline", $OnlineCheck[$i][0], $OnlineCheck[$i][1])
                    Dim $Body[3]
                    $Body[0] = $OnlineCheck[$i][1] & " Server has not responded on last Ping. Please note that this is Just a test."
                    $CurrentOffline = $CurrentOffline & @CRLF & $OnlineCheck[$i][1]
                    $Body[1] = @CRLF
                    $Body[2] = "Server Outage List:" & @CRLF & $CurrentOffline
                    $Response = _INetSmtpMail($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, "", -1)
                EndIf
            EndIf
        Next
    EndIf
    
Until $RunForever = 100
To try 4 or five times instead of

$pingerror = Ping($Pulltxtfilelist[$x])

you could have

for $t = 1 to 5
  $pingerror = Ping($Pulltxtfilelist[$x])
  if $pingerror then exitloop; got response so stop trying
  sleep(1000);possibly wait before next attempt
next
;Now $pingerror = 0 means that tried 5 times but still no good.

Are the extra email accounts for the same server, so that each server could have 1 account or more?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Yea the Emails would fire for the same serverlisting.

To give you a practical example and why im using this.

I have a Webserver,Fileserver and Backup server thats running on my network, but being as busy as I am, I cant always monitor them. Now I'd like that Myself and the rest of my team get a Email notification to our personal mail addresses and our work addresses so we can action it more effectively.

I cant configure a mail forwarder that could just forward to everyone and I would like that it was just configured on a simple file (The ini file in this case.)

And thanks for the Suggest on the Responce checking. Busy testing it to see if it working :P


Saru Mo Ki Kara Ochiru[u]Direct Translation[/u]: Even monkeys will fall from trees.[u]I.E.:[/u] To Error is HumanMy Splash Screen applet: Splash Screen Coding

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yea the Emails would fire for the same serverlisting.

To give you a practical example and why im using this.

I have a Webserver,Fileserver and Backup server thats running on my network, but being as busy as I am, I cant always monitor them. Now I'd like that Myself and the rest of my team get a Email notification to our personal mail addresses and our work addresses so we can action it more effectively.

I cant configure a mail forwarder that could just forward to everyone and I would like that it was just configured on a simple file (The ini file in this case.)

And thanks for the Suggest on the Responce checking. Busy testing it to see if it working :)

With exchange you just setup a mail group and add the users as members. So if you sent a email to _Alerts@yourdomain.com it sends to aaaa@yourdomain.com, bbbb@yourdomain.com, cccc@yourdomain.com Each gets the email as being sent from _Alerts with out the other users explicitly knowing they are in the group.

If doesn't work like you want. You can try the below each will send out an email. Also the code you saw before worked decent my I am making it better. I want to see the RAW ping drop outs but also know if it is fully down. So I am only doing one failed ping for a raw and also doing telnet IP 139 and if a connection goes its up if its down it drops it.

http://www.autoitscript.com/forum/index.ph...=85572&st=0

$s_ToAddress = "aaaa@yourdomain.com

$Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, "", -1)

$s_ToAddress = "bbbb@yourdomain.com

$Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, "", -1)

$s_ToAddress = "cccc@yourdomain.com

$Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, "", -1)

Edited by mbkowns

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