Sign in to follow this  
Followers 0
CHOVIE

Ping and e-mail when faulty

2 posts in this topic

Good Day All,

I have gone through the forums on how to setup a multiple pinging devices and if one of the ip`s fails a mail needs to be sent out ........ I have gone through these samples to see what was going on. I can`t even just get one of them to run to see how it looks like .......

1.

2.

Please remember that I am still a newb at all of this and on programming itself so please try and put it in "layman`s terms"......... I have tried to update two of the above posts but to no sucess ....... Please I some can just explain to me where I need to do the changes to make it work, It will be mostly appreciated .......

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



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

$INIFULLPATH = @WindowsDir & "\Settings.ini"
$TMPDATSTORE = @WindowsDir & "\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(@WindowsDir & "\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 $i = 1 To $OfflineCheck[0][0]
       $CurrentOffline = $CurrentOffline & @CRLF & $OfflineCheck[$i][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

I get the following error .......

(63) : ==> Subscript used with non-Array variable.:
For $i = 1 To $OfflineCheck[0][0]
For $i = 1 To $OfflineCheck^ ERROR
->14:04:14 AutoIT3.exe ended.rc:1
>Exit code: 1 Time: 2.145

Please if someone can just show me how to fix it ........

Regards,

Chovie

 


..... To Be The Best You Have To Beat The Best .....

Share this post


Link to post
Share on other sites



If your INI file lists no servers as being offline, then no array will be created and you will get that error message. Try wrapping the For...Next statement in an If statment checking to see if it is an array using IsArray. Something like:

If IsArray($OfflineCheck) Then
          <code here>
EndIf

However, I would suggest writing your own code so the program will do exactly what you want. Writing whether something is online or offline to an INI file is inefficient. I would suggest reading your server list to an array and storing whether it is online or offline in a second dimension.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

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