Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: KMPBEMRT

KMPBEMRT.m

Go to the documentation of this file.
KMPBEMRT ;SP/JML - VBEM Nightly compression and transmission;2/1/2023
 ;;4.0;CAPACITY MANAGEMENT;**1,2,3,4**;3/1/2018;Build 36
 ;
 ; Reference to $$WORKDAY^XUWORKDY in ICR #10046
 ; Reference to $$HTFM^XLFDT in ICR #10103
 ; Reference to $$SITE^VASTIE in ICR #10112
 ; Reference to GETENV^%ZOSV, EC^%ZOSV and LGR^%ZOSV in ICR #10097
 ; Reference to $ESTACK, $ETRAP, ^%ZTER and UNWIND^%ZTER in ICR #1621
 ;
RUN ;
 N $ESTACK,$ETRAP S $ETRAP="D ^%ZTER Q"
 I $$GETVAL^KMPVCCFG("VBEM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VBEM DRIVER")
 N KMPPARMS,KMPVSITE,KMPVSINF,KMPSC,KMPVSTOP,KMPVCHKH,KMPVH,KMPVSINT,KMPVHANG,KMPVSLOT,ZTDTH,ZTRTN,ZTDESC,ZTSAVE,%
 N KMPDET,KMPDST,KMPETSO,KMPTIMES,KMPUTCE,KMPUTCO,KMPVLINE,KMPVNODE,KMPVTEST,Y,KMPFMDAY
 ; ALWAYS - verify data is not building past configured number of days - if so for any reason, delete it
 D PURGEDLY^KMPVCBG("VBEM")
 ; Quit if monitor is not turned on
 I $$GETVAL^KMPVCCFG("VBEM","ONOFF",8969)'="ON" D  Q
 .I $$GETVAL^KMPVCCFG("VBEM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VBEM DRIVER END")
 ; Environment Check
 ;   if TEST system - quit if system is a front end OR allow test=no
 ;   if PROD system - quit if system is a front end AND allow test=no
 S KMPVTEST=$$GETVAL^KMPVCCFG("VBEM","ALLOW TEST SYSTEM",8969,"I")
 D GETENV^%ZOSV S KMPVNODE=$P(Y,U,3)_":"_$P($P(Y,U,4),":",2) ;supported by ICR #10097
 I $$PROD^KMPVCCFG'="prod",$$GETVAL^KMPVCCFG("VTCM","ALLOW TEST SYSTEM",8969,"I")'=1 Q
 ;
 D NOW^%DTC
 S KMPVSITE=$$SITE^VASITE($P(%,".")) ;supported by ICR #10112
 S KMPVSINF=$$SITEINFO^KMPVCCFG()
 S KMPSC=$P(KMPVSINF,"^",5)
 ;
 ; COMPRESS DATA - REMOVE $J SPECIFICITY - KILL 'DLY' NODE
 S KMPVSTOP=0,KMPVCHKH=+$H
 ; Setup Parameter array to send to job
 S KMPPARMS("KMPVSITE")=KMPVSITE,KMPPARMS("KMPVSINF")=KMPVSINF
 S KMPPARMS("KMPSC")=KMPSC,KMPPARMS("KMPVCHKH")=KMPVCHKH
 S KMPPARMS("KMPFMDAY")=+$$HTFM^XLFDT($H,1) ;supported by ICR #10103
 F  D  Q:KMPVSTOP
 .I $$GETVAL^KMPVCCFG("VBEM","ONOFF",8969)'="ON" S KMPVSTOP=1 Q  ; RUN FLAG SET TO 0
 .S KMPVH=$H
 .I KMPVH>KMPVCHKH SET KMPVSTOP=1 Q
 .S KMPVSINT=$$GETVAL^KMPVCCFG("VBEM","COLLECTION INTERVAL",8969)
 .S KMPVHANG=KMPVSINT*60
 .S KMPVSLOT=$$SLOT^KMPVCCFG(KMPVH,KMPVSINT,"HOROLOG")
 .S KMPPARMS("KMPVH")=KMPVH,KMPPARMS("KMPVSINT")=KMPVSINT
 .S KMPPARMS("KMPVSLOT")=KMPVSLOT
 .M ^KMPTMP("KMPV","VBEM",KMPVNODE,"PARMS")=KMPPARMS
 .J COLLECT(KMPVNODE)
 .H KMPVHANG
 I $$GETVAL^KMPVCCFG("VBEM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VBEM DRIVER END")
 Q
