Сброс всех локальных оповещений TMG

Microsoft.Forefront.TMG.ResetAllLocalISAAlerts (Task)

Сброс (удаление) всех оповещений для целевого сервера

Element properties:

TargetMicrosoft.Forefront.TMG.Server
AccessibilityInternal
CategoryMaintenance
EnabledTrue
RemotableFalse
Timeout300

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction Microsoft.Windows.ScriptWriteAction Default

Source Code:

<Task ID="Microsoft.Forefront.TMG.ResetAllLocalISAAlerts" Accessibility="Internal" Enabled="true" Target="Microsoft.Forefront.TMG.Server" Timeout="300" Remotable="true">
<Category>Maintenance</Category>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>ResISAAlerts.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>

'Copyright (c) Microsoft Corporation. All rights reserved.
'*************************************************************************
' $ScriptName: "ResISAAlerts" $
'
' Purpose: Resets (clears) all alerts for the targeted server
'
' $Arguments: This script takes in 1 optional argument. Anything more will generate an error.
' The argument is optional and it should be used to indicate whether or not to
' enable tracing. If the value argument is "TRACE ON" the tracing will be enabled.
' For any other value/no value the tracing is disabled.
'
' $File: ResISAAlerts.vbs $
'*************************************************************************

Option Explicit
SetLocale("en-us")

'===============
' Global variables
'===============
Dim sUtilObj
Dim sErrObj
Dim sBlnTraceRefreshed

Const conForWriting = 2
Const conForAppending = 8
Const conTraceOn = "TRACEON"

sBlnTraceRefreshed = False


'##########################################################################
' Class: Util
' Description: Contains methods for tracing, generating events,
' creating objects
'##########################################################################
Class Util

' Used to say to LogMessage when/how to print the message.
Public DBG_NONE
Public DBG_ERROR
Public DBG_WARNING
Public DBG_TRACE
Public HKEY_LOCAL_MACHINE
Public MOMApiObject
'Internal Debug Level
Private m_nDebugLevel
'Name of the logfile for tracing
Private m_logFileName

'---------------
' Properties
'---------------
Public Property Get LogFileName
LogFileName = m_logFileName
End Property

Public Property Let LogFileName(ByVal fileName)
If Not (IsEmpty(filename) OR IsNull(fileName)) Then
m_logFileName = fileName
Else
sErrObj.GenerateMOMErrorEvent("Log file name cannot be empty or null")
End If
End Property

'---------------
' Methods
'---------------
'=============
' Method: Class_Initialize
' Description: This is the constructor
'=============
Private Sub Class_Initialize()
' Initialize Debug level constants
DBG_TRACE = 1
DBG_WARNING = 2
DBG_ERROR = 3
DBG_NONE = 4

'by default only errors are logged
m_nDebugLevel = DBG_ERROR
'Create a MOM Script API object
Set MOMApiObject = MomCreateObject("MOM.ScriptAPI")
End Sub

'=============
' Method: Class_Terminate
' Description: This is the destructor
'=============
Private Sub Class_Terminate()
Set MOMApiObject = Nothing
End Sub

'=============
' Method: SetDebugLevel
' Description: To change the debugging output level of information
' generated by this utility.
' Parameters: nLevel - Level, either DBG_NONE, DBG_TRACE,
' DBG_WARNING or DBG_ERROR
'=============
Public Sub SetDebugLevel(ByVal nLevel)
m_nDebugLevel = nLevel
End Sub

'=============
' Method: WriteToTrace
' Description: Writes text to a trace file. For every run of the script,
' the trace file is recreated.
' Parameters: msg - Any text that needs to be written to the trace file.
'=============
Public Sub WriteToTrace (ByVal msg)
Dim fso, traceFileObj, objErr

Set objErr = new Error

If Not m_nDebugLevel = DBG_TRACE Then
Exit Sub
End If

On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.number &lt;&gt; 0 Then objErr.PrintError
On Error Goto 0

'Checking whether the trace file is recreated in this run
If Not sBlnTraceRefreshed Then
On Error Resume Next
Set traceFileObj = fso.OpenTextFile(sUtilObj.LogFileName, conForWriting, True)
If Err.number &lt;&gt; 0 Then objErr.PrintError
On Error Goto 0
sBlnTraceRefreshed = True
Else
On Error Resume Next
Set traceFileObj = fso.OpenTextFile(sUtilObj.LogFileName, conForAppending, True)
If Err.number &lt;&gt; 0 Then objErr.PrintError
On Error Goto 0
End If

msg = FormatDateTime(Date(), vbShortDate) &amp; " " &amp; _
FormatDateTime(Time(), vbLongTime) &amp; "[" &amp; _
WScript.ScriptName &amp; "]--&gt; " &amp; msg
On Error Resume Next
traceFileObj.WriteLine(msg)
If Err.number &lt;&gt; 0 Then objErr.PrintError
On Error Goto 0

traceFileObj.Close
Set traceFileObj = Nothing
Set fso = Nothing

End Sub

'=============
' Method: MomCreateObject
' Description: Creates an Object and includes neccessary error handling
' Parameters: sProgramId - The Program ID of the object type to be created.
' Returns: Returns the object that is created.
'=============
Public Function MomCreateObject(ByVal sProgramId)
Dim errMsg
On Error Resume Next
Set MomCreateObject = CreateObject(sProgramId)

