This example shows how to use the Computer Monitor in the following scenario:
You are using the Computer Monitor to monitor your web application by periodically requesting a page from the server, and then evaluating the response from that request.
If the server fails, you want to send a notification message. You want this to be a "warning" message, sent with a severity of 7. You'll send it to a Notification Group, where certain people will be notified based on the severity.
If the server is still unresponsive 5 minutes later, you want to send a more urgent message. This message will be sent to the same group, but with a severity of 9, which will cause an administrator to be paged (based on the way you have set up the group).
After the second message has been sent, you don't want to send any more notification messages until the server is restored.
When the server is restored, you want to send out another notification message. You want this notification message to have the same severity as the most recent error message, so that it will get sent to the same people.
First you must set up the computer monitor trigger. Your web application has a page called "webtest.asp" that returns the text "Result: Application OK" if everything is working properly.
Therefore, the Computer Monitor will be set to request this page, and trigger if the response returned by the server does not match this text.
You want the trigger to test every 5 minutes, and you need to check these additional options:
Trigger at test interval.... You want the trigger to keep firing every 5 minutes while the server is dead. This is necessary so that you can send the "escalating" messages.
Trigger again when successful response received. You want the trigger to fire again when the connection is restored, so you can send the message indicating that the server has been restored.
This job will have a single step: a Notification Task to send your notification message.
You will use a script to determine the subject, text, and severity of the message.
Specify "%NotificationSubject%" as the subject. "%NotificationSubject%" will be replaced automatically by the value of the NotificationSubject script parameter, which will be set in the script (see below).
Specify "%NotificationMessage%" as the subject. "%NotificationMessage%" will be replaced automatically by the value of the NotificationMessage script parameter, which will be set in the script (see below).
The setting of the Severity does not matter; it will be overridden by the script.
The step will use a Script Condition. The script will serve two purposes:
It will determine whether the message should be sent. (Remember, the trigger will continue to fire every 5 minutes as long as the server cannot be reached, but we only want to send messages for the first two triggers, and again when the server is restored.)
If a message should be sent, the script will set the subject, text, and severity of the message.
'first, determine whether the job is being triggered because the server has failed 'or because it has been restored. The Action parameter tells us this if Parameters("Action")="ConnectionFailed" then 'the job has been triggered because the server or connection failed 'set the message text to be used. Build a notification message that includes the status code and the error message 'assign this message to the NotificationMessage parameter, which the Notification Task uses as its message text Parameters("NotificationMessage")="Connection Status: " & Parameters("ConnectionStatusCode") & vbcrlf & _ "Error Message: " & Parameters("ResponseText") 'now figure out how many times a failure has been detected since the last successful response. 'We only want to send messages for the first and second failure. 'The FailureCount parameter tells us this if Parameters("FailureCount")=1 then 'first failure 'set the subject to be used for the notification message Parameters("NotificationSubject")="Server XXX failed (first notice)" 'set the severity for the message Parameters("MessageSeverity")=7 'set the Result to True to indicate that the condition is satisfied, so step will be run Result=true elseif Parameters("FailureCount")=2 then 'second failure 'set the subject to be used for the notification message Parameters("NotificationSubject")="Server XXX failed (second notice)" 'set the severity for the message Parameters("MessageSeverity")=9 'override the severity set for the task 'set the result to True to indicate that the condition is satisfied, so step will be run Result=true else 'subsequent failure 'After we've already sent 2 messages, we don't want to send any more until the connection is restored. 'Set the Result to False, which indicates that the condition is not met. This will cause 'the step to be skipped (notification will not be sent). Result=False end if else 'the job is being triggered because the server or connection has been 'restored after a previously-reported failure 'set the message subject and text to be used: Parameters("NotificationSubject")="Server restored" Parameters("NotificationMessage")="Connection Status: " & Parameters("ConnectionStatusCode") & vbcrlf & _ "Response: " & Parameters("ResponseText") Result=true 'set the result to True to indicate that the condition is satisfied, so step will be run 'we want to send this message to the same people who received the most recent failure notification, 'so we need to set the severity to match the severity of the most recent message. 'the FailureCount will tell us how many failures were detected since the last success; based 'on that we know which severity to use. 'if the count is 1, we know we only sent a severity 7 message before. 'if the count is >1, we know we sent a severity 9 message before. if Parameters("FailureCount")=1 then Parameters("MessageSeverity")=7 else Parameters("MessageSeverity")=9 end if end if
The Recipients for your task should be users or groups that are configured to notify the correct people based on the message severity. For example, you may set up your web server administrator so that she is notified by e-mail for all notifications, and by pager for notifications with a severity of 9. Then, if you include her as a recipient for this task, she will receive an e-mail warning if the server is unreachable, and another alert by pager if the server is still unreachable 5 minutes later.