COLLECT(KMPVNODE) ;
 N $ES,$ETRAP S $ETRAP="D ^%ZTER Q"
 I $$GETVAL^KMPVCCFG("VBEM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VBEM COLLECTOR")
 N B,KMPCNT,KMPDATA,KMPDATE,KMPDONE,KMPETS,KMPINST,KMPLI,KMPMAX,KMPNT,KMPSTAT,KMPTI,KMPVD,KMPVDATA,KMPVFMDAY,KMPVHDAY
 N KMPVI,KMPVJ,KMPVJTOT,KMPVLN,KMPVN,KMPVO,KMPVOPT,KMPVTIME,KMPVUTOT,KMPVWD
 N KMPDARR,KMPJMSG
 ;
 K ^KMPTMP("KMPV","VBEM","TRANSMIT",KMPVNODE)
 K ^KMPTMP("KMPV","VBEM","COMPRESS",KMPVNODE)
 M KMPPARMS=^KMPTMP("KMPV","VBEM",KMPVNODE,"PARMS")
 S KMPVSITE=KMPPARMS("KMPVSITE"),KMPVSINF=KMPPARMS("KMPVSINF")
 S KMPSC=KMPPARMS("KMPSC"),KMPVCHKH=KMPPARMS("KMPVCHKH")
 S KMPVH=KMPPARMS("KMPVH"),KMPVSINT=KMPPARMS("KMPVSINT")
 S KMPVSLOT=KMPPARMS("KMPVSLOT"),KMPFMDAY=KMPPARMS("KMPFMDAY"),U="^"
 ;
 S KMPVHDAY=""
 F  S KMPVHDAY=$O(^KMPTMP("KMPV","VBEM","DLY",KMPVHDAY)) Q:(KMPVHDAY="")  D
 .S KMPVTIME=""
 .F  S KMPVTIME=$O(^KMPTMP("KMPV","VBEM","DLY",KMPVHDAY,KMPVNODE,KMPVTIME)) Q:KMPVTIME=""  D
 ..I KMPVTIME>=KMPVSLOT,KMPVHDAY>=+$H Q
 ..S KMPVOPT=""
 ..F  S KMPVOPT=$O(^KMPTMP("KMPV","VBEM","DLY",KMPVHDAY,KMPVNODE,KMPVTIME,KMPVOPT)) Q:KMPVOPT=""  D
 ...S KMPVJ="",KMPVDATA="",KMPVJTOT="",KMPVUTOT=0
 ...F  S KMPVJ=$O(^KMPTMP("KMPV","VBEM","DLY",KMPVHDAY,KMPVNODE,KMPVTIME,KMPVOPT,KMPVJ)) Q:KMPVJ=""  D
 ....S KMPVDATA=$G(^KMPTMP("KMPV","VBEM","DLY",KMPVHDAY,KMPVNODE,KMPVTIME,KMPVOPT,KMPVJ))
 ....F KMPVI=1:1:6 S $P(KMPVJTOT,"^",KMPVI)=$P(KMPVDATA,"^",KMPVI)+$P(KMPVJTOT,"^",KMPVI)
 ....S KMPVUTOT=KMPVUTOT+1
 ...S ^KMPTMP("KMPV","VBEM","COMPRESS",KMPVNODE,KMPVHDAY,KMPVTIME,KMPVOPT)=KMPVJTOT_"^"_KMPVUTOT
 ..K ^KMPTMP("KMPV","VBEM","DLY",KMPVHDAY,KMPVNODE,KMPVTIME)  ; Kill node once all data compiled in 'compress' node
 ; PROCESS 'COMPRESS' NODE FOR TRANSMISSION
 S KMPVHDAY="",B="|"
 F  S KMPVHDAY=$O(^KMPTMP("KMPV","VBEM","COMPRESS",KMPVNODE,KMPVHDAY)) Q:KMPVHDAY=""  D
 .; IF BETWEEN 1 AND 7 DAYS OLD AND NOT TRANSMITTED SEND WARNING MESSAGE AND ATTEMPT TO TRANSMIT AGAIN
 .I KMPVHDAY<(+$H-1) D CANMSG^KMPUTLW("TRANWARN","VBEM",KMPVSITE,KMPVHDAY)
 .S KMPVLN=1
 .S KMPVTIME=""
 .F  S KMPVTIME=$O(^KMPTMP("KMPV","VBEM","COMPRESS",KMPVNODE,KMPVHDAY,KMPVTIME)) Q:KMPVTIME=""  D
 ..S KMPVOPT=""
 ..F  S KMPVOPT=$O(^KMPTMP("KMPV","VBEM","COMPRESS",KMPVNODE,KMPVHDAY,KMPVTIME,KMPVOPT)) Q:KMPVOPT=""  D
 ...S KMPVDATA=$G(^KMPTMP("KMPV","VBEM","COMPRESS",KMPVNODE,KMPVHDAY,KMPVTIME,KMPVOPT))
 ...S KMPVO=$TR($$EVTPKG^KMPUTLW2(KMPVOPT),"^","|")
 ...S KMPVD=$TR(KMPVDATA,"^","|")
 ...S ^KMPTMP("KMPV","VBEM","TRANSMIT",KMPVNODE,$J,KMPVHDAY,KMPVTIME,KMPVLN)=KMPVO_B_KMPVD,KMPVLN=KMPVLN+1
 ...; eventname|parentevent|eventtype|eventsource|packagenamespace|packagename|occurrences|cputime|r-lines|rcmd|gref|elapsed time|user count
 .K ^KMPTMP("KMPV","VBEM","COMPRESS",KMPVNODE,KMPVHDAY)
 ; quit if no data to transmit.
 I '$D(^KMPTMP("KMPV","VBEM","TRANSMIT",KMPVNODE,$J)) D  Q
 .I $$GETVAL^KMPVCCFG("VBEM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VBEM COLLECTOR END")
 S KMPVHDAY=""
 F  S KMPVHDAY=$O(^KMPTMP("KMPV","VBEM","TRANSMIT",KMPVNODE,$J,KMPVHDAY)) Q:KMPVHDAY=""  D
 .S KMPVFMDAY=+$$HTFM^XLFDT(KMPVHDAY,1) ;supported by ICR #10103
 .S KMPVWD=$$WORKDAY^XUWORKDY(KMPVFMDAY) ;supported by ICR #10046
 .S KMPDATE=$$SHORTDAT^KMPUTLW(KMPVHDAY,"HOROLOG")
 .S KMPVTIME=""
 .F  S KMPVTIME=$O(^KMPTMP("KMPV","VBEM","TRANSMIT",KMPVNODE,$J,KMPVHDAY,KMPVTIME)) Q:KMPVTIME=""  D
 ..S KMPTIMES=$$TSTAMP^KMPUTLW(KMPVHDAY_","_KMPVTIME,"HOROLOG",1) ; yyy-mm-dd hh:mm:ssZtz
 ..S KMPETSO=$P(KMPTIMES,"^")
 ..S KMPUTCO=$P(KMPTIMES,"^",2)
 ..S KMPUTCE=$P(KMPTIMES,"^",3)
 ..S KMPDST=$P(KMPTIMES,"^",4)
 ..S KMPVN=$P(KMPVNODE,":")
 ..S KMPINST=$P(KMPVNODE,":",2),KMPNT=$$NODETYPE^KMPUTLW(KMPINST)
 ..S KMPJSON=##class(%DynamicObject).%New()
 ..S KMPJSON.Function="VBEM"
 ..D SITE^KMPUTLW(KMPJSON)
 ..S KMPJMSG=##class(%DynamicObject).%New()
 ..S KMPJMSG.Date=KMPDATE
 ..S KMPJMSG.Workday=KMPVWD
 ..S KMPJMSG.Timestamp=KMPETSO
 ..S KMPJMSG.UtcOdbc=KMPUTCO
 ..S KMPJMSG.UtcEpoch=KMPUTCE
 ..S KMPJMSG.IsDst=KMPDST
 ..S KMPJMSG.Node=KMPVN,KMPJMSG.NodeType=KMPNT
 ..S KMPJMSG.Instance=KMPINST
 ..S KMPJSON.MessageData=KMPJMSG
 ..S KMPDARR=##class(%DynamicArray).%New()
 ..S KMPVLINE=""
 ..F  S KMPVLINE=$O(^KMPTMP("KMPV","VBEM","TRANSMIT",KMPVNODE,$J,KMPVHDAY,KMPVTIME,KMPVLINE)) Q:KMPVLINE=""  D
 ...S KMPDET=$G(^KMPTMP("KMPV","VBEM","TRANSMIT",KMPVNODE,$J,KMPVHDAY,KMPVTIME,KMPVLINE))
 ...D KMPDARR.%Push(KMPDET)
 ..S KMPJSON.Details=KMPDARR
 ..S KMPSTAT=$$POST^KMPUTLW(KMPJSON,"/businessevent",1,"VBEM")
 ..I +KMPSTAT'=200 H 30 S KMPSTAT=$$POST^KMPUTLW(KMPJSON,"/businessevent",1,"VBEM")
 ..K ^KMPTMP("KMPV","VBEM","TRANSMIT",KMPVNODE,$J,KMPVHDAY,KMPVTIME)
 ..S ^XTMP("KMP "_KMPFMDAY,"VBEM","HTTP",KMPVNODE,$P($H,",",2))=KMPSTAT
 ..I +KMPSTAT'=200 D SETRETRY
 I $$GETVAL^KMPVCCFG("VBEM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VBEM COLLECTOR END")
 Q
 ;