If Err.number &lt;&gt; 0 Then
errMsg = "Unable to create automation object '" &amp; sProgramID &amp; "'" &amp; "--" &amp; _
"Error- Number: " &amp; Err.number &amp; " Description:" &amp; Err.Description &amp; _
" Source:" &amp; Err.Source
If lcase(sProgramId) = lcase("MOM.ScriptAPI") Then
CreateOpsMgrEvent 312, WScript.ScriptName, "ERROR", errMsg
ThrowEmptyDiscoveryData()
Quit()
Else
sErrObj.GenerateMOMErrorEvent(errMsg)
End If
End If
End Function

'=============
' Method: CreateOpsMgrEvent
' Description: Create an event in the Operations Manager log
' Parameters: eventId - ID of the event to be created
' source - Source of this event
' eventType - String specifying the type of event (ERROR, INFORMATION, SUCCESS, WARNING)
' desc - Description of event.
' Returns: Returns the object that is created.
'=============
Public Sub CreateOpsMgrEvent(ByVal eventId, ByVal source, ByVal eventType, ByVal desc)
Dim strCommand, WshShell

On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
strCommand = "cmd /c eventcreate /ID " &amp; eventID &amp; _
" /SO " &amp; """" &amp; source &amp; """" &amp; _
" /T " &amp; """" &amp; eventType &amp; """" &amp; _
" /D " &amp; """" &amp; desc &amp; """" &amp; _
" /L " &amp; """Operations Manager"""
WshShell.Run strCommand

If Err.number &lt;&gt; 0 Then WScript.Echo "Error in 'Util.CreateOpsMgrEvent()'"
End Sub

End Class

'##########################################################################
' Class: Error
' Description: Contains methods to Save Error details, Raise Error,
' Clear Error
' Assumptions: Util Object is created and available to use. It should be named
' as "sUtilObj"
'##########################################################################
Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile
Private ERROR_FILE_NOT_FOUND

Public Sub Class_Initiaze()
ERROR_FILE_NOT_FOUND = 2
End Sub

Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub
Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = m_lNumber
End Property
Public Property Get Source()
Source = m_sSource
End Property
Public Property Get Description()
Description = m_sDescription
End Property
Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property

Public Sub PrintError
WScript.Echo "Error writing to trace." &amp; _
"Error: Number-" &amp; Err.number &amp; _
"; Description-" &amp; Err.Description &amp; _
"; Source-" &amp; Err.Source
End Sub
'=============
' Method: GenerateMOMErrorEvent
' Description: Uses the "MOM Script API" object to log a script event. Appends the Error
' details to the message sent as parameter
' Parameters: strMessage - contains the custom text to write to the event
'=============
Public Function GenerateMOMErrorEvent(ByVal strMessage)
strMessage = strMessage &amp; " Error - Number:" &amp; m_lNumber &amp; _
" Source:" &amp; m_sSource &amp; _
" Description:" &amp; m_sDescription &amp; _
" HelpContext:" &amp; m_sHelpContext &amp; _
" HelpFile:" &amp; m_sHelpFile
On Error Resume Next
CreateScriptErrorEvent(strMessage)
Quit()
End Function

'=============
' Method: CreateScriptErrorEvent
' Description: Generate a MOM event with script error message in the
' Operations Manager Log.
' Parameters: strMessage - Message to write to the event
'=============
Public Function CreateScriptErrorEvent(ByVal strMessage)
On Error Resume Next
sUtilObj.MOMApiObject.LogScriptEvent WScript.ScriptName, 4001, 1, strMessage
End Function

'=============
' Method: ErrorCheck
' Description: Checks if an error occurred and writes the error to Operations Manager
' event log.
'=============
Public Sub ErrorCheck()
If Err.number &lt;&gt; 0 Then
Save
GenerateMOMErrorEvent("")
End If
End Sub

Public Sub ErrorCheckMsg(ByVal msg)
If Err.number &lt;&gt; 0 Then
Save
GenerateMOMErrorEvent(msg)
End If
End Sub

End Class

Sub Main()

Dim objFPCRoot, objFPCSignaledAlerts, objFPCSignaledAlert, arrArgs
Set sUtilObj = new Util
Set sErrObj = new Error

Set arrArgs = Wscript.Arguments
If arrArgs.Count &lt; 2 Then
If arrArgs.Count = 1 Then
'Check if Trace is ON
If (lcase(trim(arrArgs(0))) = lcase(conTraceOn)) Then
'Set the debug level to Trace
sUtilObj.SetDebugLevel(sUtilObj.DBG_TRACE)
'Set the trace log file name
sUtilObj.LogFileName = WScript.ScriptName &amp; ".trace"
End If
End If
Else
sErrObj.GenerateMOMErrorEvent("Invalid number of arguments passed to script.")
End if

sUtilObj.WriteToTrace "Start:" &amp; vbTab &amp; "Reset TMG Alerts"

Set objFPCRoot = sUtilObj.MomCreateObject("FPC.Root")

On Error Resume Next
Set objFPCSignaledAlerts = objFPCRoot.GetContainingServer().SignaledAlerts
sErrObj.ErrorCheckMsg "Error retrieving the FPCSignaledAlerts"
On Error Goto 0

If Not IsEmpty(objFPCSignaledAlerts) Then
sUtilObj.WriteToTrace "Found " &amp; objFPCSignaledAlerts.Count &amp; " Alerts"
For Each objFPCSignaledAlert in objFPCSignaledAlerts
objFPCSignaledAlert.Reset()
Next
Set objFPCSignaledAlerts = Nothing
Set objFPCSignaledAlert = Nothing
Else
sUtilObj.WriteToTrace "No FPCSignaledAlert objects found"
End If

sUtilObj.WriteToTrace "End:" &amp; vbTab &amp; "Reset TMG Alerts"

Set objFPCRoot = Nothing
Set sUtilObj = Nothing
Set sErrObj = Nothing
End Sub

Main()
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</WriteAction>
</Task>