home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ramsey.zip / SYMON.CMD
OS/2 REXX Batch file  |  1995-03-26  |  10KB  |  262 lines

  1. /**********************************************************/
  2. /*                                                        */
  3. /* Program name:  Symon.cmd                               */
  4. /* Title:  E-Mail Enabling Rexx                           */
  5. /* OS/2 Developer Magazine, Rexx Report                   */
  6. /* Author:  Mark Ramsey                                   */
  7. /* Phone:   (614) 791-9055 Ext 11                         */
  8. /* Fax:     (614) 791-9055                                */
  9. /*                                                        */
  10. /* Description:  This app monitors the available disk     */
  11. /*               space on the system.  If the avaiable    */
  12. /*               reach 5% or less, a warning message is   */
  13. /*               sent to the specified e-mail id.         */
  14. /*                                                        */
  15. /* Program Requirements:  Must have a VIM e-mail system   */
  16. /*               and associated dlls, RexxVIM, and the    */
  17. /*               OS/2 Rexx sub-system                     */
  18. /*                                                        */
  19. /* Date:  March 23, 1995                                  */
  20. /**********************************************************/
  21.  
  22. /* Variables */
  23. user_name   = 'Joe User'       /* this must be a valid e-mail id for signon */
  24. user_pw     = 'snoopy'         /* this must be the valid passord            */
  25. db_path     = 'm:\ccdata'      /* this is the location of the mail files    */
  26. admin_name  = 'System_Monitor' /* this is where to send the warning message */
  27. sleep_time  = 3600             /* how long to wait between checks           */
  28. low_percent = 5                /* percentage to cause warning message       */
  29. temp_file   = 'DIRLIST.TXT'    /* file name to store directory listing      */
  30.  
  31. '@echo off'
  32. '@cls'
  33. Say 
  34. Say 
  35. Say 'System Monitor, Version 1.00  (03/23/95)'
  36. Say
  37.  
  38. /* Load the RexxVIM extensions to Rexx */
  39. rc = RxFuncAdd('RxVIMLoadFuncs', 'REXXVIM', 'RxVIMLoadFuncs')
  40. if rc <> 0 then do
  41.    Say
  42.    Say '  RexxVIM failed to load, return code' rc
  43.    Say
  44.    signal done
  45. end  /* Do */
  46. call RxVIMLoadFuncs
  47. Say '  RexxVIM functions are now loaded'
  48.  
  49. /* Load the RexxUtil extensions to Rexx */
  50. rc = RxFuncAdd('SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs')
  51. if rc <> 0 then do
  52.    Say
  53.    Say '  RexxUtil failed to load, return code' rc
  54.    Say
  55.    signal done
  56. end  /* Do */
  57. call SysLoadFuncs
  58. Say '  RexxUtil functions are now loaded'
  59.  
  60. Say
  61. Say '  Monitoring system........ '
  62.  
  63. do forever
  64.  
  65.    parse value SysDriveInfo('C:') with drive free total label
  66.  
  67.    free_percent = FORMAT(free/total * 100,2,0)
  68.  
  69.    if  free_percent <= low_percent then do
  70.  
  71.       /* Text to send with message */
  72.       TextMsg = "Drive Size:" total " Free:" free " Label:" label
  73.  
  74.       /* Create file listing for root directory */
  75.       'dir c:\ >' temp_file
  76.  
  77.       /* Call the procedure to send message to administrator */
  78.       call SEND_MESSAGE
  79.  
  80.       /* Remove the temp directory file */
  81.       'erase' temp_file
  82.  
  83.  
  84.    end  /* Do */
  85.    SysSleep(sleep_time)       /* Wait for specified time */
  86.  
  87. end /* do */
  88. return
  89. /* end of main program */
  90.  
  91.  
  92. /***** SEND_MESSAGE *******/
  93.  
  94. /* This procedure performs the VIM functions to send a message */
  95. /* to the admin id.  Each time a message is sent, the program  */
  96. /* establishes a new connection to the VIM subsystem           */
  97.  
  98. SEND_MESSAGE:
  99.  
  100. /* Initialize the VIM subsystem */
  101. Session = ''
  102. rc = RxVIMInitialize()
  103. if (rc > 0) then signal VIMError
  104.  
  105.  
  106. /* Open a session with the postoffice using the parameters */
  107. /* specified.                                              */
  108. /*                                                         */
  109. /*  db_path   - path to the message container database     */
  110. /*  user_name - name of the e-mail id to open session      */
  111. /*  user_pw   - password for the user_name account         */
  112. /*  Session   - will contain the session pointer after the */
  113. /*              completion of the function call            */
  114.  
  115. rc = RxVIMOpenSession(db_path,user_name,user_pw,'Session')
  116. if (rc > 0) then signal VIMError
  117.  
  118.  
  119. /* Create a new message of type VIM_MAIL                   */
  120. /*                                                         */
  121. /*  Session - session pointer from the open function call  */
  122. /*  msg type- VIM_MAIL only supported type                 */
  123. /*  Message - will contain the message pointer after the   */
  124. /*            completion of the function call              */
  125.  
  126. rc = RxVIMCreateMessage(Session,'VIM_MAIL','Message')
  127. if (rc > 0) then signal VIMError
  128.  
  129.  
  130. /* Set the subject of the message                          */
  131. /*                                                         */
  132. /*  Message -   msg pointer from the create function call  */
  133. /*  Attribute - Keyword for attribute to set               */
  134. /*  Value     - Value to use                               */
  135.  
  136. hdrtext = "Disk Space at" free_percent "percent"
  137. rc = RxVIMSetMessageHeader(Message,'VIMSEL_SUBJECT', hdrtext)
  138. if (rc > 0) then signal VIMError
  139.  
  140.  
  141. /* Set the priority to high                                */
  142. /*                                                         */
  143. /*  Message -   msg pointer from the create function call  */
  144. /*  Attribute - Keyword for attribute to set               */
  145. /*  Value     - Value to use                               */
  146.  
  147. rc = RxVIMSetMessageHeader(Message,'VIMSEL_PRIORITY', 'VIM_HIGH_PRIORITY')
  148. if (rc > 0) then signal VIMError
  149.  
  150.  
  151. /* Set the recipient to the administrative user            */
  152. /*                                                         */
  153. /*  Message - msg pointer from the create function call    */
  154. /*  class   - keyword for class of recipient (TO,CC,BCC)   */
  155. /*  type    - type of recipient (One or group name         */
  156. /*  entity  - name type                                    */
  157. /*  adrbook - addressbook for name                         */
  158. /*  name    - userid to send (in local addressbook)        */
  159. /*  adrtype - type of addressbook entry (one or group)     */
  160. /*  adrname - full address entry (Fred Smith at ABC_PO)    */
  161.  
  162. rc = RxVIMSetMessageRecipient(Message,'VIMSEL_TO','VIMSEL_ENTITY','','',,
  163.                 admin_name,'','')
  164. if (rc > 0) then signal VIMError
  165.  
  166.  
  167. /* Add the text to the message                             */
  168. /*                                                         */
  169. /*  Message - msg pointer from the create message function */
  170. /*  Class   - class of the item (here it is part of note)  */
  171. /*  Type    - item type (here we are adding text)          */
  172. /*  Flags   - this is native text                          */
  173. /*  Name    - name or title of item                        */
  174. /*  Item    - text of the item                             */
  175. /*  Filename- not used for this call                       */
  176.  
  177. rc = RxVIMSetMessageItem(Message,'VIMSEL_NOTE_PART','VIM_TEXT','VIMSEL_NATIVE',,
  178.          'Text',TextMsg,'')
  179. if (rc > 0) then signal VIMError
  180.  
  181.  
  182. /* Add the file attachment to the message                  */
  183. /*                                                         */
  184. /*  Message - msg pointer from the create message function */
  185. /*  Class   - class of the item (here it is a file attach) */
  186. /*  Type    - item type (here we are adding text)          */
  187. /*  Flags   - this is native text                          */
  188. /*  Name    - name or title of item                        */
  189. /*  Item    - not used for this call                       */
  190. /*  Filename- filename to use for the attachment           */
  191.  
  192. rc = RxVIMSetMessageItem(Message,'VIMSEL_ATTACH','VIM_TEXT','VIMSEL_NATIVE',,
  193.          'Directory','',temp_file)
  194. if (rc > 0) then signal VIMError
  195.  
  196.  
  197. /* Send the message                                        */
  198. /*                                                         */
  199. /*  Message - msg pointer from the create message call     */
  200.  
  201. rc = RxVIMSendMessage(Message)
  202. Say '  Warning message sent'
  203. if (rc > 0) then signal VIMError
  204.  
  205.  
  206. /* Close the session with the postoffice                   */
  207. /*                                                         */
  208. /*  Session - session pointer from the open session call   */
  209.  
  210. rc = RxVIMCloseSession(Session)
  211. if (rc > 0) then signal VIMError
  212.  
  213.  
  214. /* Terminate the active VIM subsystem connection           */
  215.  
  216. rc = RxVIMTerminate()
  217. if (rc > 0) then signal VIMError
  218.  
  219. return
  220.  
  221.  
  222. /***** VIMError *******/
  223.  
  224. /* If an error occurs, this function will return the text */
  225. /* associated with the error.  Extended text may be       */
  226. /* displayed if it exists for the specified error.        */
  227.  
  228. VIMError:
  229.  
  230. /* Obtain the status text on the non-zero return code      */
  231. /*                                                         */
  232. /*  Session - session pointer from the open session call   */
  233. /*  rc      - return code to obtain extended information   */
  234. /*  Status  - stem variable to return text                 */
  235.  
  236. rc = RxVIMStatusText(Session,rc,'Status')
  237. Say
  238. Say '|-Error Information -----------------|'
  239.  
  240. if Status.1 = 'STATUS.1' then
  241.   Say 'Cannot obtain error status information'
  242. else do
  243.   Say '  Error Text -' Status.1
  244.   Say
  245.   Say '  Ext Status -' Status.2
  246. end
  247.  
  248. /* Terminate the VIM Connection */
  249. rc = RxVIMTerminate()
  250. signal done
  251.  
  252.  
  253. /* The done section will unload the RexxVIM extensions */
  254. /* and RexxUtil extenstions                            */
  255. DONE:
  256. /*** Drop all of the RexxVIM external functions ***/
  257. call RxVIMDropFuncs
  258. Say '  All RexxVIM functions released'
  259. call SysDropFuncs
  260. Say '  All RexxUtil functions released'
  261. exit
  262.