VBScript to monitor IP devices on the network


[updated May 18 2008: to include E-Mailing, WMI Ping and the possibility to use timouts per device, see end of article for download]
[updated Feb 23 2009: some more error handling and a switch from arrays to classes and dictionary objects.
[updated match 20th 20-09: fixed small bug allowing longer device downtimes]

There are many tools that monitor network appliances, servers and workstations on your network, but I wanted something simple, un-intrusive and adaptable. Since I could not really find what I was after (most tools need to be installed, are shareware or simply don't quite do what I want) I decided to write my own 'ping monitor' in VBScript.
Its usage is pretty simple; tell it what devices you want monitored and it will send a ping to them every number of seconds. It allows for a timeout per device to be configured, but will report a device going down (with the time) as well as it going up again in the console as well by sending an E-Mail.
Timeouts

The reason for the timeout is that I noticed some devices to be less responsive than others, but not necessarily 'down'. For example; one of the things I like to 'ping' is the first router (or 'hop') outside of my own network (I called it 'outside'), just to check if my internet link is still up. Sometimes this misses a ping or two, but we only consider it 'down' if it is not responsive for more than two minutes. The script allows for this timeout in seconds to be configured per device.
An example:

Above you can see a number of IP addresses being monitored. Some internal, some external, some LAN based and some Wireless. Its initial output is pretty straightforward.
E-MAIL Messages

As you can see I have taken the 'device' (in this case a Windows 2008 Core server) offline for 27 seconds, since this took longer than the 10 seconds I allowed as a 'Timeout' the script will, besides warning me in the console, also have sent me an E-Mail looking like this:

If the user hare earlier received an E-Mail warning (and –only then-) we will also send a message once the device is 'seen again':

That's it. And since this is a VBScript, you can log this to a file, send it trough mail, have it printed as a daily status… whatever you want. As mentioned besides logging it locally in the console, the script also sends out an E-Mail (see my article on CDO messaging to read about the interesting problems I had to solve there). It goes without saying that when your E-Mail server is down, mail cannot be relied upon, that why the console is the best place to check, but mail is just so convenient isn't it ;-)
Usage tips: the boy who cried wolf…

On a sidenote: be very careful choosing the timeout values; as these are the variables that are responsible for triggering the reason for sending an E-Mail. I have seen many projects at several companies introducing this type of monitoring using software such as Active Experts, Big Brother, NetIQ, etc. The most important reason for such projects going south is first of all the implementers wanting too much, and secondly the tools being configured to be chatty. What I mean is that you would be wise to start small; learn as you go by starting to monitor only your key infrastructure devices. Make sure to use large time-out (of course still within reason) to make sure you do not get 'false positives'. Only once you are satisfied by that start adding devices, and allow for timeout valus to be tweaked on a per device basis. The reason for all this is that it's easy to technically roll out a monitoring project, but it will fail if the system reports issues where there are no real isues.. You may recall the story about 'the boy who cried wolf': if your support staff doesn't take the error messages seriously, the monitoring can be considered a failed effort.
Configuration

The script consists of essentially two files; the first one being the script itself, and the second one a configuration file that holds the device names and IP numbers and allowed timeout values in seconds. Note that the device names can be anything you want them to be to describe the device, as these names are not being used for DNS or Netbios resolution but only as a reference.
The name for the config file is devices.cfg and its contents should look something like this:
# domain and app servers
10.10.1.1, voo-server, 30
10.10.1.3, voo-server2, 30
10.10.1.4, voo-server3, 30
10.10.1.5, voo-server4, 30

# backbone infra
10.10.1.253, router, 10
82.161.24.1, outside, 120
10.10.1.254, hilink, 20

# client accesspoints
10.10.1.251, wap-kees, 30
10.10.1.252, wap-livingroom, 30
10.10.1.250, switch, 10

# utility devices or servers
10.10.1.220, printserver, 30
10.10.1.10, phoneserver, 30
10.10.1.209, phone100, 10
10.10.1.210, phone101, 30

# win 2008 core test server
10.10.1.203, core1, 10
As you can see you're allowed to skip lines and add some comments, this makes it easier to organize things a bit.
Keep in mind that the script allows for timeouts, so it will not immediately start warning when only one ping is missing. Another thing you want to keep in mind is that this script is not multi-threaded. So there's a limit to the amount of devices you can monitor, simply because each device needs time to –be- monitored. It's sequential, not parallel. That means if you decide to put 100 devices in the configuration file, it will take a long time for each 'turn' of pinging all devices to finish before the next round starts. This of course would mean that a device can potentially be offline for quite a while before you notice it.
If you only use this for a few devices (less than 50) this should have no big impact however.
There's a lot of potential for a script like this, future versions could implement multithreading, use WMI to check services, have a decent warning system built-in (paging or SMS). For these things to happen I believe it would be better to port it to C# first. Maybe some day when I find the time… ;-)
The script is public domain, you can do with it what you want, as long as you keep my name and website in it as the initial author.
You can download mon-ping.vbs with a sample configuration file here




موضوعات مشابه: