home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2004 April
/
PCWorld_2004-04_cd.bin
/
software
/
temacd
/
remotany
/
RemotelyAnywhere.msi
/
MonitoringScript.txt
< prev
next >
Wrap
Text File
|
2003-09-05
|
23KB
|
369 lines
###################################################################################################
# #
# RemotelyAnywhere System Monitoring Sample Scripts #
# #
# RemotelyAnywhere provides a mechanism for monitoring certain aspects of a computer system, #
# and alert the system administrator if anything 'out of ordinary' happens. #
# #
# The system administator can create scripts, that define the behavior of the system monitoring #
# module. Some sample scripts are provided below to help you get started. #
# #
# Before you use these sample scripts, you might want to tailor their behavior to better suit #
# your configuration and your needs. You will also have to enter the Configuration dialog in #
# RemotelyAnywhere, and set up an SMTP server under 'Preferences/Network' if you want to make use #
# of alerting via email. #
# #
# THIS SOFTWARE IS PROVIDED BY 3AM LABS LTD ``AS IS'' AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE #
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE #
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS #
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) #
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT #
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY #
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF #
# SUCH DAMAGE. #
# #
###################################################################################################
###################################################################################################
# #
# Global Error Handler #
# #
# This error handler is invoked when one of the rules below encounters an error. #
# #
###################################################################################################
ERROR
{
Log("\"[RULE]\" has failed at instruction \"[ERROR_SOURCE]\" with "
"the following error: [ERROR_MESSAGE]");
SendMail("YourAccount@YourProvider", "RemotelyAnywhere failure",
"RemotelyAnywhere on [MACHINE] encountered the following error:\n"
"[RULE]\n[ERROR_SOURCE]\n[ERROR_MESSAGE]");
}
###################################################################################################
# #
# Check free space on disk C #
# #
# Script that demonstrates the use of the following: #
# #
# DiskFreeSpaceUnder #
# Execute #
# SendMail #
# #
###################################################################################################
"(Sample) Check free space on disk C" (1h) # check every hour
{
DiskFreeSpaceUnder("C:\\", 128M)
# if C:\ has less than 128 megabytes free, execute the code below
{
#Execute("C:\\Program Files\\RemotelyAnywhere\\Cleanup.bat > C:\\Temp\\Cleanup.txt");
# Execute Cleanup.bat, and redirect its output into Cleanup.txt (Uncomment the above
# line to enable executing a batch file.)
SendMail("YourAccount@YourProvider", "[MACHINE] C disk full",
"[MACHINE] has run out of disk space on drive C.\n"
"It has [FREE_MBYTES]/[TOTAL_MBYTES] MBytes ([FREE_PERCENT]) free space.\n"
"\n"
"Cleanup.bat returned:\n"
"[FILE C:\\Temp\\Cleanup.txt]\n");
# Send an email with the above contents, also include the output from Cleanup.bat
} else {
SendMail("YourAccount@YourProvider", "Disk space back to normal",
"[MACHINE] has now enough disk space on drive C.\n"
"It has [FREE_MBYTES]/[TOTAL_MBYTES] MBytes ([FREE_PERCENT]) free space.\n");
}
}
###################################################################################################
# #
# Check processor utilization #
# #
# Script that demonstrates the use of the following: #
# #
# ProcUsageAboveFor #
# Log #
# #
###################################################################################################
"(Sample) Check processor utilization" (20s) # check every 20 seconds
{
ProcUsageAboveFor(80%, 1m)
# if the processor usage has been above 80% for one minute, execute the code below
{
Log("Processor utilization is above 80% for a minute. "
"(Average: [AVG_USAGE], Max: [MAX_USAGE], Min: [MIN_USAGE])");
# make an entry in the RemotelyAnywhere.log file
}
}
###################################################################################################
# #
# Check memory utilization #
# #
# Script that demonstrates the use of the following: #
# #
# MemUsageAboveFor #
# SendMessage #
# #
###################################################################################################
"(Sample) Check memory utilization" (30s) # check every 30 seconds
{
MemUsageAboveFor(90%, 1m)
# if the memory usage has been above 90% for one minute, execute the code below
{
SendMessage("Administrator", "High memory utilization!\n(Max: [MAX_USAGE])");
# send an administrative message to the Administrator
}
}
###################################################################################################
###################################################################################################
# #
# Monitor traffic on modem #
# #
# Script that demonstrates the use of the following: #
# #
# NetInUsageAboveFor #
# NetOutUsageAboveFor #
# SendMail #
# #
# Please note that this script can be modified to monitor any network adapter in the system. #
# Simply replace the adapter ID (4 in this case) with the ID of the network adapter you wish to #
# monitor. Network adaper IDs can be found by looking at the Network Adapters page under #
# Performance in RemotelyAnywhere. #
# #
###################################################################################################
"(Sample) Monitor traffic on modem" (1m) # check every minute
{
NetInUsageAboveFor(4, 90%, 10m) or NetOutUsageAboveFor(4, 90%, 10m)
# if the incoming or outgoing traffic is above 90% for ten minutes on adapter 4,
# execute the code below
{
SendMail("YourAccount@YourProvider", "High traffic on adapter 4",
"[DATE] [TIME]: see subject");
# send email
}
}
###################################################################################################
# #
# Check web server #
# #
# Script that demonstrates the use of the following: #
# #
# CheckAnswer #
# SendMessage #
# #
###################################################################################################
"(Sample) Check web server" (10m) # check every ten minutes
{
CheckAnswer("localhost:80", "HEAD / HTTP/1.0\n\n", "HTTP/1.1 200 OK", 2m)
# connect to port 80 on localhost, send the first string, and wait for up to two
# minutes for the second string
{
SendMessage("Administrator", "HTTP server down! Response: \"[ANSWER]\"");
# send an administrative message to the Administrator
} else {
SendMessage("Administrator", "HTTP server is back online.");
# send an administrative message to the Administrator
}
}
###################################################################################################
# #
# Check for email #
# #
# Script that demonstrates the use of the following: #
# #
# Small #
# SendMessage #
# #
###################################################################################################
"(Sample) CheckEmail" (10s)
{
#Call the Small script 'Email.sma'. You should edit this file and update
#it with your POP server and email account.
Small("Email")
{
SendMessage("Administrator", "You have [SMALL_RES] new email messages.");
}
else
{
#NULL action - you should provide an empty ELSE branch here
}
}
###################################################################################################
# #
# Watch a process #
# #
# Script that demonstrates the use of the following: #
# #
# Small #
# SendMessage #
# Log #
# Execute #
# #
###################################################################################################
"(Sample) Check Process" (10s)
{
#Call the Small script 'WatchProcess.sma'. You should edit this file and update
#it with the process you are watching for, it is currently checking for Notepad.
#A similar script can be easily developed for services.
Small("WatchProcess")
{
Log("Notepad.exe is not running. Attempting to start it.");
SendMessage("Administrator", "Notepad.exe is not running. Attempting to start it.");
Execute("start notepad.exe");
}
else
{
Log("Notepad.exe is back online.");
SendMessage("Administrator", "Notepad.exe is back online.");
}
}
###################################################################################################
# #
# Monitor the contents of a directory #
# #
# Script that demonstrates the use of the following: #
# #
# DirChanged, DirChangedSubtree #
# WriteFile #
# #
###################################################################################################
"(Sample) Monitor System Directory" (10m)
{
DirChangedSubtree("%SystemRoot%")
# If the contents of C:\WINDOWS or any subdirectories change, the following block is executed
# Note: if you use DirChanged instead of DirChangedSubtree only C:\WINDOWS will be monitored
# Note: be careful monitoring large directories frequently, it may be memory and CPU consuming
{
# Append change information to C:\WINDOWS.txt
# the [DIRCHANGED_*] variables contain information about one file per line with the
# following format:
# <modification date>\t<file size in bytes>\t<file name>\r\n
WriteFile("%SystemDrive%\\WINDOWS.txt",
"---------------------------------------\r\n"
"Contents of C:\\WINDOWS changed\r\n"
"---------------------------------------\r\n"
"\r\n"
"New files / folders:\r\n"
"[DIRCHANGED_NEW]\r\n"
"Modified files / folders:\r\n"
"[DIRCHANGED_MODIFIED]\r\n"
"Deleted files / folders:\r\n"
"[DIRCHANGED_DELETED]\r\n"
"\r\n");
}
# Note: It's meaningless to define an else branch to rules containing a DirChangedSubtree
# condition, it will never be executed
}
###################################################################################################
# #
# Monitor folder size #
# #
# Script that demonstrates the use of the following: #
# #
# DirSizeAbove, DirSizeAboveSubtree #
# SendMessage #
# #
###################################################################################################
"(Sample) Temporary folder size" (30s)
{
DirSizeAboveSubtree("%Temp%", 100M)
# If the size of the temporary directory (including subdirectories) is above 100 Megabytes,
# the following block is executed
# Note: be careful monitoring large directories frequently, it may be memory and CPU consuming
{
SendMessage("Administrator", "Temporary folder is too large!\r\n([DIR_SIZE] bytes)");
}
else
{
SendMessage("Administrator", "Temporary folder size has been normalized.\r\n([DIR_SIZE] bytes)");
}
}
###################################################################################################
# #
# Monitor user activity #
# #
# Script that demonstrates the use of the following: #
# #
# UserActivityChanged #
# WriteODBC #
# #
###################################################################################################
"(Sample) Monitor Interactive User" (1s)
{
UserActivityChanged()
# If there is an interactive user and he/she begins a new task,
# the following action block is executed with information about the previous task
# Note: the user interface application (RAGUI.exe) must be running to monitor user activity
{
# send task information to ODBC data source (see Preferences / ODBC messages)
WriteODBC("[INTERACTIVE_USER]", "\"[ACTIVE_PROCESS]\" "
"(PID: [ACTIVE_PID], time: [ACTIVE_FOR]) [ACTIVE_CAPTION]");
}
# Note: It is meaningless to define an else branch to rules containing a UserActivityChanged
# condition, it will never be executed
}
###################################################################################################
# #
# Monitor ping round-trip times to a computer #
# #
# Script that demonstrates the use of the following: #
# #
# Small #
# WriteFile #
# #
###################################################################################################
"(Sample) Ping" (1m) # check every minute
{
# Call the Small script 'Ping.sma'. You should edit this file and update
# it with the name of the computer to ping and timeout settings
# it returns 0 if everything's ok, or the maximum round-trip time on consecutive timeouts
Small("Ping")
{
WriteFile("C:\\Ping.txt", "[DATE] [TIME]: Ping timed out ([SMALL_RES] ms).");
}
else
{
WriteFile("C:\\Ping.txt", "[DATE] [TIME]: Successful ping.");
}
}