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

KMPETMRT.m

Go to the documentation of this file.
KMPETMRT ;SP/JML - Collect Cache Metrics for the Real-Time Error Trap Monitor ;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 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("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM DRIVER")
 N KMPCHKH,KMPFMDAY,KMPH,KMPHANG,KMPINST,KMPNDTYP,KMPPARMS,KMPSINF,KMPSINT,KMPSTOP,KMPVNODE,KMPVTEST,KMPWORK,U,Y
 N ZTDESC,ZTDTH,ZTRTN,ZTSAVE
 ;
 ; ALWAYS - verify data is not building past configured number of days - if so for any reason, delete it
 D PURGEDLY^KMPVCBG("VETM")
 ; Quit if monitor is not turned on
 I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969)'="ON" D  Q
 .I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM 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("VETM","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" I ($$ISBENODE^KMPVCCFG(KMPVNODE)=0)!(KMPVTEST=0) Q
 I $$PROD^KMPVCCFG="prod" I ($$ISBENODE^KMPVCCFG(KMPVNODE)=0)&(KMPVTEST=0) Q
 ;
 S U="^"
 S KMPFMDAY=+$$HTFM^XLFDT($H,1) ;supported by ICR #10103
 S KMPWORK=$$WORKDAY^XUWORKDY(KMPFMDAY) ;supported by ICR #10046
 S KMPSINF=$$SITEINFO^KMPVCCFG() ; site name^fac num^mail domain^prod/test^site code
 ; Main loop - tasks off collection to keep interval intact
 S ^KMPTMP("KMPV","VETM","TEMP")=0
 S KMPSTOP=0,KMPCHKH=+$H
 S KMPINST=$P(KMPVNODE,":",2),KMPNDTYP=$$NODETYPE^KMPUTLW(KMPINST)
 S KMPPARMS("KMPFMDAY")=KMPFMDAY,KMPPARMS("KMPCHKH")=KMPCHKH
 S KMPPARMS("KMPWORK")=KMPWORK,KMPPARMS("KMPSINF")=KMPSINF
 S KMPPARMS("KMPINST")=KMPINST,KMPPARMS("KMPNDTYP")=KMPNDTYP
 F  D  Q:KMPSTOP
 .I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969)'="ON" S KMPSTOP=1 Q  ; RUN FLAG SET TO 0
 .S KMPH=$H
 .I KMPH>KMPCHKH SET KMPSTOP=1 Q
 .S KMPSINT=$$GETVAL^KMPVCCFG("VETM","COLLECTION INTERVAL",8969)
 .S KMPHANG=KMPSINT*60
 .S KMPPARMS("KMPH")=KMPH,KMPPARMS("KMPSINT")=KMPSINT
 .M ^KMPTMP("KMPV","VETM",KMPVNODE,"PARMS")=KMPPARMS
 .J COLLECT(KMPVNODE)
 .H KMPHANG
 I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM DRIVER END")
 Q
 ;
