KB00032: Generating Custom MessageMaster Messages in VB

Description

You have VB programs that run in your enterprise, and you would like to make them generate MessageMaster messages that you and other IT Support staff can subscribe to.

Resolution

To illustrate, we will demonstrate with an example. We will write a simple program that checks for free disk space, and generates a custom MessageMaster message if it finds that the disk space is below 100MB.

1. Create your message in the MessageMaster hierarchy

In order to be able to generate a custom MessageMaster message, you first have to create a Message Definition for it. This is done from the MessageMaster Console, under the Message Admin menu. (Having to pre-define your messages may seem strange at first, but the benefits soon outweigh the inconvenience. See "Why do you have to pre-define message definitions", referenced below.)

First, decide where in the MessageMaster hierarchy you want to create your message. The levels of the hierarchy are Category, Application, Module, Version, Message. By default you will have two Categories, EventMaster (if you have EventMaster installed) and MessageMaster. In this example, we will create a third Category for our custom message, called In-house Applications.

Under the In-house Applications Category, create an Application called System Checks. Under that, create a Module called Disk Space Check. Under that, create a version called 1.0. Finally, under that, create a new Message definition called DS-1 (for Disk Space 1), just so that our message id has some meaning. Fill in the other details of the message definition as follows:

Field Value to enter
Severity Warning
Title @workstation is low on disk space
Message The machine @workstation has only @diskSpace MB of free disk space. Please check the machine, and free up some disk space.
Delivery Limit 1 Day

Note: @diskSpace is a custom 'tag' that we're defining in this message. At the time that we generate the message, we'll be able to provide a value that will be substituted for this tag in the message. @workstation is a built-in tag. See 'MessageMaster Variables' for a list of all built-in tags that can be used in message definitions and titles, referenced below.

2. Write a program to do the check you wish to perform

Here is a sample program that will check for disk space:

Private Sub Form_Load()
   Dim fso, d, fSpace
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set d = fso.GetDrive("c:")
   fSpace = d.FreeSpace/1024 ' get free space in MB
End Sub

3. Generate a MessageMaster module for your project

First, we'll get MessageMaster to give us some code that we can call from our script when we want to generate the message. In the MessageMaster console, under the Message Admin menu, click on the new "In-house Applications" Category, and under that click on the "System Checks" Application. Click on the "Generate VB Module..." action link. You will be prompted to save a .bas file called System_ChecksMessages.bas. Go ahead and save it in your project directory, and then add it to your project.

If you open the module and look at the functions, you'll see that a separate function was generated for each message under the Application called "System Checks". In our case, there's just one message, but you get the point. At the top of the module is some sample code that shows you how to call the functions.

4. Generate the message in your code

Here is the code that you'll need to generate the message. We will explain each line below.

Dim oMsg As MESSAGEMASTERCLIENTLib.MessageMasterMsg2
Set oMsg = Disk_Space_Check_1_0_DS_1()
oMsg.AddTag "diskSpace", CStr(fSpace)
oMsg.Send

The first line defines a variable, oMsg, to be a MessageMaster Message object. You need to go Project / References from the menu, and check off "MessageMaster Client 2.0 Type Library" to add it as a reference in your project before you can do this.

In the second line, we call the generated function for our particular message, DS-1. It's not named exactly as we spelled it, since spaces and dashes are changed to underlines, but it's still easy to tell which function corresponds to which message. The function creates a MessageMaster Message object for that particular message, and we assign it to oMsg.

In the third line, we add our custom tag and its value to the oMsg object by calling the AddTag method. In our DS-1 message, we defined a tag called @diskSpace, and its value will be the amount of free disk space, which is fSpace. If we had defined more tags, we could just make multiple calls to the AddTag method.

Finally, we use the Send method to send off our message to the IncomingMessages queue on the MessageMaster server.

4. Set up your program to be run on your clients

You can now launch your disk space check program any way that you normally deploy programs in your enterprise. One way is to set it up as a startup script in Active Directory, to run on all machines in your enterprise.

Note: only clients that have MessageMaster Client installed will successfully generate a message.

5. Receive your message

The best way to receive your new custom message is to subscribe to it. See 'Subscription - Agents and Carriers', referenced below, for how to use the MessageMaster subscription system.

Or you can search for your message in the MessageMaster database by using the Search page of the MessageMaster console.

See Also

Applies To

Did this help?

Yes
No, not what I was
      looking for...
No, it was missing info...
No, it was wrong...

Comment (Anonymous):