| 1 | NVSMSG ;slcciofo/maw,mb-alert and messaging utility ;02:21 PM  19 Apr 2000
 | 
|---|
| 2 |  ;;2.0;NVS system management utility;**11,12,13**; Jan 01, 1999
 | 
|---|
| 3 |  ;
 | 
|---|
| 4 |  ; **NOTE: THIS ROUTINE IS USED ONLY ON INTERSYSTEMS CACHE SYSTEMS**
 | 
|---|
| 5 |  ;
 | 
|---|
| 6 |  ; This routine is invoked by various NVS system monitoring utilities
 | 
|---|
| 7 |  ; (for example, unattended backup, integrity check, etc.).  It retrieves
 | 
|---|
| 8 |  ; the contents of the host file specified and places it in a mail message.
 | 
|---|
| 9 |  ; For Intersystems Cache, a CSTAT can be generated by this utility (see
 | 
|---|
| 10 |  ; further documentation below).  If warranted, an alert can also be set
 | 
|---|
| 11 |  ; up by this utility (see documentation below).
 | 
|---|
| 12 |  ;
 | 
|---|
| 13 | EN(DIR,FILE,SUBJ,ALERT,CSTAT)   ;
 | 
|---|
| 14 |  ;
 | 
|---|
| 15 |  ; DIR   = the directory path where FILE will be found.
 | 
|---|
| 16 |  ;         If DIR is passed = "", this module aborts.
 | 
|---|
| 17 |  ; FILE  = the name of the host file to be retrieved and
 | 
|---|
| 18 |  ;            included in the mail message.
 | 
|---|
| 19 |  ; SUBJ  = a string (up to 30 characters) that will be used
 | 
|---|
| 20 |  ;            as the message (and alert, if appropriate) subject.
 | 
|---|
| 21 |  ;            Note:  SUBJ will be truncated if $LENGTH>30
 | 
|---|
| 22 |  ; ALERT = pass = 1 if an alert is to be sent
 | 
|---|
| 23 |  ; CSTAT = pass = 1 and a CSTAT will be generated
 | 
|---|
| 24 |  ;
 | 
|---|
| 25 |  N DEVOK,ERRFLAG,I,LINENUM,MAILGRP,MSGNUM
 | 
|---|
| 26 |  S $ZT=$G(^%ZOSF("ERRTN"))
 | 
|---|
| 27 |  S U="^"
 | 
|---|
| 28 |  K ^TMP($J),^XTMP("NVSMSG")
 | 
|---|
| 29 |  I $G(SUBJ)="" S SUBJ="NVS SYSTEM PROCEDURE MESSAGE"
 | 
|---|
| 30 |  I $L(SUBJ)>30 S SUBJ=$E(SUBJ,1,30)
 | 