COLLECT(KMPVNODE) ;
 N $ES,$ETRAP S $ETRAP="D ^%ZTER Q"
 I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM COLLECTOR")
 N B,KMPAJN,KMPDB,KMPCIO,KMPCNT,KMPDAT,KMPDBI,KMPDST,KMPEARR,KMPEDATA,KMPEDATE,KMPELINE,KMPENUM,KMPERR,KMPERRN
 N KMPETSO,KMPH,KMPINODE,KMPINST,KMPJMSG,KMPJNODE,KMPJNUM,KMPJSON,KMPLGR,KMPNDTYP,KMPNT,KMPPNAM,KMPSLOT,KMPSTAT,KMPTIMES
 N KMPTS,KMPUNAM,KMPUTCE,KMPUTCO,KMPZA,KMPZB,KMPZIO
 ;
 M KMPPARMS=^KMPTMP("KMPV","VETM",KMPVNODE,"PARMS")
 S KMPFMDAY=KMPPARMS("KMPFMDAY")
 S KMPWORK=KMPPARMS("KMPWORK"),KMPSINF=KMPPARMS("KMPSINF")
 S KMPCHKH=KMPPARMS("KMPCHKH"),U="^"
 S KMPH=KMPPARMS("KMPH"),KMPSINT=KMPPARMS("KMPSINT")
 S KMPINST=KMPPARMS("KMPINST"),KMPNDTYP=KMPPARMS("KMPNDTYP")
 ;
 S KMPJSON=##class(%DynamicObject).%New()
 S KMPJMSG=##class(%DynamicObject).%New()
 S KMPEARR=##class(%DynamicArray).%New()
 ;
 S KMPJSON.Function="VETM"
 S KMPSLOT=$$SLOT^KMPVCCFG(KMPH,KMPSINT,"HOROLOG")
 S $P(KMPH,",",2)=KMPSLOT
 S KMPTIMES=$$TSTAMP^KMPUTLW(KMPH,"HOROLOG",1) ; yyy-mm-dd hh:mm:ssZts
 S KMPETSO=$P(KMPTIMES,"^")
 S KMPUTCO=$P(KMPTIMES,"^",2)
 S KMPUTCE=$P(KMPTIMES,"^",3)
 S KMPDST=$P(KMPTIMES,"^",4)
 ;
 D SITE^KMPUTLW(KMPJSON)
 S KMPJMSG.Timestamp=KMPETSO,KMPJMSG.UtcOdbc=KMPUTCO
 S KMPJMSG.UtcEpoch=KMPUTCE,KMPJMSG.IsDst=KMPDST
 S KMPJMSG.Node=$P(KMPVNODE,":"),KMPJMSG.NodeType=KMPNDTYP
 S KMPJMSG.Instance=KMPINST,KMPJMSG.Workday=KMPWORK
 S KMPJMSG.NodeType=KMPNDTYP
 S KMPJMSG.Date=$$SHORTDAT^KMPUTLW(+$H,"HOROLOG")
 S KMPJSON.MessageData=KMPJMSG
 ;
 ; Get metrics
 S KMPDAT=+KMPH,KMPCNT=0
 S KMPENUM=+$G(^KMPTMP("KMPV","VETM","TEMP"))
 F  S KMPENUM=$O(^%ZTER(1,KMPDAT,1,KMPENUM)) Q:+KMPENUM=0  D
 .S KMPCNT=KMPCNT+1
 .S KMPELINE="",B="|"
 .S KMPJNODE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"J"))
 .S KMPINODE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"I"))
 .S KMPEDATE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"H"))
 .S KMPTS=$P($$TSTAMP^KMPUTLW(KMPEDATE,"HOROLOG",1),"^")
 .S KMPDBI=$P(KMPJNODE,"^",4),KMPDB=$P(KMPDBI,":",1)
 .S KMPINST=$P(KMPDBI,":",2),KMPNT=$$NODETYPE^KMPUTLW(KMPINST)
 .S KMPERRN=+$G(^%ZTER(1,KMPDAT,1,KMPENUM,0)),KMPERR=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"ZE"))
 .S KMPLGR=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"GR"))
 .S KMPLGR=$TR(KMPLGR,"|","b")
 .S KMPCIO=$TR($P(KMPINODE,"^",1),"|","~"),KMPZA=$P(KMPINODE,"^",2)
 .S KMPZB=$P(KMPINODE,"^",3),KMPZIO=$TR($P(KMPINODE,"^",4),"|","~")
 .I KMPZA["|" S KMPZA=$REPLACE(KMPZA,"|","VerticalBar")
 .I KMPZB["|" S KMPZB=$REPLACE(KMPZB,"|","VerticalBar")
 .I KMPZIO["|" S KMPZIO=$REPLACE(KMPZIO,"|","VerticalBar")
 .S KMPJNUM=$P(KMPJNODE,"^",1),KMPPNAM=$P(KMPJNODE,"^",2)
 .S KMPUNAM=$P(KMPJNODE,"^",3),KMPAJN=$P(KMPJNODE,"^",5)
 .S KMPELINE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"LINE"))
 .S KMPEDATA=KMPERRN_B_KMPTS_B_KMPTS_B_KMPDB_B_KMPINST_B_KMPNT_B_KMPERR_B_KMPLGR_B_KMPCIO_B
 .S KMPEDATA=KMPEDATA_KMPZA_B_KMPZB_B_KMPZIO_B_KMPJNUM_B_KMPPNAM_B_KMPUNAM_B_KMPAJN_B_KMPELINE
 .D KMPEARR.%Push(KMPEDATA)
 .S ^KMPTMP("KMPV","VETM","TEMP")=KMPENUM
 S KMPJSON.Details=KMPEARR
 I KMPCNT=0 D  Q
 .I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM COLLECTOR END")
 ;
 S KMPSTAT=$$POST^KMPUTLW(KMPJSON,"/errortrap",,"VETM")
 I +KMPSTAT'=200 H 30 S KMPSTAT=$$POST^KMPUTLW(KMPJSON,"/errortrap",,"VETM")
 S ^XTMP("KMP "_KMPFMDAY,"VETM","HTTP",KMPVNODE,$P($H,",",2))=KMPSTAT
 I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM COLLECTOR END")
 I +KMPSTAT'=200 D SETRETRY
 Q
 ;
SETRETRY ;
 N KMPTEXT
 S KMPTEXT("SUBJECT")="VSM FAILED SEND: VETM 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","VETM","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","VETM","RETRY",KMPVNODE,KMPDAY)) Q:KMPDAY=""  D
 .S KMPI=""
 .F  S KMPI=$O(^KMPTMP("KMPV","VETM","RETRY",KMPVNODE,KMPDAY,KMPI)) Q:KMPI=""  D
 ..S KMPJSON=$G(^KMPTMP("KMPV","VETM","RETRY",KMPVNODE,KMPDAY,KMPI))
 ..S KMPSTAT=$$POST^KMPUTLW({}.%FromJSON(KMPJSON),"/errortrap",,"VETM")
 ..I +KMPSTAT=200 K ^KMPTMP("KMPV","VETM","RETRY",KMPVNODE,KMPDAY,KMPI)
 ..H $R(10)
 Q