Nt Alerts Delivered To Your Mailbox
Posted on 19 Nov 1999
by Scott Dexter (sgd)
Rated 3.91 (Ratings: 1)
- More articles in Backend
So you got yer NT box, yer IIS server, and yer ASP pages humming quietly in the back room fer what seems like days now after the sudden explosion in traffic over the weekend that made you tune the box because a) you ran out of memory, b) the processor got stuck at 100% because of some problem the IT guys haven't patched, c) ASP processing was dog slow because you didn't have enough script engines cached and/or allocated, or d) all of the above or something else.
You've even learned some good Performance Monitor counters to pay attention to, like number of ASP requests queued, total processor utilization, current number of ASP sessions, and a couple others. But you hate having to manually go look at them every once in a while, cause you hafta get up from your seat and walk down the hall, er something.
My dear friend, take advantage of the Alerts page in Performance Monitor and some VBScript you've probably already written. On the Alerts page you specify a counter (like ASP requests queued) and a threshold (like 10) and a program to kick off when it happens (you got it, like a program you write using some VBScript). You can take some ASP code you probably have laying around --you know, that little routine that sends an email?-- and turn it into a WSH script that can be fired from a command line (don't worry, I've got code below). The program fired by the alert has to be specified by full pathname, so you know.
Here's the little diddy I have running, and yeah, I use a third party component from Mabry (http://www.mabry.com) to do the mailing. We like Mabry, they're nice. I have the script in the c:\ cause I'm lazy and I didn't want to type long directory paths in the Alerts box. You call it with two parameters, subject line and message text:
emailsupport.vbs "This is a Test" "Your server is dying and all you can think about is hockey?"
And now, the code. It took me all of 15 minutes to learn the differences and get parameters passed in.
*******BOF*********' Don't hang around if there's an errorOn Error Resume Next
' What's on the command line --its a Collection, not an arraySet oArgs = WScript.Argumentsif oArgs.Count<2 then alert="test" mesg = "test"else'first arg is where from, the second is the message alert=oArgs(0) mesg = oArgs(1)end if
' send the mail with the argument:mailAlert alert,mesg
' now go awayWScript.Quitsub mailAlert(byval wherefrom, byval mesg)On Error Resume NextMailDstIsHost = 64 ' does this look familiar?Set oMail = WScript.CreateObject("Mabry.MailCtrl") oMail.Blocking = True ' Set header properties oMail.To = "<email@example.com>" oMail.From = "<firstname.lastname@example.org>" oMail.EMailAddress = "<email@example.com>" oMail.Date = Now oMail.Subject = "Email Alert from " & wherefrom oMail.Body(0) = Now & " : " & mesg oMail.Host = "yourSMTPserverhere" oMail.Flags = MailDstIsHost ' Connect to server oMail.ConnectType = 0 ' basic SMTP oMail.Connect oMail.WriteMessage MailDstIsHost ' Disconnect oMail.Disconnect' instead of Set oMail=Nothing we do this:WScript.DisconnectObject oMail
Take it and run, I implore you