Jump to content

Recommended Posts

Posted (edited)

This script is called by another routine and processes either an email and/or an sms alert as well as logging the date time stamped event.

Would be interested in any comments in relation to more efficient use of code especially the emailsms processing.

SMS processing is based on sending an Email to an Email to SMS service provider who can process both local and international SMS's

Many thanks to those who have helped me by explaining as well as providing code examples which have been used in the development of this script.

;) Ant

#include <INet.au3>

#include <Date.au3>

; The availability of the INI file has already been checked in a

; startup process associated with this script

; Read INI file variables

;

$var5 = IniRead(@ScriptDir&"\xyz.ini", "stealth", "mode", "0")

$var9 = iniread(@scriptdir&"\abc.ini", "alerts", "email", "0")

$var10 = iniread(@scriptdir&"\abc.ini", "alerts", "sms", "0")

$var11 = iniread(@scriptdir&"\abc.ini", "server", "ISP", "")

$var12 = iniread(@scriptdir&"\abc.ini", "fromname", "name", "")

$var13 = iniread(@scriptdir&"\abc.ini", "fromaddress", "from", "")

$var14 = iniread(@scriptdir&"\abc.ini", "toaddress", "emailaddr", "")

$var15 = iniread(@scriptdir&"\abc.ini", "toaddress", "smsaddr", "")

; Checks for email alert processing

;

If $var9() = 0 AND $var10() = 0 then

$file = FileOpen(@scriptdir & "\MonitorLog.txt", 9)

FileWriteLine($file, "Alerts processing switch OFF " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

FileClose($file)

Exit

EndIf

;Set Stealth Mode

;

if $var5() = 1 then

Opt("TrayIconHide", 1)

EndIf

;Wait for network connectivity

;

While 1

$IsCon=DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)

if $iscon[0] = 1 then ExitLoop

Sleep(60000) ; The value in this statement will become variable read from an INI file

wend

; Send EMAIL/SMS Alert

;

For $i = 2 to 1 step -1

if $i = 1 and $var10() + $var9() = 1 Then

Exit

EndIf

$s_SmtpServer = $var11

$s_FromName = $var12

$s_FromAddress = $var13

If $i = 2 and $var9() = 1 then

$s_ToAddress = $var14

ElseIf $i = 2 and $var10() = 1 Then

$s_ToAddress = $var15

EndIf

If $i = 1 and $var10() = 1 Then

$s_ToAddress = $var15

EndIf

$s_Subject = "Monitor"

Dim $as_Body[3]

$as_Body[0] = "Manual shut down: " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC)

$as_Body[1] = ""

$as_Body[2] = "End of Message"

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

$file = FileOpen(@scriptdir & "\MonitorLog.txt", 9)

If $i = 2 and $var9() = 1 then

FileWriteLine($file, "Monitor Email Alert " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

Elseif $i = 2 or $i = 1 and $var10() = 1 then

FileWriteLine($file, "Monitor SMS Alert " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

EndIf

FileClose($file)

Next

Exit

;

;End of script

Edited by anixon

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...