|---|
| 31 |  I FILE=""&(DIR'="") D
 | 
|---|
| 32 |  .I $ZV["OpenVMS" D  Q
 | 
|---|
| 33 |  ..I DIR[":"&(DIR'["]") D  Q
 | 
|---|
| 34 |  ...S FILE=$P(DIR,":",2)
 | 
|---|
| 35 |  ...S DIR=$P(DIR,":")_":"
 | 
|---|
| 36 |  ..I DIR["]" D  Q
 | 
|---|
| 37 |  ...S FILE=$P(DIR,"]",2)
 | 
|---|
| 38 |  ...S DIR=$P(DIR,"]")_"]"
 | 
|---|
| 39 |  .I $ZV["Windows" D
 | 
|---|
| 40 |  ..S DIR=$TR(DIR,"/","\")
 | 
|---|
| 41 |  ..F I=1:1 Q:$P(DIR,"\",I)=""
 | 
|---|
| 42 |  ..S FILE=$P(DIR,"\",I-1)
 | 
|---|
| 43 |  ..S DIR=$P(DIR,FILE)
 | 
|---|
| 44 |  S ALERT=+ALERT
 | 
|---|
| 45 |  S CSTAT=+CSTAT
 | 
|---|
| 46 |  ;
 | 
|---|
| 47 |  I DIR=""!(FILE="") D  Q
 | 
|---|
| 48 |  .S ^TMP($J,1)="An error occured during a system procedure."
 | 
|---|
| 49 |  .S ^TMP($J,2)="No log file was specified.  Following is the"
 | 
|---|
| 50 |  .S ^TMP($J,3)="information that was provided by the calling"
 | 
|---|
| 51 |  .S ^TMP($J,4)="application:"
 | 
|---|
| 52 |  .S ^TMP($J,5)="  Host file directory: "_$S($G(DIR)'="":DIR,1:"not specified")
 | 
|---|
| 53 |  .S ^TMP($J,6)="  Host file name: "_$S($G(FILE)'="":FILE,1:"not specified")
 | 
|---|
| 54 |  .S ^TMP($J,7)="  Subject: "_$S($G(SUBJ)'="":SUBJ,1:"not specified")
 | 
|---|
| 55 |  .S ^TMP($J,8)="No other information is available.  Please investigate."
 | 
|---|
| 56 |  .S MAILGRP=""
 | 
|---|
| 57 |  .I $$GROUP("IRM") S MAILGRP="G.IRM"
 | 
|---|
| 58 |  .I MAILGRP="" S MAILGRP=.5
 | 
|---|
| 59 |  .S MSGNUM=0
 | 
|---|
| 60 |  .D MAIL(SUBJ,MAILGRP,"^TMP("_$J_",",+$G(ALERT),.MSGNUM)
 | 
|---|
| 61 |  ;
 | 
|---|
| 62 |  S ^XTMP("NVSMSG",0)=$$DT^XLFDT_U_$$DT^XLFDT_U_"NVS Procedure Message"
 | 
|---|
| 63 |  ;
 | 
|---|
| 64 |  ; call Kernel to retrieve the log file contents and set the temporary
 | 
|---|
| 65 |  ; global for us...
 | 
|---|
| 66 |  S DEVOK=1
 | 
|---|
| 67 |  S DEVOK=$$FTG^%ZISH(DIR,FILE,"^XTMP(""NVSMSG"",1)",2,"OVF")
 | 
|---|
| 68 |  ;
 | 
|---|
| 69 |  ; if DEVOK is 0, then the log file couldn't be retrieved, or the
 | 
|---|
| 70 |  ; temporary global array could not be set.  Set up the message to
 | 
|---|
| 71 |  ; relay this information...
 | 
|---|
| 72 |  I 'DEVOK D
 | 
|---|
| 73 |  .S ^TMP($J,1)="An error occured attempting to retrieve a specified host"
 | 
|---|
| 74 |  .S ^TMP($J,2)="file during a system process.  Here is the information"
 | 
|---|
| 75 |  .S ^TMP($J,3)="specified by the calling utility:"
 | 
|---|
| 76 |  .S ^TMP($J,4)="Directory: "_$S(DIR'="":DIR,1:"not specified")
 | 
|---|
| 77 |  .S ^TMP($J,5)="File name: "_$S(FILE'="":FILE,1:"not specified")
 | 
|---|
| 78 |  .S ^TMP($J,6)="Subject: "_$S(SUBJ'="":SUBJ,1:"not specified")
 | 
|---|
| 79 |  ;
 | 
|---|
| 80 |  ; retrieve the text from the temporary global and put into our local array...
 | 
|---|
| 81 |  I DEVOK D
 | 
|---|
| 82 |  .S (ERRFLAG,LINENUM)=0
 | 
|---|
| 83 |  .F  S LINENUM=$O(^XTMP("NVSMSG",LINENUM)) Q:'LINENUM!(ERRFLAG=1)  D
 | 
|---|
| 84 |  ..S ^TMP($J,LINENUM)=^XTMP("NVSMSG",LINENUM)
 | 
|---|
| 85 |  ..I ^TMP($J,LINENUM)["WARNING"!(^TMP($J,LINENUM)["$ZE") S ERRFLAG=1
 | 
|---|
| 86 |  .;
 | 
|---|
| 87 |  .; check for ERRFLAG.  if it = 1, then warnings and/or errors exist in
 | 
|---|
| 88 |  .; the log file.  let's insert a line right at the top of the message text
 | 
|---|
| 89 |  .; indicating that fact...
 | 
|---|
| 90 |  .I +$G(ERRFLAG) D
 | 
|---|
| 91 |  ..S ^TMP($J,.1)="**********************>> WARNING <<***********************"
 | 
|---|
| 92 |  ..S ^TMP($J,.2)="* ERROR AND/OR WARNING MESSAGES EXIST IN THIS LOG FILE!! *"
 | 
|---|
| 93 |  ..S ^TMP($J,.3)="* RECOMMEND COMPLETE REVIEW OF THE LOG FILE AND          *"
 | 
|---|
| 94 |  ..S ^TMP($J,.4)="* CORRECTIVE ACTION BE TAKEN IMMEDIATELY!!               *"
 | 
|---|
| 95 |  ..S ^TMP($J,.5)="**********************************************************"
 | 
|---|
| 96 |  .;
 | 
|---|
| 97 |  .; if CSTAT, generate one and tell the recipients that we did that...
 | 
|---|
| 98 |  .I +$G(CSTAT) D
 | 
|---|
| 99 |  ..I $ZV["OpenVMS" S X=$ZF(-1,"@SYS$COMMON:[SYSMGR]CSTAT.COM")
 | 
|---|
| 100 |  ..I $ZV["Windows NT" S X=$ZF(-1,"T:\ANONYMOUS\CSTAT\CSTAT.CMD")
 | 
|---|
| 101 |  ..S ^TMP($J,.6)=" "
 | 
|---|
| 102 |  ..S ^TMP($J,.7)="NOTE!! THE CSTAT COMMAND FILE WAS CALLED AS A RESULT OF THIS PROBLEM."
 | 
|---|
| 103 |  ..S ^TMP($J,.8)="Please look for the CSTAT reports in "
 | 
|---|
| 104 |  ..I $ZV["OpenVMS" S ^TMP($J,.8)=^TMP($J,.8)_"USER$:[ANONYMOUS.CSTAT]"
 | 
|---|
| 105 |  ..I $ZV["Windows NT" S ^TMP($J,.8)=^TMP($J,.8)_"T:\ANONYMOUS\CSTAT\"
 | 
|---|
| 106 |  ..S ^TMP($J,.9)=" "
 | 
|---|
| 107 |  ;
 | 
|---|
| 108 |  ; send the mail message.  NOTE:  site can change the mail group to be looked
 | 
|---|
| 109 |  ; up ("IRM" is the default) by changing the mail group name in the following...
 | 
|---|
| 110 |  S MAILGRP=""
 | 
|---|
| 111 |  I $$GROUP("IRM") S MAILGRP="G.IRM"
 | 
|---|
| 112 |  I MAILGRP="" S MAILGRP=.5
 | 
|---|
| 113 |  S MSGNUM=0
 | 
|---|
| 114 |  D MAIL(SUBJ,MAILGRP,"^TMP("_$J_",",+$G(ALERT),.MSGNUM)
 | 
|---|
| 115 |  ;
 | 
|---|
| 116 |  ; if ALERT requested *and* message recipient is not POSTMASTER, set up the alert...
 | 
|---|
| 117 |  I +$G(ALERT)&(+MAILGRP'=.5) D ALERT(SUBJ_" Check mail message "_MSGNUM_".",MAILGRP)
 | 
|---|
| 118 |  ;
 | 
|---|
| 119 |  K ^TMP($J),^XTMP("NVSMSG")
 | 
|---|
| 120 |  Q
 | 
|---|
| 121 |  ;        
 | 
|---|
| 122 | MAIL(MSGSUBJ,RECIP,TEXT,NVS,MSG)        ; send e-mail...
 | 
|---|
| 123 |  ; MSGSUBJ = message subject
 | 
|---|
| 124 |  ; RECIP   = mail group name (local and/or remote) or local user DUZ
 | 
|---|
| 125 |  ; TEXT    = local or global array reference for the text to be included in the message.
 | 
|---|
| 126 |  ;           Note:  this reference must be in the form required by ^XMD -- for example:
 | 
|---|
| 127 |  ;             TEXT="array("
 | 
|---|
| 128 |  ;             TEXT="^TMP($J,"
 | 
|---|
| 129 |  ; NVS     = if passed=1 then mail group G.CSAVANTI@FORUM.MED.VA.GOV added to recipients
 | 
|---|
| 130 |  ; MSG     = passed by reference, returned as the message number (XMZ)
 | 
|---|
| 131 |  ;
 | 
|---|
| 132 |  N XMDUZ,XMSUB,XMTEXT,XMY,XMZ,XTEXT
 | 
|---|
| 133 |  S XMDUZ=.5
 | 
|---|
| 134 |  S XMSUB=MSGSUBJ
 | 
|---|
| 135 |  S XMY(RECIP)=""
 | 
|---|
| 136 |  I +$G(NVS)=1 S XMY("G.CSAVANTI@FORUM.MED.VA.GOV")=""
 | 
|---|
| 137 |  I TEXT'="" S XMTEXT=TEXT
 | 
|---|
| 138 |  I TEXT="" D
 | 
|---|
| 139 |  .S XTEXT(1)="NO TEXT WAS DEFINED FOR THIS MESSAGE"
 | 
|---|
| 140 |  .S XMTEXT="XTEXT("
 | 
|---|
| 141 |  D ^XMD
 | 
|---|
| 142 |  S MSG=XMZ
 | 
|---|
| 143 |  Q
 | 
|---|
| 144 |  ;
 | 
|---|
| 145 | ALERT(ASUBJ,RECIP)      ; send a simple alert...
 | 
|---|
| 146 |  ; ASUBJ = alert subject (can be same as mail message subject)
 | 
|---|
| 147 |  ; RECIP = an individual local user or mail group to which the alert will be sent
 | 
|---|
| 148 |  ;
 | 
|---|
| 149 |  N DUZ,XQA,XQAID,XQAMSG
 | 
|---|
| 150 |  S DUZ=".5"
 | 
|---|
| 151 |  S XQA(RECIP)=""
 | 
|---|
| 152 |  S XQAID="NVS"_$J
 | 
|---|
| 153 |  S XQAMSG=ASUBJ
 | 
|---|
| 154 |  D SETUP^XQALERT
 | 
|---|
| 155 |  Q
 | 
|---|
| 156 |  ;
 | 
|---|
| 157 | GROUP(X)        ; verify a specified mail group exists and that it has membership...
 | 
|---|
| 158 |  ; X = name of mail group (example: "IRM")
 | 
|---|
| 159 |  ; returns 0 if not found, 1 if found
 | 
|---|
| 160 |  N Y
 | 
|---|
| 161 |  S Y=+$O(^XMB(3.8,"B",X,0))
 | 
|---|
| 162 |  I Y'>0 Q 0
 | 
|---|
| 163 |  ; check for members in this group...
 | 
|---|
| 164 |  I $O(^XMB(3.8,Y,1,"B",""))="" Q 0
 | 
|---|
| 165 |  Q 1
 | 
|---|