'*******************************************************************************************
'*
'* Function:
'* ---------
'* AntigenProcessChecker.vbs
'* $Revision: 4 $
'*
'* Purpose:
'* --------
'* Monitors Scan Job Processes by counting them to make sure the correct number are present
'*
'* Parameters:
'* -----------
'* Process
'* TextLog
'*
'* Parameter definitions:
'* ----------------------
'* 1. Process => defines the name of the Scan Job process that is being monitored
'* 2. TextLog => defines whether this scripts logs entries to a text file under the local
'* Antigen installation folder. Possible Values are true ; false
'*
'*******************************************************************************************
AntigenInstallPath = RetrieveRegValue (REG_KEY & "Antigen For Exchange","InstalledPath", 1)
InstalledProduct = "Antigen For Exchange"
If IsNull(AntigenInstallPath) Then
AntigenInstallPath = RetrieveRegValue (REG_KEY & "Antigen For SMTP","InstalledPath", 1)
InstalledProduct = "Antigen For SMTP"
End If
If IsNull(AntigenInstallPath) Then
WriteMOMEvent "TASK ERROR: Unable To Retrieve Antigen Installation Path", 1, INSTALL_PATH_FAIL
ScriptContext.Quit
End If
If TextLogParameter = "true" then
CreateLogFolder(AntigenInstallPath)
End If
WriteLog "NULL"
WriteLog "Beginning Execution of ScanProcessMonitor Script to check status of " & ProcessParameter
Select Case ProcessParameter
Case "AntigenInternet.exe"
NumSG = 0
AntigenService = ANTIGEN_IMC
ExchService = SMTP_SERV
Case "AntigenRealtime.exe"
NumSG = GetNumStorageGroups()
AntigenService = ANTIGEN_STORE
ExchService = EXCH_STORE
End Select
If CheckServiceRunning (TextLogParameter, AntigenService, ExchService) Then
If CheckScanJobHook(TextLogParameter, ProcessParameter) Then
If ExpectedNumProcesses (ProcessParameter, InstalledProduct, NumSG) <= ActualNumProcesses (ProcessParameter) Then
WriteLog "Process Count OK"
Else
Select Case ProcessParameter
Case "AntigenInternet.exe"
WriteMOMEvent "MOM detected an AntigenInternet.exe process may have crashed due to an exception", 1, INTERNET_COUNT_FAIL
Case "AntigenRealtime.exe"
WriteMOMEvent "MOM detected an AntigenRealtime.exe process may have crashed due to an exception", 1, REALTIME_COUNT_FAIL
End Select
WriteLog "Process Count Incorrect - Possible Process Failure"
End If
End If
End If
WriteLog "Finished Execution of ScanProcessMonitor Script"
'***********************************************************************
'*
'* Function: GetNumStorageGroups()
'*
'* Purpose: Gets number of Storage Groups on the server
'*
'***********************************************************************
Set objCDOEXMExchangeServer = CreateObject("CDOEXM.ExchangeServer")
objCDOEXMExchangeServer.DataSource.Open(ServerName)
Set objStorageGroup = CreateObject("CDOEXM.StorageGroup")
i=0
For Each urlStorageGroup In objCDOEXMExchangeServer.StorageGroups
i = i + 1
Next
Set objStorageGroup = Nothing
Set objCDOEXMExchangeServer = Nothing
GetNumStorageGroups = i
End Function
'***********************************************************************
'*
'* Function: ExpectedNumProcesses()
'*
'* Purpose: Determines expected number of process instances
'*
'***********************************************************************
Function ExpectedNumProcesses (ProcessParameter, InstalledProduct, NumSG)
If ProcessParameter = "AntigenInternet.exe" Then
ExpectedNumProcesses = RetrieveRegValue (REG_KEY & InstalledProduct,"InternetProcessCount", 2)
Else
RetrieveValue = RetrieveRegValue (REG_KEY & InstalledProduct,"RealtimeProcessCount", 2)
ExpectedNumProcesses = RetrieveValue * NumSG + 1
End If
WriteLog "Expected Number of " & ProcessParameter & " Processes = " & ExpectedNumProcesses
End Function
'***********************************************************************
'*
'* Function: ActualNumProcesses()
'*
'* Purpose: Determines actual number of process instances
'*
'***********************************************************************
Function ActualNumProcesses (ProcessParameter)
i = 0
Set refWMI = GetObject("winMgmts:")
strQuery = "SELECT * FROM Win32_Process WHERE Name='" & ProcessParameter & "'"
Set colProcesses = refWMI.ExecQuery(strQuery)
For Each refItem In ColProcesses
i = i + 1
Next
Set refWMI = Nothing
Set colProcesses = Nothing
ActualNumProcesses = i
WriteLog "Actual Number of " & ProcessParameter & " Processes = " & ActualNumProcesses
End Function
'***********************************************************************
'*
'* Function: CheckScanJobHook()
'*
'* Purpose: Checks corresponding process is running
'*
'***********************************************************************
Function CheckScanJobHook(TextLogParameter, ProcessParameter)
EnableValue = RetrieveRegValue (REG_KEY & InstalledProduct,"AntigenEnabled", 2)
If ProcessParameter = "AntigenInternet.exe" Then
If EnableValue = 2 or EnableValue = 3 Then
CheckScanJobHook = True
Else
CheckScanJobHook = False
End If
End If
If ProcessParameter = "AntigenRealtime.exe" Then
If EnableValue = 1 or EnableValue = 3 Then
CheckScanJobHook = True
Else
CheckScanJobHook = False
End If
End If
If CheckScanJobHook Then
WriteLog "Scan Interface Active...Process Check Proceeding"
Else
WriteLog "Scan Interface Inactive...Process Check Aborting"
End If
End Function
'***********************************************************************
'*
'* Function: CheckServiceRunning()
'*
'* Purpose: Checks corresponding process is running
'*
'***********************************************************************
Function CheckServiceRunning (TextLogParameter, strService1, strService2)
Dim refWMI
Dim refService
Set refWMI = GetObject("winMgmts:")
Set refService = refWMI.Get("Win32_Service.Name='" & strService1 & "'")
If refService.State = "Running" Then
Set refService = refWMI.Get("Win32_Service.Name='" & strService2 & "'")
If refService.State = "Running" Then
WriteLog strService1 & " and " & strService2 & " Service running...Process Check Proceeding"
CheckServiceRunning = True
Else
WriteLog strService2 & " Service not running...Process Check Aborting"
CheckServiceRunning = False
End If
Else
WriteLog strService1 & " Service not running...Process Check Aborting"
CheckServiceRunning = False
End If
Dim objFSO
set objFSO = CreateObject ("Scripting.FileSystemObject")
If objFSO.FolderExists(AntigenInstallPath & "\MOMLogs") = 0 then
objFSO.CreateFolder(AntigenInstallPath & "\MOMLogs")
End If
Set objFS) = Nothing
End Function
'***********************************************************************
'*
'* Function: WriteLog()
'*
'* Purpose: Writes script activity and errors to a log file
'*
'***********************************************************************
Function WriteLog (strLogText)
Dim objfs
Dim objf
Dim strTimeStamp
If TextLogParameter = "true" Then
On Error Resume Next
Err.Clear
Set objfs = CreateObject("Scripting.FileSystemObject")
Set objf = objfs.OpentextFile(AntigenInstallPath & "\MOMLogs\" & "Tasks.log", 8, False)
' If log file doesn't exist - create it
If Err.Number <> 0 Then
Set objf = objfs.CreatetextFile(AntigenInstallPath & "\MOMLogs\" & "Tasks.log", False)
Err.Clear
End If
If strLogText = "NULL" then
objf.WriteLine("")
Else
strTimeStamp = Date & " " & Time & " "
objf.WriteLine(strTimeStamp & strLogText)
End If
End If
Set objfs = Nothing
Set objf = Nothing
End Function
'********************************************************************
'*
'* Function: RetrieveRegValue
'*
'* Purpose: Retrieves String Value from Registry
'*
'********************************************************************
Function RetrieveRegValue (Key, strValueName, intValueType)
' intValueType -> 1 = String Value
' -> 2 = DWORD Value
const HKEY_LOCAL_MACHINE = &H80000002
Dim strServerName
Dim objReg
Dim strRegValue
On Error Resume Next
Err.Clear
Set objReg=GetObject("winmgmts:\root\default:StdRegProv")
If Err.Number <> 0 Then
Err.Clear
strRegValue = NULL
Else
Select Case intValueType
Case 1
strErr = objReg.GetStringValue (HKEY_LOCAL_MACHINE, Key, strValueName, strRegValue)
Case 2
strErr = objReg.GetDWORDValue (HKEY_LOCAL_MACHINE, Key, strValueName, strRegValue)
End Select
' if reading the registry fails via wmi return error
If strErr <> 0 then
strRegValue = NULL
End If
End If