Using scripting host to develop and test MOM Scripts.
Developing and testing MOM scripts sometimes can be tricky, because you can’t simply cut and paste VBS which works with scripting host to MOM. Let me share how I develop and test scripts.
My typical project folder looks like this:
Lib
Lib\backend-ws.vbs
Lib\mom.vbs
middleend-discovery-build.cmd
middleend-discovery.vbs
middleend-discovery.wsf
middleend-performance-build.cmd
middleend-performance.mom
middleend-performance.vbs
middleend-performance.wsf
Toolkit
Toolkit\parse.vbs
Each MOM script consists of main VBS module, which has the same name as a script, Scripting Host project file (WSF), CMD, which combines all scripts together into .MOM file. After that you just simply copy and paste MOM file to your MOM Administrators console.
"Lib" folder is a library, where we can see two scripts – one of them is some data provider script, the other one (mom.vbs) is a standard library, which contains all mom-specific functions. Let’s take a look on its’ fragment:
Option Explicit 'NON-MOM
‘skipped
Public Sub CreateEvent(iEventID, iEventType, sMessage, sCategory)
'MOM On Error Resume Next
Dim oNewEvent
' Create a new event
'MOM Set oNewEvent = ScriptContext.CreateEvent()
' Set event properties
'MOM oNewEvent.Message = sMessage
'MOM oNewEvent.EventNumber = iEventID
'MOM oNewEvent.EventType = iEventType
'MOM oNewEvent.Category = sCategory
' Submit the event
'MOM ScriptContext.Submit oNewEvent
wscript.echo "EventID: " & iEventID & ", Message: " & sMessage 'NON-MOM
Set oNewEvent = Nothing
End Sub
As you could notice, I use comments with some value to distinguish MOM lines from non-MOM lines. I use parser (Toolkit\parse.vbs), which ignores all ‘NON-MOM lines and uncomments all ‘MOM lines.
That’s it! Now all my scripts being tested and work in MOM right after I tested them in Scripting Host!
You can download example.zip and try my technique.