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 >
Text File  |  2003-09-05  |  23KB  |  369 lines

  1. ###################################################################################################
  2. #                                                                                                 #
  3. # RemotelyAnywhere System Monitoring Sample Scripts                                               #
  4. #                                                                                                 #
  5. # RemotelyAnywhere provides a mechanism for monitoring certain aspects of a computer system,      #
  6. # and alert the system administrator if anything 'out of ordinary' happens.                       #
  7. #                                                                                                 #
  8. # The system administator can create scripts, that define the behavior of the system monitoring   #
  9. # module. Some sample scripts are provided below to help you get started.                         #
  10. #                                                                                                 #
  11. # Before you use these sample scripts, you might want to tailor their behavior to better suit     #
  12. # your configuration and your needs. You will also have to enter the Configuration dialog in      #
  13. # RemotelyAnywhere, and set up an SMTP server under 'Preferences/Network' if you want to make use #
  14. # of alerting via email.                                                                          #
  15. #                                                                                                 #
  16. # THIS SOFTWARE IS PROVIDED BY 3AM LABS LTD ``AS IS'' AND                                         #
  17. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE                           #
  18. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE                      #
  19. # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE                         #
  20. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL                      #
  21. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS                         #
  22. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                           #
  23. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT                      #
  24. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY                       #
  25. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF                          #
  26. # SUCH DAMAGE.                                                                                    #
  27. #                                                                                                 #
  28. ###################################################################################################
  29.  
  30. ###################################################################################################
  31. #                                                                                                 #
  32. # Global Error Handler                                                                            #
  33. #                                                                                                 #
  34. # This error handler is invoked when one of the rules below encounters an error.                  #
  35. #                                                                                                 #
  36. ###################################################################################################
  37.  
  38. ERROR
  39. {
  40.     Log("\"[RULE]\" has failed at instruction \"[ERROR_SOURCE]\" with "
  41.         "the following error: [ERROR_MESSAGE]");
  42.  
  43.     SendMail("YourAccount@YourProvider", "RemotelyAnywhere failure",
  44.              "RemotelyAnywhere on [MACHINE] encountered the following error:\n"
  45.               "[RULE]\n[ERROR_SOURCE]\n[ERROR_MESSAGE]");
  46. }
  47.  
  48. ###################################################################################################
  49. #                                                                                                 #
  50. # Check free space on disk C                                                                      #
  51. #                                                                                                 #
  52. # Script that demonstrates the use of the following:                                              #
  53. #                                                                                                 #
  54. # DiskFreeSpaceUnder                                                                              #
  55. # Execute                                                                                         #
  56. # SendMail                                                                                        #
  57. #                                                                                                 #
  58. ###################################################################################################
  59.  
  60. "(Sample) Check free space on disk C" (1h) # check every hour
  61. {
  62.  
  63.     DiskFreeSpaceUnder("C:\\", 128M) 
  64.     # if C:\ has less than 128 megabytes free, execute the code below
  65.     {
  66.         #Execute("C:\\Program Files\\RemotelyAnywhere\\Cleanup.bat > C:\\Temp\\Cleanup.txt");
  67.         # Execute Cleanup.bat, and redirect its output into Cleanup.txt (Uncomment the above
  68.         # line to enable executing a batch file.)
  69.  
  70.         SendMail("YourAccount@YourProvider", "[MACHINE] C disk full",
  71.             "[MACHINE] has run out of disk space on drive C.\n"
  72.             "It has [FREE_MBYTES]/[TOTAL_MBYTES] MBytes ([FREE_PERCENT]) free space.\n"
  73.             "\n"
  74.             "Cleanup.bat returned:\n"
  75.             "[FILE C:\\Temp\\Cleanup.txt]\n");
  76.         # Send an email with the above contents, also include the output from Cleanup.bat
  77.     } else {
  78.         SendMail("YourAccount@YourProvider", "Disk space back to normal",
  79.             "[MACHINE] has now enough disk space on drive C.\n"
  80.             "It has [FREE_MBYTES]/[TOTAL_MBYTES] MBytes ([FREE_PERCENT]) free space.\n");
  81.     }
  82.  
  83. }
  84.  
  85. ###################################################################################################
  86. #                                                                                                 #
  87. # Check processor utilization                                                                     #
  88. #                                                                                                 #
  89. # Script that demonstrates the use of the following:                                              #
  90. #                                                                                                 #
  91. # ProcUsageAboveFor                                                                               #
  92. # Log                                                                                             #
  93. #                                                                                                 #
  94. ###################################################################################################
  95.  
  96. "(Sample) Check processor utilization" (20s) # check every 20 seconds
  97. {
  98.  
  99.     ProcUsageAboveFor(80%, 1m)
  100.     # if the processor usage has been above 80% for one minute, execute the code below
  101.     {
  102.         Log("Processor utilization is above 80% for a minute. "
  103.             "(Average: [AVG_USAGE], Max: [MAX_USAGE], Min: [MIN_USAGE])");
  104.         # make an entry in the RemotelyAnywhere.log file
  105.     }
  106. }
  107.  
  108. ###################################################################################################
  109. #                                                                                                 #
  110. # Check memory utilization                                                                        #
  111. #                                                                                                 #
  112. # Script that demonstrates the use of the following:                                              #
  113. #                                                                                                 #
  114. # MemUsageAboveFor                                                                                #
  115. # SendMessage                                                                                     #
  116. #                                                                                                 #
  117. ###################################################################################################
  118.  
  119. "(Sample) Check memory utilization" (30s) # check every 30 seconds
  120. {         
  121.  
  122.     MemUsageAboveFor(90%, 1m)
  123.     # if the memory usage has been above 90% for one minute, execute the code below
  124.     {
  125.         SendMessage("Administrator", "High memory utilization!\n(Max: [MAX_USAGE])");
  126.         # send an administrative message to the Administrator
  127.     }
  128. }
  129.  
  130. ###################################################################################################
  131.  
  132. ###################################################################################################
  133. #                                                                                                 #
  134. # Monitor traffic on modem                                                                        #
  135. #                                                                                                 #
  136. # Script that demonstrates the use of the following:                                              #
  137. #                                                                                                 #
  138. # NetInUsageAboveFor                                                                              #
  139. # NetOutUsageAboveFor                                                                             #
  140. # SendMail                                                                                        #
  141. #                                                                                                 #
  142. # Please note that this script can be modified to monitor any network adapter in the system.      #
  143. # Simply replace the adapter ID (4 in this case) with the ID of the network adapter you wish to   #
  144. # monitor. Network adaper IDs can be found by looking at the Network Adapters page under          #
  145. # Performance in RemotelyAnywhere.                                                                #
  146. #                                                                                                 #
  147. ###################################################################################################
  148.  
  149. "(Sample) Monitor traffic on modem" (1m) # check every minute
  150. {
  151.  
  152.     NetInUsageAboveFor(4, 90%, 10m) or NetOutUsageAboveFor(4, 90%, 10m)
  153.     # if the incoming or outgoing traffic is above 90% for ten minutes on adapter 4,
  154.     # execute the code below
  155.     {
  156.         SendMail("YourAccount@YourProvider", "High traffic on adapter 4", 
  157.                  "[DATE] [TIME]: see subject");
  158.         # send email
  159.     }
  160. }
  161.  
  162. ###################################################################################################
  163. #                                                                                                 #
  164. # Check web server                                                                                #
  165. #                                                                                                 #
  166. # Script that demonstrates the use of the following:                                              #
  167. #                                                                                                 #
  168. # CheckAnswer                                                                                     #
  169. # SendMessage                                                                                     #
  170. #                                                                                                 #
  171. ###################################################################################################
  172.  
  173. "(Sample) Check web server" (10m) # check every ten minutes
  174. {
  175.     CheckAnswer("localhost:80", "HEAD / HTTP/1.0\n\n", "HTTP/1.1 200 OK", 2m)
  176.     # connect to port 80 on localhost, send the first string, and wait for up to two 
  177.     # minutes for the second string
  178.     {
  179.         SendMessage("Administrator", "HTTP server down! Response: \"[ANSWER]\"");
  180.         # send an administrative message to the Administrator
  181.     } else {
  182.         SendMessage("Administrator", "HTTP server is back online.");
  183.         # send an administrative message to the Administrator
  184.     }
  185. }
  186.  
  187. ###################################################################################################
  188. #                                                                                                 #
  189. # Check for email                                                                                 #
  190. #                                                                                                 #
  191. # Script that demonstrates the use of the following:                                              #
  192. #                                                                                                 #
  193. # Small                                                                                           #
  194. # SendMessage                                                                                     #
  195. #                                                                                                 #
  196. ###################################################################################################
  197.  
  198. "(Sample) CheckEmail" (10s)
  199. {
  200.  
  201.   #Call the Small script 'Email.sma'. You should edit this file and update
  202.   #it with your POP server and email account.
  203.  
  204.   Small("Email")
  205.   {
  206.      SendMessage("Administrator", "You have [SMALL_RES] new email messages.");
  207.   }
  208.   else
  209.   {
  210.      #NULL action - you should provide an empty ELSE branch here
  211.   }
  212. }
  213.  
  214.  
  215. ###################################################################################################
  216. #                                                                                                 #
  217. # Watch a process                                                                                 #
  218. #                                                                                                 #
  219. # Script that demonstrates the use of the following:                                              #
  220. #                                                                                                 #
  221. # Small                                                                                           #
  222. # SendMessage                                                                                     #
  223. # Log                                                                                             #
  224. # Execute                                                                                         #
  225. #                                                                                                 #
  226. ###################################################################################################
  227.  
  228. "(Sample) Check Process" (10s)
  229. {
  230.  
  231.   #Call the Small script 'WatchProcess.sma'. You should edit this file and update
  232.   #it with the process you are watching for, it is currently checking for Notepad.
  233.   #A similar script can be easily developed for services.
  234.  
  235.   Small("WatchProcess")
  236.   {
  237.     Log("Notepad.exe is not running. Attempting to start it.");
  238.     SendMessage("Administrator", "Notepad.exe is not running. Attempting to start it.");
  239.     Execute("start notepad.exe");
  240.   }
  241.   else
  242.   {
  243.     Log("Notepad.exe is back online.");
  244.     SendMessage("Administrator", "Notepad.exe is back online.");
  245.   }
  246. }
  247.  
  248. ###################################################################################################
  249. #                                                                                                 #
  250. # Monitor the contents of a directory                                                             #
  251. #                                                                                                 #
  252. # Script that demonstrates the use of the following:                                              #
  253. #                                                                                                 #
  254. # DirChanged, DirChangedSubtree                                                                   #
  255. # WriteFile                                                                                       #
  256. #                                                                                                 #
  257. ###################################################################################################
  258.  
  259. "(Sample) Monitor System Directory" (10m)
  260. {
  261.     DirChangedSubtree("%SystemRoot%")
  262.     # If the contents of C:\WINDOWS or any subdirectories change, the following block is executed
  263.     # Note: if you use DirChanged instead of DirChangedSubtree only C:\WINDOWS will be monitored
  264.     # Note: be careful monitoring large directories frequently, it may be memory and CPU consuming
  265.     {
  266.         # Append change information to C:\WINDOWS.txt
  267.         # the [DIRCHANGED_*] variables contain information about one file per line with the
  268.         # following format:
  269.         # <modification date>\t<file size in bytes>\t<file name>\r\n
  270.         WriteFile("%SystemDrive%\\WINDOWS.txt",
  271.             "---------------------------------------\r\n"
  272.             "Contents of C:\\WINDOWS changed\r\n"
  273.             "---------------------------------------\r\n"
  274.             "\r\n"
  275.             "New files / folders:\r\n"
  276.             "[DIRCHANGED_NEW]\r\n"
  277.             "Modified files / folders:\r\n"
  278.             "[DIRCHANGED_MODIFIED]\r\n"
  279.             "Deleted files / folders:\r\n"
  280.             "[DIRCHANGED_DELETED]\r\n"
  281.             "\r\n");
  282.     }
  283.     # Note: It's meaningless to define an else branch to rules containing a DirChangedSubtree
  284.     # condition, it will never be executed
  285. }
  286.  
  287.  
  288. ###################################################################################################
  289. #                                                                                                 #
  290. # Monitor folder size                                                                             #
  291. #                                                                                                 #
  292. # Script that demonstrates the use of the following:                                              #
  293. #                                                                                                 #
  294. # DirSizeAbove, DirSizeAboveSubtree                                                               #
  295. # SendMessage                                                                                     #
  296. #                                                                                                 #
  297. ###################################################################################################
  298.  
  299. "(Sample) Temporary folder size" (30s)
  300. {
  301.     DirSizeAboveSubtree("%Temp%", 100M)
  302.     # If the size of the temporary directory (including subdirectories) is above 100 Megabytes,
  303.     # the following block is executed
  304.     # Note: be careful monitoring large directories frequently, it may be memory and CPU consuming
  305.     {
  306.         SendMessage("Administrator", "Temporary folder is too large!\r\n([DIR_SIZE] bytes)");
  307.     }
  308.     else
  309.     {
  310.         SendMessage("Administrator", "Temporary folder size has been normalized.\r\n([DIR_SIZE] bytes)");
  311.     }
  312. }
  313.  
  314.  
  315. ###################################################################################################
  316. #                                                                                                 #
  317. # Monitor user activity                                                                           #
  318. #                                                                                                 #
  319. # Script that demonstrates the use of the following:                                              #
  320. #                                                                                                 #
  321. # UserActivityChanged                                                                             #
  322. # WriteODBC                                                                                       #
  323. #                                                                                                 #
  324. ###################################################################################################
  325.  
  326. "(Sample) Monitor Interactive User" (1s)
  327. {
  328.     UserActivityChanged()
  329.     # If there is an interactive user and he/she begins a new task,
  330.     # the following action block is executed with information about the previous task
  331.     # Note: the user interface application (RAGUI.exe) must be running to monitor user activity
  332.     {
  333.         # send task information to ODBC data source (see Preferences / ODBC messages)
  334.         WriteODBC("[INTERACTIVE_USER]", "\"[ACTIVE_PROCESS]\" "
  335.                   "(PID: [ACTIVE_PID], time: [ACTIVE_FOR]) [ACTIVE_CAPTION]");
  336.     }
  337.     # Note: It is meaningless to define an else branch to rules containing a UserActivityChanged
  338.     # condition, it will never be executed
  339. }
  340.  
  341.  
  342. ###################################################################################################
  343. #                                                                                                 #
  344. # Monitor ping round-trip times to a computer                                                     #
  345. #                                                                                                 #
  346. # Script that demonstrates the use of the following:                                              #
  347. #                                                                                                 #
  348. # Small                                                                                           #
  349. # WriteFile                                                                                       #
  350. #                                                                                                 #
  351. ###################################################################################################
  352.  
  353. "(Sample) Ping" (1m) # check every minute
  354. {
  355.  
  356.     # Call the Small script 'Ping.sma'. You should edit this file and update
  357.     # it with the name of the computer to ping and timeout settings
  358.     # it returns 0 if everything's ok, or the maximum round-trip time on consecutive timeouts
  359.  
  360.     Small("Ping")
  361.     {
  362.         WriteFile("C:\\Ping.txt", "[DATE] [TIME]: Ping timed out ([SMALL_RES] ms).");
  363.     }
  364.     else
  365.     {
  366.         WriteFile("C:\\Ping.txt", "[DATE] [TIME]: Successful ping.");
  367.     }
  368. }
  369.