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

KMPMCMRT.m

Go to the documentation of this file.
KMPMCMRT ;ATL/JML - Collect HL7/HLO counts for the VistA Message Count Monitor ;2/1/2023
 ;;4.0;CAPACITY MANAGEMENT;**1,2,3,4**;3/1/2018;Build 36
 ;
 ; Reference to $$HTFM^XLFDT in ICR #10103
 ; Reference to $$WORKDAY^XUWORKDY in ICR #10046
 ; Reference to GETENV^%ZOSV, EC^%ZOSV and LGR^%ZOSV in ICR #10097
 ; Reference to $ESTACK, $ETRAP, ^%ZTER and UNWIND^%ZTER in ICR #1621
 ;
RUN ; Collect metrics per configured interval and store in ^KMPTMP("KMPV","VMCM","DLY" -- CALLED VIA CACHE TASK MANAGER
 ;
 ;
 N $ESTACK,$ETRAP S $ETRAP="D ^%ZTER Q"
 I $$GETVAL^KMPVCCFG("VMCM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VMCM DRIVER")
 N KMPD,KMPPARMS,KMPFMDAY,KMPH,KMPNDTYP,KMPSC,KMPVCHKH,KMPVH,KMPVHANG,KMPVNODE,KMPVSINF,KMPVSINT,KMPVSTOP,KMPVTEST
 N KMPDST,KMPETSO,KMPINST,KMPTIMES,KMPUTCE,KMPUTCO,KMPWORK
 N Y,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("VMCM")
 ; Quit if monitor is not turned on
 I $$GETVAL^KMPVCCFG("VMCM","ONOFF",8969)'="ON" D  Q
 .I $$GETVAL^KMPVCCFG("VMCM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VMCM 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("VMCM","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 KMPVSTOP=0,KMPVCHKH=+$H
 S KMPVSINF=$$SITEINFO^KMPVCCFG()
 S KMPSC=$P(KMPVSINF,"^",5)
 S KMPH=$H,KMPD=$P(KMPH,","),KMPFMDAY=+$$HTFM^XLFDT(KMPH,1) ;supported by ICR #10103
 S KMPWORK=$$WORKDAY^XUWORKDY(KMPFMDAY) ;supported by ICR #10046
 S KMPINST=$P(KMPVNODE,":",2),KMPNDTYP=$$NODETYPE^KMPUTLW(KMPINST)
 S KMPPARMS("KMPVCHKH")=KMPVCHKH,KMPPARMS("KMPVSINF")=KMPVSINF
 S KMPPARMS("KMPSC")=KMPSC,KMPPARMS("KMPH")=KMPH
 S KMPPARMS("KMPD")=KMPD,KMPPARMS("KMPFMDAY")=KMPFMDAY
 S KMPPARMS("KMPINST")=KMPINST,KMPPARMS("KMPNDTYP")=KMPNDTYP
 S KMPPARMS("KMPWORK")=KMPWORK
 F  D  Q:KMPVSTOP
 .I $$GETVAL^KMPVCCFG("VMCM","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("VMCM","COLLECTION INTERVAL",8969)
 .S KMPVHANG=KMPVSINT*60
 .S KMPPARMS("KMPVH")=KMPVH,KMPPARMS("KMPVSINT")=KMPVSINT
 .M ^KMPTMP("KMPV","VMCM",KMPVNODE,"PARMS")=KMPPARMS
 .J COLLECT(KMPVNODE)
 .H KMPVHANG
 I $$GETVAL^KMPVCCFG("VMCM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VMCM DRIVER END")
 Q
 ;
COLLECT(KMPVNODE) ;
 N $ES,$ETRAP S $ETRAP="D ^%ZTER Q"
 I $$GETVAL^KMPVCCFG("VMCM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VMCM COLLECTOR")
 N B,KMPARR,KMPARR1,KMPCURR,KMPDELTA,KMPDEV,KMPETS,KMPHLOIN,KMPHLOUT,KMPNDTYP,KMPINST,KMPPETS,KMPPREV,KMPVLIEN,KMPVLLINE,KMPVLN,KMPVLNAME
 N KMPVLPROC,KMPVLRECV,KMPVLSEND,KMPVLSENT,KMPVLSTATE,KMPVTIME
 ;
 K ^KMPTMP("KMPV","VMCM","TRANSMIT")
 M KMPPARMS=^KMPTMP("KMPV","VMCM",KMPVNODE,"PARMS")
 M KMPARR=^KMPTMP("KMPV","VMCM","PREVIOUS")
 S KMPVCHKH=KMPPARMS("KMPVCHKH"),KMPVSINF=KMPPARMS("KMPVSINF")
 S KMPSC=KMPPARMS("KMPSC"),KMPH=KMPPARMS("KMPH")
 S KMPD=KMPPARMS("KMPD"),KMPFMDAY=KMPPARMS("KMPFMDAY")
 S KMPWORK=KMPPARMS("KMPWORK")
 S KMPVH=KMPPARMS("KMPVH"),KMPVSINT=KMPPARMS("KMPVSINT")
 S KMPINST=KMPPARMS("KMPINST"),KMPNDTYP=KMPPARMS("KMPNDTYP")
 S KMPVLN=1,B="|",U="^"
 S KMPVTIME=$$SLOT^KMPVCCFG(KMPVH,KMPVSINT,"HOROLOG")
 S KMPTIMES=$$TSTAMP^KMPUTLW(+KMPVH_","_KMPVTIME,"HOROLOG",1) ; yyy-mm-dd hh:mm:ssZts
 S KMPETSO=$P(KMPTIMES,"^"),KMPUTCO=$P(KMPTIMES,"^",2)
 S KMPUTCE=$P(KMPTIMES,"^",3),KMPDST=$P(KMPTIMES,"^",4)
 S (KMPVLIEN,KMPVLLINE,KMPVLNAME,KMPVLSTATE)=""
 S (KMPVLRECV,KMPVLPROC,KMPVLSEND,KMPVLSENT)=0
 F  S KMPVLIEN=$O(^HLCS(870,KMPVLIEN)) Q:KMPVLIEN=""  D
 .I $D(^HLCS(870,KMPVLIEN,0)) D
 ..S KMPVLLINE=$G(^HLCS(870,KMPVLIEN,0))
 ..S KMPVLNAME=$P(KMPVLLINE,"^",1),KMPDEV=$P(KMPVLLINE,"^",4)
 ..I KMPVLNAME="" S KMPVLNAME="Unknown_"_KMPVLIEN
 ..S KMPVLSTATE=$P(KMPVLLINE,"^",5)
 ..S KMPVLRECV=+$G(^HLCS(870,KMPVLIEN,"IN QUEUE BACK POINTER"))
 ..S KMPVLPROC=+$G(^HLCS(870,KMPVLIEN,"IN QUEUE FRONT POINTER"))
 ..S KMPVLSEND=+$G(^HLCS(870,KMPVLIEN,"OUT QUEUE BACK POINTER"))
 ..S KMPVLSENT=+$G(^HLCS(870,KMPVLIEN,"OUT QUEUE FRONT POINTER"))
 ..;
 ..S KMPCURR=KMPVLRECV_"^"_KMPVLPROC_"^"_KMPVLSEND_"^"_KMPVLSENT_"^"_$P($$TSTAMP^KMPUTLW($H,"HOROLOG",0),"^",1)
 ..S KMPPREV=$G(KMPARR(KMPVLNAME)) ; VAL VAL VAL VAL TIME
 ..S KMPARR1(KMPVLNAME)=KMPCURR
 ..Q:KMPPREV=""
 ..; CALCULATE DELTA
 ..S KMPDELTA=$$CALCDELT(KMPCURR,KMPPREV)
 ..; S INTO TRANSIT GLOBAL
 ..S ^KMPTMP("KMPV","VMCM","TRANSMIT",$J,KMPVLN)=KMPVLNAME_B_KMPVLSTATE_B_KMPDEV_B_KMPDELTA,KMPVLN=KMPVLN+1
 ; Add HLO metrics
 S KMPHLOIN=$$HLODAILY("IN"),KMPHLOUT=$$HLODAILY("OUT")
 I $D(KMPARR) S ^KMPTMP("KMPV","VMCM","TRANSMIT",$J,KMPVLN)="HLO"_B_B_B_KMPHLOIN_B_B_KMPHLOUT_B
 ;
 K ^KMPTMP("KMPV","VMCM","PREVIOUS")
 M ^KMPTMP("KMPV","VMCM","PREVIOUS")=KMPARR1
 ;
 ; quit if no data to transmit.
 N KMPCNT,KMPDARR,KMPDATA,KMPDONE,KMPJMSG,KMPJSON,KMPLI,KMPMAX,KMPSTAT,KMPTI
 I '$D(^KMPTMP("KMPV","VMCM","TRANSMIT",$J)) D  Q
 .I $$GETVAL^KMPVCCFG("VMCM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VMCM COLLECTOR END")
 S KMPTI="",KMPMAX=40000
 S KMPLI=$O(^KMPTMP("KMPV","VMCM","TRANSMIT",$J,""),-1)
 S KMPDONE=0
 F  D  Q:KMPDONE
 .N KMPDARR,KMPJMSG,KMPJSON
 .S KMPJSON=##class(%DynamicObject).%New()
 .S KMPJSON.Function="VMCM"
 .S KMPJMSG=##class(%DynamicObject).%New()
 .D SITE^KMPUTLW(KMPJSON)
 .S KMPJMSG.Timestamp=KMPETSO,KMPJMSG.UtcOdbc=KMPUTCO
 .S KMPJMSG.UtcEpoch=KMPUTCE,KMPJMSG.IsDst=KMPDST
 .S KMPJMSG.Workday=KMPWORK,KMPJMSG.Instance=KMPINST
 .S KMPJMSG.Node=$P(KMPVNODE,":"),KMPJMSG.NodeType=KMPNDTYP
 .S KMPJMSG.Date=$$SHORTDAT^KMPUTLW(KMPD,"HOROLOG")
 .S KMPJSON.MessageData=KMPJMSG
 .S KMPDARR=##class(%DynamicArray).%New()
 .S KMPCNT=0
 .F  S KMPTI=$O(^KMPTMP("KMPV","VMCM","TRANSMIT",$J,KMPTI))  Q:KMPTI=""!(KMPCNT>KMPMAX)  D
 ..S KMPDATA=$G(^KMPTMP("KMPV","VMCM","TRANSMIT",$J,KMPTI))
 ..D KMPDARR.%Push(KMPDATA)
 ..I KMPTI>=KMPLI S KMPDONE=1
 ..S KMPCNT=KMPCNT+1
 .S KMPJSON.Details=KMPDARR
 .S KMPSTAT=$$POST^KMPUTLW(KMPJSON,"/messagecount",,"VMCM")
 .I +KMPSTAT'=200 S KMPSTAT=$$POST^KMPUTLW(KMPJSON,"/messagecount",,"VMCM")
 .S ^XTMP("KMP "_KMPFMDAY,"VMCM","HTTP",KMPVNODE,$P($H,",",2))=KMPSTAT
 .I +KMPSTAT'=200 D SETRETRY
 K ^KMPTMP("KMPV","VMCM","TRANSMIT",$J)
 I $$GETVAL^KMPVCCFG("VMCM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VMCM COLLECTOR END")
 Q
 ;
HLODAILY(KMPDIR) ;
 N KMPHLO,KMPHLOD,KMPHLOTS,KMPMIN,KMPVHRAP,KMPVHSAP,KMPVHTIME,KMPVHTODAY,KMPVHTOTAL,KMPVHTYPE
 S KMPVHTOTAL=0
 S KMPVHTODAY=$$DT^XLFDT
 S KMPVHTIME=KMPVHTODAY-.0001
 F  S KMPVHTIME=$O(^HLSTATS(KMPDIR,"HOURLY",KMPVHTIME)) Q:'KMPVHTIME  Q:((KMPVHTIME\1)>KMPVHTODAY)  D
 .S KMPVHSAP=""
 .F  S KMPVHSAP=$O(^HLSTATS(KMPDIR,"HOURLY",KMPVHTIME,KMPVHSAP)) Q:KMPVHSAP=""  D
 ..Q:KMPVHSAP="ACCEPT ACK"
 ..S KMPVHRAP=""
 ..F  S KMPVHRAP=$O(^HLSTATS(KMPDIR,"HOURLY",KMPVHTIME,KMPVHSAP,KMPVHRAP)) Q:KMPVHRAP=""  D
 ...S KMPVHTYPE=""
 ...F  S KMPVHTYPE=$O(^HLSTATS(KMPDIR,"HOURLY",KMPVHTIME,KMPVHSAP,KMPVHRAP,KMPVHTYPE)) Q:KMPVHTYPE=""  D
 ....S KMPVHTOTAL=KMPVHTOTAL+$G(^HLSTATS(KMPDIR,"HOURLY",KMPVHTIME,KMPVHSAP,KMPVHRAP,KMPVHTYPE))
 S KMPHLOTS=$P($$TSTAMP^KMPUTLW($H,"HOROLOG",0),"^")
 ; SET CUR INTO ARRAY
 S KMPARR1("HLO",KMPDIR)=KMPVHTOTAL_"^"_KMPHLOTS
 I '$D(KMPARR) Q ""
 ; Get previous
 S KMPHLO=KMPARR("HLO",KMPDIR)
 ; CALC TIME DIFF
 S KMPMIN=$system.SQL.DATEDIFF("mi",$P(KMPHLO,"^",2),KMPHLOTS)
 I KMPMIN=0 S KMPMIN=1
 ; CALC NUMBER DIFF
 S KMPHLOD=$FN((KMPVHTOTAL-$P(KMPHLO,"^",1))/KMPMIN,"",0)
 ; RETURN VALUE
 Q KMPHLOD
 ;
CALCDELT(KMPCURR,KMPPREV) ;
 N KMPCTS,KMPI,KMPMIN,KMPPTS,KMPDELT
 S KMPCTS=$P(KMPCURR,"^",5),KMPPTS=$P(KMPPREV,"^",5)
 S KMPMIN=$system.SQL.DATEDIFF("mi",KMPPTS,KMPCTS)
 I KMPMIN=0 S KMPMIN=1
 F KMPI=1:1:4 S $P(KMPDELT,"|",KMPI)=$FN(($P(KMPCURR,"^",KMPI)-$P(KMPPREV,"^",KMPI))/KMPMIN,"",0)
 Q KMPDELT
 ;
SETRETRY ;
 N KMPTEXT
 S KMPTEXT("SUBJECT")="VSM FAILED SEND: VMCM 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","VMCM","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","VMCM","RETRY",KMPVNODE,KMPDAY)) Q:KMPDAY=""  D
 .S KMPI=""
 .F  S KMPI=$O(^KMPTMP("KMPV","VMCM","RETRY",KMPVNODE,KMPDAY,KMPI)) Q:KMPI=""  D
 ..S KMPJSON=$G(^KMPTMP("KMPV","VMCM","RETRY",KMPVNODE,KMPDAY,KMPI))
 ..S KMPSTAT=$$POST^KMPUTLW({}.%FromJSON(KMPJSON),"/messagecount",,"VMCM")
 ..I +KMPSTAT=200 K ^KMPTMP("KMPV","VMCM","RETRY",KMPVNODE,KMPDAY,KMPI)
 ..H $R(10)
 Q