December 04
MOM 2005 Stats to Jet Database Redux
Just in time for the holiday season, a new and improved version of MOM_Report_to_Database.vbs
This script takes in two arguments, the MOM Server name and the Management Group Name, collects the mom daily statistics and puts them into a database D:\MOMMGT\MOMRPT.MDB.
This will allow for reporting on multiple Management Groups.
For full details please see my prior posting http://myitforum.com/articles/2/view.asp?id=10257
If your already using the original script and database only a few modifications will have to be made.
The database will have to have a row called MGName added, and the scheduled task will have to have the parameters added for the /MOMServer:ServerName /MGName:ManagementGroupName
There is error checking to make sure that there are 2 parameters, if the two parameters are not there, the script will quit with the parameters that are required.
Usage:
cscript mom_report_to_database.vbs /MOMServer:MOMServerName /MGName:MOMManagementGroupName
'Start Of Code
'========================================================
' Author: Scott Moss
' date DEC 4, 2007
' Mom_report_to_Database2.vbs This one uses Named Arguments
' usage cscript mom_report_to_database.vbs /MOMServer:MOMServerName /MGName:MOMManagementGroupName
' disclaimer use at your own risk.
' mom script that will collect daily stats for mom and put them in a
' jet db to run your onw reports against it. Put Script in same folder w/ DB.
' Run as a scheduled task at 11:59 PM every day from MOM Server
' Requirements
' Create Scheduled Task to run this vb script every night at 11:59 pm.
' *** the objects in MSFT_TodayStatistics zero out at 11:59:59 pm ***
' Create Access Database MOMRPT.MDB
' Create Table called momdata
' Create field names that correspond with the recordset objects below
' Date, MGName, ComputerGroups, Monitored, CriticalErrors, etc.
' Must give credit to Don Hite. His idea to dump to excel gave me the idea to dump it to a db.
'=======================================================
'cscript mom_report_to_database.vbs /MOMServer:MOMServerName /MGName:MOMManagementGroupName
' Verify that 2 arguments were passed
iNumberOfArguments = WScript.Arguments.Count
If iNumberOfArguments = 2 Then
'
Else
Wscript.Echo "Error: invalid number of arguments entered. " & _
"cscript mom_stats_to_JetDB_Argument.vbs /MOMServer:MOMServerName /MGName:MOMManagementGroupName"
Wscript.Quit
End If
Set colNamedArguments = WScript.Arguments.Named
strMOMServer = colNamedArguments.Item("MOMServer")
strMGName = colNamedArguments.Item("MGName")
'mom part
strComputer = strMOMServer
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MOM")
Set colItems = objWMIService.ExecQuery("Select * from MSFT_TodayStatistics")
dtmThisDate = (Now)
'database part
Const adOpenStatic = 3
Const adLockOptimistic = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
"Provider = Microsoft.Jet.OLEDB.4.0; " & _
"Data Source = D:\MOMMGT\momrpt.mdb"
objRecordSet.Open "SELECT * FROM momdata" , _
objConnection, adOpenStatic, adLockOptimistic
For Each objItem In colItems
objRecordSet.AddNew
objRecordSet("Date") = dtmThisDate
objRecordSet("MGName") = strMGName
objRecordSet("ComputerGroups") = objItem.TotalComputerGroups
objRecordSet("Monitored") = objItem.TotalComputersMonitored
objRecordSet("CriticalErrors") = objItem.TotalCriticalErrors
objRecordSet("TotalErrors") = objItem.TotalErrors
objRecordSet("EventsToday") = objItem.TotalEventsToday
objRecordSet("NewAlertsToday") = objItem.TotalNewAlertsToday
objRecordSet("SecurityBreaches") = objItem.TotalSecurityBreaches
objRecordSet("ServiceLevelExceptions") = objItem.TotalServiceLevelExceptions
objRecordSet("ServicesUnavailable") = objItem.TotalServicesUnavailable
objRecordSet("UnresolvedAlerts") = objItem.TotalUnresolvedAlerts
objRecordSet("TotalWarnings") = objItem.TotalWarnings
objRecordSet.Update
objRecordSet.Close
objConnection.Close
Next
'End Of Code