SETRETRY ;
 N KMPTEXT
 S KMPTEXT("SUBJECT")="VSM FAILED SEND: VBEM at "_KMPJSON.Site.SiteCode
 S KMPTEXT(1)="Status Code: "_+KMPSTAT
 S KMPTEXT(2)="Status Text: "_$P(KMPSTAT,"^",2)
 S KMPTEXT(3)="Response Time: "_$P(KMPSTAT,"^",3)
 S KMPTEXT(4)="Node: "_KMPVNODE
 D INFOMSG^KMPUTLW(.KMPTEXT)
 S ^KMPTMP("KMPV","VBEM","RETRY",KMPVNODE,+$H,$H)=KMPJSON.%ToJSON()
 Q
 ;
RETRY ;  retry failed POSTS
 N KMPDAY,KMPI,KMPJSON,KMPSTAT,KMPVNODE,Y
 ;
 D GETENV^%ZOSV S KMPVNODE=$P(Y,"^",3)_":"_$P($P(Y,"^",4),":",2) ;supported by ICR #10097
 S KMPDAY=""
 F  S KMPDAY=$O(^KMPTMP("KMPV","VBEM","RETRY",KMPVNODE,KMPDAY)) Q:KMPDAY=""  D
 .S KMPI=""
 .F  S KMPI=$O(^KMPTMP("KMPV","VBEM","RETRY",KMPVNODE,KMPDAY,KMPI)) Q:KMPI=""  D
 ..S KMPJSON=$G(^KMPTMP("KMPV","VBEM","RETRY",KMPVNODE,KMPDAY,KMPI))
 ..S KMPSTAT=$$POST^KMPUTLW({}.%FromJSON(KMPJSON),"/businessevent",1,"VBEM")
 ..I +KMPSTAT=200 K ^KMPTMP("KMPV","VBEM","RETRY",KMPVNODE,KMPDAY,KMPI)
 ..H $R(10)
 Q