VBScript: Is MOM monitoring this list of server names?

My last posting had a working script in it however; it was slapped together with out really thinking about what I really needed to find out, is MOM monitoring this list of server names. My last post only told us if the MOM Agent service was on the box, which has too many holes in it to mention here. So after thinking about it and because my long weekend plans got cancelled at the last minute I wrote this script.
It reads in the target list of servers to be checked and puts them into an array. Then queries the one point database for a list of agent managed machines, which is dumped into a text file then read into as another array. If a computer name in array is not in array two its name will be written to the Difference.txt file.Note that the character case in the compairson counts. MOMSRV01 is different than MOMsrv01 and MOMSRV01 will be written to the difference.txt file.
I'm just happy I will not ever have to do this manually ever!!
Hope someone else finds this useful.

'==========================================================================
' NAME: Scott Moss
' DATE  : 1/27/2008
' http://myitforum.com/cs2/blogs/smoss/default.aspx
' The problem, here is a list of servers, are they being monitored by mom?
' the input file checkmom.txt should have one server per line, it is loaded
' into an array, query against your OnePoint DB for agentmanaged computers
' which is loaded into an array, The arrays are compaired and the diff is output
' input file D:\checkmom.txt(user provided should be in all caps)
' input file D:\MOMAgentList.txt (created by script)
' output file D:\Differences.txt
' the array check is case sensitive momsrv01 is different than MomSrv01
' change sqlservername\instancenum to suite your environment
'==========================================================================

Const ForReading = 1
Const FOR_WRITING = 2
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const OverwriteExisting = True
Const ForWriting = 2
Const ForAppending = 8

Dim stringInputFile
Dim objFso
Dim objOutputFile
Dim strOutputFile
Dim arrFirst
Dim arrSecond
Dim strElementFirst
Dim strElementSecond
Dim blnExistsInSecond

stringInputFile = "D:\checkmom.txt"
strOutputFile = "D:\Differences.txt"

Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(strOutputFile) Then
Set objOutputFile = objFso.OpenTextFile(strOutputFile,FOR_WRITING)
Else
Set objOutputFile = objFso.CreateTextFile(strOutputFile)
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objectTextStream = objFSO.OpenTextFile(stringInputFile, ForReading)
arrFirst = Split(objectTextStream.ReadAll, vbCrLf)
objectTextStream.Close

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
    "Provider=SQLOLEDB;Data Source=SQLSERVERNAME\INSTANCENUM;" &_
    "Initial Catalog=onepoint;Trusted_Connection=Yes;"

objRecordSet.Open "select Name from Computer WHERE [IsConfigManager]=0 AND ManagedType = '2' AND (idConfigManager IS NULL OR idComputer <> idConfigManager) AND  IsAddedByServiceDiscovery = 0 AND [Type] <> 67108864 ORDER BY Name", _       
 objConnection, adOpenStatic, adLockOptimistic
objRecordSet.MoveFirst

strMomAgentList = "D:\MOMAgentList.txt"
Set objFile = objFSO.CreateTextFile(strMomAgentList)
Do Until objRecordSet.EOF   
 objFile.WriteLine objRecordSet.Fields.Item("Name")   
 objRecordSet.MoveNext
Loop
objFile.Close
objRecordSet.Close
objConnection.Close

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objectTextStream = objFSO.OpenTextFile(strMomAgentList, ForReading)
arrSecond = Split(objectTextStream.ReadAll, vbCrLf)
objectTextStream.Close

For Each strElementFirst In arrFirst
blnExistsInSecond = False
For Each strElementSecond In arrSecond
If strElementFirst = strElementSecond Then
blnExistsInSecond = True
Exit For
End If
Next
If Not blnExistsInSecond Then
objOutputFile.WriteLine strElementFirst & " is not being monitored by MOM"
End If
Next
objOutputFile.Close()
Set objOutputFile = Nothing
Set objFso = Nothing

Comments

No Comments