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