달력

5

« 2024/5 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

창이름으로 프로세스 정보를 기록하는 스크립트와 연계해 레지스트리에 모니터링할 프로세스(창 이름)을 기준으로 로그 파일에 존재 여부로 실행 중인지의 여부를 판단하는 SCOM 용 VBS VB 스크립트 모니터입니다. 아래 스크립트와 마찬가지로, 로그 파일 생성(변경) 시간이 10분 이상되었거나 내용이 없는 경우(헤더만 있는 경우)에는 스크립트를 종료합니다.


'==========================================================
'Log File Configuration
'==========================================================
sLogDir = "C:\Dimensiondata\"
sLogFile = "NOTEPAD.Log"
'==========================================================

'==========================================================
'Registry Key Path, the Name of String Value
'==========================================================
KeyPath = "SOFTWARE\DDK"
sName = "NOTEPAD.exe"
'==========================================================

'==========================================================
'State Mapping/Definition
'==========================================================
'Error State: Property[@Name='State'] equals ERROR
'Normal State: Property[@Name='State'] equals NORMAL
'Stopped Processes: $Data/Context/Property[@Name='StoppedProc']$
'==========================================================


'If Log File doesn't Exist Then Quit
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists(sLogDir&sLogFile) Then
Else
 Set oFSO = Nothing
 WScript.Quit
End If

'Check Log File Modified Date/Time
Set oFile = oFSO.GetFile(sLogDir&sLogFile)
FileModified = CDate(oFile.DateLastModified)
TimeGapMin = DateDiff("n",FileModified,Now)

If TimeGapMin > 10 Then
 Set oFSO = Nothing
 Set oAPI = CreateObject("MOM.ScriptAPI")
 Call oAPI.LogScriptEvent("DDK", 2001, 2, "Modified Date of Log File is Older than 10 Minutes. Modified Date of Log File("&sLogDir&sLogFile&") is "&FileModified&".")
 Set oAPI = Nothing
 WScript.Quit
End If

'Check Log File Content
sData = oFSO.OpenTextFile(sLogDir&sLogFile,1).ReadAll
arrLines = Split(sData,vbCrLf)
LineCount = UBound(arrLines)-1

If LineCount = 0 Then
 Set oFSO = Nothing
 Set oAPI = CreateObject("MOM.ScriptAPI")
 Call oAPI.LogScriptEvent("DDK", 2001, 2, "Log File("&sLogDir&sLogFile&") is Empty.")
 Set oAPI = Nothing
 WScript.Quit
End If

'Get Registry Value
Const HKLM = &H80000002
Set oReg = getObject("WINMGMTS:root\default:StdRegProv")
oReg.GetStringValue HKLM,KeyPath,sName,sValue

If IsNull(sValue) OR sValue = "" Then
 Set oReg = Nothing
 WScript.Quit
End If

arrValue = Split(sValue,"|")

'Check the Process is Exist in Log File, Except First Line
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
For i = 0 to Ubound(arrValue)
 tmpState = 0
 CurrLine = 1
 Do While CurrLine <> UBound(arrLines)
  tmpLine = Split(arrLines(CurrLine),"|")
  If Ucase(tmpLine(2)) = Ucase(arrValue(i)) Then
   tmpState = 1
  End If
  CurrLine =  CurrLine + 1
 Loop

 If tmpState = 0 Then
  StoppedProc = StoppedProc & arrValue(i)&", "
  Call oBag.AddValue(arrValue(i), "Not running")
 ElseIf tmpState = 1 Then
  Call oBag.AddValue(arrValue(i), "Running")
 End If
Next

If StoppedProc <> "" Then
 Call oBag.AddValue("State", "ERROR")
 Call oBag.AddValue("Stopped Process(es)",Left(StoppedProc,Len(StoppedProc)-2))
Else
 Call oBag.AddValue("State", "NORMAL")
End If

Call oAPI.Return(oBag)
Set oFSO = Nothing
Set oAPI = Nothing



:
Posted by 커널64