目的:Essentials サーバーに 10 日以内に接続しているかどうかを判断するため、Windows Update エージェントを監視します。
このコンピューターは、10 日以内に SCE サーバーに接続していません。
このコンピューターは、自動更新を行うように構成されていません。
SCE サーバー上で製品構成ウィザードを実行します。
Target | Microsoft.SystemCenter.Essentials.WUAgent |
Parent Monitor | System.Health.AvailabilityState |
Category | Custom |
Enabled | True |
Alert Generate | False |
Alert Auto Resolve | True |
Monitor Type | Microsoft.Windows.TimedScript.TwoStateMonitorType |
Remotable | False |
Accessibility | Internal |
RunAs | Default |
<UnitMonitor ID="Microsoft.SystemCenter.Essentials.WUAgent.ConnectionUnitMonitor" Accessibility="Internal" Enabled="onEssentialMonitoring" Target="Microsoft.SystemCenter.Essentials.WUAgent" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="false" Priority="Normal" TypeID="Windows!Microsoft.Windows.TimedScript.TwoStateMonitorType" ConfirmDelivery="false">
<Category>Custom</Category>
<OperationalStates>
<OperationalState ID="UIGeneratedOpStateId027701d98d0b4c61b852c8de59614b8b" MonitorTypeStateID="Error" HealthState="Warning"/>
<OperationalState ID="UIGeneratedOpStateId8466cc70f29e4d4cac921b3942b440f4" MonitorTypeStateID="Success" HealthState="Success"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>3600</IntervalSeconds>
<SyncTime/>
<ScriptName>CheckWUConnection.vbs</ScriptName>
<Arguments/>
<ScriptBody>
'*************************************************************************
' Script Name - CheckWUAgentConnection.vbs
'
' Purpose - Checks to see if computer has connected to the Essentials server within last 10 days
'
' Assumptions - Script is run as a runtime task
'
' Parameters - UpdateServer Name
'
' (c) Copyright 2006, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************
OPTION EXPLICIT
SetLocale("en-us")
CONST HKLM = &H80000002
Const SCRIPT_NAME = "CheckWUAgentConnection"
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4
Const EVENT_ID_SCRIPT_ERROR = 1000
Const EVENT_ID_SUCCESS = 99
Dim oAPI, objArgs, oBag
Dim strWUServer, objAutoUpdate, objResults, dateLastSearch, objReg, activeTimeBias, dateSystemNow, dateUtcNow
'Create OpsMgr object
Set oAPI = CreateObject("Mom.ScriptAPI")
' Create a property bag
Set oBag= oAPI.CreatePropertyBag()
' Create an AutoUpdate object
set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")
If objAutoUpdate Is Nothing then
ScriptError "Unable to create Microsoft.Update.AutoUpdate object. " & GetErrorString(Err)
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
End If
On Error Resume Next
' Get the results from AutoUpdate
set objResults = objAutoUpdate.Results
If IsNull(objResults)then
ScriptError "Unable to get results from Microsoft.Update.AutoUpdate object. " & GetErrorString(Err)
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
Else
' Get the LastSearchSuccessDate from the Results in UTC time format
dateLastSearch = objResults.LastSearchSuccessDate
' Get the ActiveTimeBias from registry to calculate UTC time
Set objReg = GetObject("winmgmts:root\default:StdRegProv")
If objReg Is Nothing then
ScriptError "Unabled to bind to StdRegProv. " & GetErrorString(Err)
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
End If
' Get current Active Time Bias from registry
objReg.GetDWORDValue HKLM, "System\CurrentControlSet\Control\TimeZoneInformation", "ActiveTimeBias", activeTimeBias
If IsNull(activeTimeBias) Then
ScriptError "Could not find ActiveTimeBias information needed to convert current time to UTC. " & GetErrorString(Err)
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
End If
' Get current system date & time
dateSystemNow = now()
' Get current UTC date & time
dateUtcNow = dateAdd("n", activeTimeBias, dateSystemNow)
' Check to see if computer is contacted in last 10 days or not
If DateDiff("d",dateLastSearch,dateUtcNow) > 10 then
Call oBag.AddValue("WUConnect", "Bad")
Call oAPI.Return(oBag)
Quit()
Else
Call oBag.AddValue("WUConnect", "Good")
Call oAPI.Return(oBag)
Quit()
End If
End If
'******************************************************************************
Sub ScriptError(strError)
'
' Purpose: Records a script error.
'
' Parameters: strError, the description of the error to record
'
CreateEvent EVENT_ID_SCRIPT_ERROR, EVENT_TYPE_WARNING, "The script '" & SCRIPT_NAME & "' failed while " & strError
End Sub
'******************************************************************************
Function GetErrorString(oErr)
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr, the error object
'
' Return: String, the description for the error. (Includes the error code.)
'******************************************************************************
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description
On Error Resume Next
If 0 >= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &HFFFF0000
Const HiWord8007 = &H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF
If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " & (lErr And LoWordMask))
Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i < 5)
strErr = strMessage
End If
End If
End If
GetErrorString = vbCrLf & "The error returned was: '" & strErr & "' (0x" & Hex(lErr) & ")"
End Function
'******************************************************************************
Sub CreateEvent(lngEventID, lngEventType, strMessage)
'
' Purpose: To create a MOM event
'
' Arguments:lngEventID, the event ID
' lngEventType, the event type (see values at top of file)
' strMessage, the message text for the event
'******************************************************************************
oAPI.LogScriptEvent "Check WU Agent Config", lngEventID, lngEventType, strMessage
End Sub
'*************************************************************************
Function Quit()
WScript.Quit()
End Function
'****************************************************************************
</ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='WUConnect']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Bad</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='WUConnect']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Good</Value>
</ValueExpression>
</SimpleExpression>
</SuccessExpression>
</Configuration>
</UnitMonitor>