Subscribe to Windows IT Pro
February 08, 2005 12:00 AM

How to Script In-Your-Face Alerts

A TSA notification system
Windows IT Pro
InstantDoc ID #45195
Rating: (2)
Downloads
45195.zip

Ensuring that machines are online is one of the most important tasks that network administrators perform every day. The moment a machine goes offline, administrators need to be alerted so that they can get the machine back online. With time being such a crucial factor in high network availability, administrators need a monitoring tool that can quickly notify them when a machine is offline.

Perl is the perfect scripting language for writing such a tool. However, although writing a Perl script to monitor machines is simple, scripting a notification system isn't so simple.

To be fair, you can easily write a monitoring script that produces a log file, registers Win32 event log entries, or even sends an email message or a page. But if you're working on a computer when something goes wrong, you need an alert that jumps out and is in your face. You could decide to write code that pops open a dialog box with a message. But if you use that approach and many alerts occur while you're away from your computer, you have to wade through numerous dialog boxes and click OK in each one. A better way to provide alerts is to use the taskbar status area (TSA).

The TSA is the region of the Windows taskbar (typically at the lower right of your Windows display), where icons appear alongside the system clock. This area provides the user with information about what an application is doing. For example, when Windows Update has downloaded a new system patch, an icon appears that informs the user a patch is ready to be installed.

Applications have been using the TSA more and more, but Perl scripts haven't been able to take advantage of it because there's no native support for registering an icon with the TSA (although ActiveState offers a tool that can compile a Perl script into a TSA application called PerlTray). However, you can add such support. Let's explore how the TSA works and how to add TSA support to a machine-monitoring script.

How the TSA Works
When an application registers an icon with the TSA, the application's icon is displayed alongside the other icons. An application can add as many icons as it needs, but most applications display only one icon. After an icon is registered, it remains visible until the application deletes the icon or is terminated. If the application fails to delete the icon before termination, the icon will remain visible until the user moves the mouse pointer over it.

As situations change, an application can update its TSA icon to reflect changing conditions. For example, when an application is running smoothly, its icon might be a green light, but when the application encounters a problem, the icon might change to a red light. After the problem is corrected, the application icon can change back to the green light. This iconic visual representation of an application's status is a quick and easy way for the user to learn about problems that need attention.

In addition to an icon, an application can add a tool tip. The tool tip contains text that's associated with the application's icon. The text is usually a message that provides status details about the application's state. To continue with the previous example, when the icon turns to a red light, the tool tip might read Low disk space or Unable to process request. Users see this tool tip when they pause the mouse pointer over the icon. The tool tip appears above the icon. For example, Figure 1 shows the tool tip for the smiley face icon.

The application can change the tool-tip text at any time. Thus, the tool tip can provide a concise description of what's currently happening, without users having to open a log file and read an entire log or open a window and scroll through outputted log data. Icon changes and tool-tip updates are great feedback tools an application can employ to inform users of changes in status.

However, when an important event takes place, an application might need to do more than just update text and change an icon. The application might need to capture users' attention so that they know to look at the icon or tool tip. If users are deeply engrossed in writing a business proposal, updating a budget spreadsheet, or trying to win a hand of solitaire, they might be blissfully ignorant of a changed icon or updated tool tip.

The TSA has the ability to pop up an alert window that's guaranteed to get users' attention. This balloon-like window is large enough to hold a title and detailed description of a problem. In addition, the alert can include an icon that denotes the seriousness of the problem. For example, Figure 2 shows an alert that uses an error icon (in Windows XP, this icon is a red circle with a white X) to indicate a high severity level. Other possible icons include an exclamation point and a question mark.

Adding TSA Support to a Script
Now that you know how TSA works, let's explore how to add TSA support to a machine-monitoring script. This script, HostMonitor.pl, serves two purposes. First, it provides a working script that you can use to monitor remote machines on a network. It notifies you when one or more of the machines are unreachable. This script is useful for anyone who needs to monitor machines. Second, HostMonitor demonstrates how a Perl script can interact with the TSA. This knowledge is useful if you have scripts that would benefit from such TSA interaction.

You can download HostMonitor from the Windows Scripting Solutions Web site. Go to http://www.windowsitpro.com/windowsscripting, enter 45195 in the InstantDoc ID text box, then click the 45195.zip hotlink. The 45195.zip file includes HostMonitor_Files.zip, which contains the script and two icon files.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Mar 14, 2005

    I could not manage to run perl script...

  • Anonymous User
    7 years ago
    Mar 10, 2005

    This article is really useful... Unfortunately I'm getting an Error 404 when I click on the link to download the source ZIP file :(

  • Anonymous User
    7 years ago
    Feb 18, 2005

    Has anyone been unable to get it to run with the following error?

    C:\\NotifyTSA>perl hostmonitor.pl 192.168.30.119
    Loading icon named 'Error'
    Loading icon named 'Normal'
    icmp socket error - at hostmonitor.pl line 104

    "ppm install win32-pingicmp" installed fine and when i run it now it says its already installed.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.