Sie sind auf Seite 1von 4

'**********************************************************************************

*****************
'**********************************************************************************
*****************
' This script was written to parse the OPAL log for a registration issue due to a
network break/stop
'causing OPAL to register to a ESS (Backup Gatekeeper) that was provided at the
time of initial
'registration. OPAL will not revert back to the Primary Gatekeeper until it has
been restarted. This
'script will parse the OPAL log for the error and restart the services if found.
Maintain the send email part. do not move it to below other wise you will receive
emails even if the services are up.
'JamesDavis
'**********************************************************************************
*****************
'**********************************************************************************
*****************

'******************************************
'Elvates Privlage to Administrator
'******************************************
Set WshShell = WScript.CreateObject("WScript.Shell")

If WScript.Arguments.Length = 0 Then
Set ObjShell = CreateObject("Shell.Application")

ObjShell.ShellExecute "wscript.exe" _
, """" & WScript.ScriptFullName & """ RunAsAdministrator", ,
"runas", 1

WScript.Quit

Else

'******************************************
'Log File and Phrase to be parsed
'******************************************

Const ForReading = 1

strFileName = "D:\Cyara\logs\Opal\Opal.log"

strFailed = "registrationRequest rejected: discoveryRequired"

strSucceeded = "Registered"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

strText = objFile.ReadAll

objFile.Close

'******************************************
'Service Stopped if Failed String Found
'******************************************
IF InStr(strText, strFailed) Then

strServiceName = "Cyara Voice Gateway"

Set objWMIService = GetObject("winmgmts:


{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery("Select * from


Win32_Service Where Name ='" & strServiceName & "'")

For Each objService in colListOfServices

objService.StopService()

Next

strServiceName = "CyaraCallEngine"

Set objWMIService = GetObject("winmgmts:


{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery("Select * from


Win32_Service Where Name ='" & strServiceName & "'")

For Each objService in colListOfServices

objService.StopService()

WScript.Sleep 10000

Next

'************************************************************
'Uncomment to delete previous log after services have stopped
'************************************************************

'Set obj = CreateObject("Scripting.FileSystemObject")

'obj.DeleteFile("D:\Cyara\logs\Opal\Opal.log"),DeleteReadOnly

Dim objFSO, Stuff, WriteStuff, dateStamp

dateStamp = Now()

'Log file written if phrease found

Stuff = "Registration Rejection Found" & datestamp

'wscript.echo stuff

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set WriteStuff =
objFSO.OpentextFile("D:\Cyara\logs\Opal\OPAL_Rejection.txt", 8, True)

WriteStuff.WriteLine(Stuff)
WriteStuff.close

'************************************************************
'Update Email to desired deliveries
'************************************************************
SendEmail("UPDATE With to Email")
'SendEmail("UPDATE With to Email if second is needed")

'************************************************************
'Serivces Started backup
'************************************************************

strServiceName = "Cyara Voice Gateway"

Set objWMIService = GetObject("winmgmts:


{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery ("Select * from


Win32_Service Where Name ='" & strServiceName & "'")

For Each objService in colListOfServices

objService.StartService()

WScript.Sleep 60000 'Sleep added to give OPAL time to start prior


to starting CE

Next

strServiceName = "CyaraCallEngine"

Set objWMIService = GetObject("winmgmts:


{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery ("Select * from


Win32_Service Where Name ='" & strServiceName & "'")

For Each objService in colListOfServices

objService.StartService()

Next

ELSEIF InStr(strText, strSucceeded) Then

dateStamp = Now()

'Log file written if phrease found

Stuff = "No Error Found" & datestamp

'wscript.echo stuff

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set WriteStuff =
objFSO.OpentextFile("D:\Cyara\logs\Opal\OPAL_NoErrors.txt", 2, True)

WriteStuff.WriteLine(Stuff)

WriteStuff.close

End IF
End IF

'************************************************************
'Update From, Subject, Textbody and SMTP address
'************************************************************

Function SendEmail(toEmail)
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "webportal@cyarasolutions.com"
objEmail.To = toEmail

objEmail.Subject = "UPDATE"
objEmail.Textbody = "UPDATE"

objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"UPDATE"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25
objEmail.Configuration.Fields.Update

objEmail.Send
End Function

Das könnte Ihnen auch gefallen