星期三, 11月 08, 2023

2011-09-27 如何收集使用者透過非 5250 終端機模式存取系統資源(DB, Data queue...) 的相關資訊(IP, user ,job ) ?


如何收集使用者透過非 5250 終端機模式存取系統資源(DB, Data queue...) 的相關資訊(IP, user ,job ) ?

從 V5R4 後系統即時提供監控 System QHST log 或 任何一個 Job 的 job log 的 Message ID,我們可以透過
這個機制來收集非 5250 終端機模式存取系統資源(DB, Data queue...) 的相關資訊(IP, user ,job )。
1. 程式 WCHCPIAD09 監控 HSTLOG MSGID CPIAD09 訊息 User &4 from client &8 connected to job &3/&2/&1 in subsystem &6 in &7 on &5.
   會傳送 CPIAD09 至 HSTLOG 的相關JOB 有透過 JDBC或ODBC存取資料庫,Client Access 檔案上下傳,透過 TCPIP DDM 存取 AS/400 Data queue等的 Job.
2. 程式 WCHCPIAD12 監控 QZLSFILE JOB LOG MSGID CPIAD12 訊息 Servicing user profile &1 from client &2.
   會傳送 CPIAD09 至 Job log 有透過 Net Server 網路芳鄰存取 AS/400 IFS 目錄檔案等相關的 Job.
   
上述二支程式會使用到 CVTDTS command,請參照  2011-08-12 如何將 DTS 格式的時間...  
上述二支程式會將訊息中的變數記錄在 QGPL/CNNLOGP 檔案中。可以使用 DSPPFM QGPL/CNNLOGP 檢視紀錄。
使用 WRKWCH WCH(*ALL) 檢視執行狀況,如下畫面:
                              Work with Watches                                
                                                            System:   SYSNAME  
Type options, press Enter.                                                     
  1=Start   2=End   5=Display                                                  
                                                                               
Opt    Type/Session                     Origin        User          Status     
                                                                               
       STRWCH                                                                  
         WCHCPIAD09                     STRWCH        VENGOAL       ACTIVE     
         WCHCPIAD12                     STRWCH        VENGOAL       ACTIVE     
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                        Bottom 
Parameters or command                                                          
===>                                                                           
F1=Help   F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F12=Cancel          


File  : QCLSRC

Member: WCHCPIAD09

Type  : CLP

Usage : CRTCLPGM QGPL/WCHCPIAD09

        執行 Command:
        STRWCH SSNID(WCHCPIAD09) WCHPGM(QGPL/WCHCPIAD09)                 
               WCHMSG((CPIAD09))                                         
               WCHMSGQ((*HSTLOG))
OS    : V5R4

/* ================================================================ */
/*                                                                  */
/* Program    : WCHCPIAD09                                          */
/*                                                                  */
/* Description: Monitor QHST log msgid CPIAD09 for job QZDASOINIT   */
/*                                                     QZHQSSRV     */
/*                                                     QNPSERVS     */
/*                                                     QZRCSRVS     */
/*                                                     QTFPJTCP     */
/*                                                     QPWFSERVSO   */
/*              Log connect user, client ip, job information        */
/*              to file QGPL/CNNLOGP.                               */
/*                                                                  */
/* Date       : 2011/08/24                                          */
/*                                                                  */
/* Author     : Vengoal Chang                                       */
/* ================================================================ */
/*                                                                  */
/*                                                                  */
/* CRTCLPGM PGM(WCHCPIAD09)                                         */
/*                                                                  */
/* Use following command to find what job issue CPIAD12 to job log  */
/* and issue CPIAD09 to history log.                                */
/*                                                                  */
/* DSPLOG PERIOD((*AVAIL *CURRENT) (*AVAIL *CURRENT)) MSGID(CPIAD09)*/
/* then record job name and append to STRWCH command parameter      */
/* WCHJOB                                                           */
/*                                                                  */
/* QZLSFILE job don't send CPIAD09 to history log.                  */
/* so need monitor CPIAD12 for job QZLSFILE                         */
/*                                                                  */
/* Before run STRWCH command, first create cnnlogp                  */
/* CRTPF QGPL/CNNLOGP RCDLEN(512)                                   */
/* log data is msgid CPIAD09 + message replacement data             */
/*  &1       *CHAR            10    jobname                         */
/*  &2       *CHAR            10    jobuser                         */
/*  &3       *CHAR             6    jobnumber                       */
/*  &4       *CHAR            10    current connect user            */
/*  &5       *DTS                   convert to YYYYMMDDHHMISS       */
/*  &6       *CHAR            10    subsystem                       */
/*  &7       *CHAR            10    subsystem library               */
/*  &8       *CHAR           255    client ip                       */
/*                                                                  */
/* STRWCH SSNID(WCHCPIAD09) WCHPGM(QGPL/WCHCPIAD09)                 */
/*        WCHMSG((CPIAD09))                                         */
/*        WCHMSGQ((*HSTLOG))                                        */
/*                                                                  */
/* ================================================================ */

     Pgm        Parm(&Type &Session &Error &Data)
     Dcl        Var(&Type)      Type(*Char) Len(10)
     Dcl        Var(&Session)   Type(*Char) Len(10)
     Dcl        Var(&Error)     Type(*Char) Len(10)
     Dcl        Var(&Data)      Type(*Char) Len(2000)

     Dcl        Var(&LenEvtDta) Type(*Int)  Len(4) +
                     Stg(*Defined) DefVar(&Data   1)
     Dcl        Var(&Job)       Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&Data 33)
     Dcl        Var(&User)      Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&Data 43)
     Dcl        Var(&Nbr )      Type(*Char) Len( 6) +
                     Stg(*Defined) DefVar(&Data 53)
     Dcl        Var(&MSGID)     Type(*Char) Len(7) +
                     Stg(*Defined) DefVar(&Data 5)
     Dcl        Var(&MsgF)      Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&Data 391)
     Dcl        Var(&MsgFLib)   Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&Data 401)
     Dcl        Var(&OffRplDta) Type(*Int)  Len(4) +
                     Stg(*Defined) DefVar(&Data 441)
     Dcl        Var(&LenRplDta) Type(*Int)  Len(4) +
                     Stg(*Defined) DefVar(&Data 445)
     Dcl        Var(&OrgLenRpl) Type(*Int)  Len(4) +
                     Stg(*Defined) DefVar(&Data 59)

     Dcl        Var(&MsgDtaPtr) Type(*Ptr)
     Dcl        Var(&MsgDta)    Type(*Char) Len(1010) +
                     Stg(*Based)   BasPtr(&MsgDtaPtr)

     /* CPIAD12 char data */
     Dcl        Var(&MsgUser  )    Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&MsgDta  1)
     Dcl        Var(&Host     ) Type(*Char) Len(255) +
                     Stg(*Defined) DefVar(&MsgDta 11)

     Dcl        Var(&MsgTxt )    Type(*Char) Len(1024)
     Dcl        Var(&Rtvm0100  ) Type(*Char) Len(1024)
     Dcl        Var(&RplDta )    Type(*Char) Len(1024)
     Dcl        Var(&MsgTxtLenC) Type(*Char) Len(4)
     Dcl        Var(&MsgTxtLen ) Type(*Dec ) Len(5 0)
     Dcl        Var(&RplDtaLenC) Type(*Char) Len(4)
     Dcl        Var(&ErrCode)    Type(*Char) Len(15) /* Error Code */

     Dcl        Var(&DQ)         Type(*Char) Len(1) VALUE('"')
     Dcl        Var(&CMD)        Type(*Char) Len(5000)
     Dcl        Var(&REDIR)      Type(*Char) Len(100)
     Dcl        Var(&MSGDTS)     Type(*Char) Len(8)
     Dcl        Var(&MSGYMD)     Type(*Char) Len(8)
     Dcl        Var(&MSGHMS)     Type(*Char) Len(6)

/* Check to make sure this is a *MSGID watch                         */
    If         Cond(&Type = '*MSGID') Then(Do)
/* Check to make sure this is for CPIAD09                            */

     If      Cond(&MsgID = 'CPIAD09') Then(Do)

             ChkObj     Obj(Qgpl/CnnLogP) ObjType(*File)
             MonMsg Cpf9801 *N Do
               CrtPf Qgpl/CnnLogP RcdLen(512)
             EndDo

             ChgVar Var(&MsgDtaPtr) Value(%Addr(&Data))
             Chgvar Var(%Offset(&MsgDtaPtr)) +
                    Value(%Offset(&MsgDtaPtr) + &OffRplDta)

             ChgVar Var(&RplDta)     Value(%sst(&MsgDta 1 &LenRplDta))

             ChgVar     Var(&Cmd) Value('print' *BCAT &DQ)

             ChgVar     Var(&ReDir) VALUE('>> /qsys.lib/' *CAT +
                          'QGPL'   *TCAT '.lib/' *CAT 'CNNLOGP' +
                          *TCAT '.file/' *CAT 'cnnlogp' *TCAT '.mbr')

             ChgVar     &MsgDts %SST(&RplDta 37 8)
             CvtDts     Dts(&MsgDts) RtnDate(&MsgYmd) RtnTime(&MsgHms)

             ChgVar     &CMD                                          +
                          (&CMD *TCAT &MsgId *TCAT %SST(&RplDta 1 36) +
                                *CAT  &MsgYmd *CAT &MsgHms            +
                                *CAT  %SST(&RplDta 45 275)            +
                                *TCAT  &Dq *BCAT &ReDir)

             StrQsh     Cmd(&CMD)
     EndDo

    EndDo /* End If &Type = *MSGID */

    ChgVar       Var(&Error) Value('          ')
    EndPgm


File  : QCLSRC

Member: WCHCPIAD12

Type  : CLP

Usage : CRTCLPGM QGPL/WCHCPIAD12

        執行 Command:
        STRWCH SSNID(WCHCPIAD12) WCHPGM(QGPL/WCHCPIAD12)          
        WCHMSG((CPIAD12))                                         
        WCHMSGQ((*JOBLOG))                                        
        WCHJOB((*ALL/*ALL/QZLSFILE))                              
OS    : V5R4

/* ================================================================ */
/*                                                                  */
/* Program    : WCHCPIAD12                                          */
/*                                                                  */
/* Description: Monitor QZLSFILE   job log msgid CPIAD12            */
/*              Log connect user, client ip, job information        */
/*              to file QGPL/CNNLOGP.                               */
/*                                                                  */
/* Date       : 2011/08/23                                          */
/*                                                                  */
/* Author     : Vengoal Chang                                       */
/* ================================================================ */
/*                                                                  */
/*                                                                  */
/* CRTCLPGM PGM(WCHCPIAD12)                                         */
/*                                                                  */
/*                                                                  */
/* QZLSFILE job only send CPIAD12 to job log.                       */
/*                                                                  */
/* STRWCH SSNID(WCHCPIAD12) WCHPGM(QGPL/WCHCPIAD12)                 */
/*        WCHMSG((CPIAD12))                                         */
/*        WCHMSGQ((*JOBLOG))                                        */
/*        WCHJOB((*ALL/*ALL/QZLSFILE))                              */
/*                                                                  */
/* ================================================================ */

     Pgm        Parm(&Type &Session &Error &Data)
     Dcl        Var(&Type)      Type(*Char) Len(10)
     Dcl        Var(&Session)   Type(*Char) Len(10)
     Dcl        Var(&Error)     Type(*Char) Len(10)
     Dcl        Var(&Data)      Type(*Char) Len(2000)

     Dcl        Var(&LenEvtDta) Type(*Int)  Len(4) +
                     Stg(*Defined) DefVar(&Data   1)
     Dcl        Var(&Job)       Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&Data 33)
     Dcl        Var(&User)      Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&Data 43)
     Dcl        Var(&Nbr )      Type(*Char) Len( 6) +
                     Stg(*Defined) DefVar(&Data 53)
     Dcl        Var(&MSGID)     Type(*Char) Len(7) +
                     Stg(*Defined) DefVar(&Data 5)
     Dcl        Var(&MsgDts)      Type(*Char) Len(8) +
                     Stg(*Defined) DefVar(&Data 379)
     Dcl        Var(&MsgF)      Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&Data 391)
     Dcl        Var(&MsgFLib)   Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&Data 401)
     Dcl        Var(&OffRplDta) Type(*Int)  Len(4) +
                     Stg(*Defined) DefVar(&Data 441)
     Dcl        Var(&LenRplDta) Type(*Int)  Len(4) +
                     Stg(*Defined) DefVar(&Data 445)
     Dcl        Var(&OrgLenRpl) Type(*Int)  Len(4) +
                     Stg(*Defined) DefVar(&Data 59)

     Dcl        Var(&MsgDtaPtr) Type(*Ptr)
     Dcl        Var(&MsgDta)    Type(*Char) Len(1010) +
                     Stg(*Based)   BasPtr(&MsgDtaPtr)

     /* CPIAD12 char data */
     Dcl        Var(&MsgUser  )    Type(*Char) Len(10) +
                     Stg(*Defined) DefVar(&MsgDta  1)
     Dcl        Var(&Host     ) Type(*Char) Len(255) +
                     Stg(*Defined) DefVar(&MsgDta 11)

     Dcl        Var(&MsgTxt )    Type(*Char) Len(1024)
     Dcl        Var(&Rtvm0100  ) Type(*Char) Len(1024)
     Dcl        Var(&RplDta )    Type(*Char) Len(1024)
     Dcl        VAR(&MsgTxtLenC) Type(*Char) Len(4)
     Dcl        VAR(&MsgTxtLen ) Type(*Dec ) Len(5 0)
     Dcl        VAR(&RplDtaLenC) Type(*Char) Len(4)
     Dcl        VAR(&ErrCode)    Type(*Char) Len(15) /* Error Code */

     Dcl        Var(&DQ)         Type(*Char) Len(1) VALUE('"')
     Dcl        Var(&CMD)        Type(*Char) Len(5000)
     Dcl        Var(&REDIR)      Type(*Char) Len(100)
     Dcl        Var(&MSGYMD)     Type(*Char) Len(8)
     Dcl        Var(&MSGHMS)     Type(*Char) Len(6)


/* Check to make sure this is a *MSGID watch                         */
    If         Cond(&Type = '*MSGID') Then(Do)
/* Check to make sure this is for CPIAD02                            */

     If      Cond(&MsgID = 'CPIAD12') Then(Do)

             ChkObj     Obj(Qgpl/CnnLogP) ObjType(*File)
             MonMsg Cpf9801 *N Do
               CrtPf Qgpl/CnnLogP RcdLen(512)
             EndDo

             ChgVar Var(&MsgDtaPtr) Value(%Addr(&Data))
             Chgvar Var(%Offset(&MsgDtaPtr)) +
                    Value(%Offset(&MsgDtaPtr) + &OffRplDta)

             ChgVar &RplDta       %sst(&MsgDta 1 &LenRplDta)

             ChgVar     %BIN(&MSGTXTLENC)        1024
         /*  ChgVar     %BIN(&RplDtaLenC)        1010 */
             ChgVar     %BIN(&RplDtaLenC)        &LenRplDta
             ChgVar     %BIN(&ErrCode     1  4)    15
             Call       QMHRTVM ( +
                                 &Rtvm0100               +
                                 &MsgTxtLenC             +
                                 'RTVM0100'              +
                                 'CPIAD12'               +
                                 'QCPFMSG   QSYS       ' +
                                 &RplDta                 +
                                 &RplDtaLenC             +
                                 '*YES      '            +
                                 '*NO       '            +
                                 &Errcode)

             ChgVar &MsgTxtLenC    %SST(&Rtvm0100  9 4)
             ChgVar &MsgTxtLen     %BIN(&MsgTxtLenC)
             ChgVar &MsgTxt (&MSGID *CAT ':' *BCAT               +
                             %SST(&Rtvm0100 25 &MsgTxtLen) *BCAT  +
                             'connected to job' *BCAT    +
                         &Nbr *CAT '/' *CAT &User *Tcat '/' *CAT &Job)
             SndPgmMsg  MsgId(CPF9898) Msgf(QCPFMSG) MsgDta(&MsgTxt) +
                          ToUsr(*SYSOPR)

             ChgVar     Var(&Cmd) Value('print' *BCAT &DQ)

             ChgVar     Var(&ReDir) VALUE('>> /qsys.lib/' *CAT +
                          'QGPL'   *TCAT '.lib/' *CAT 'CNNLOGP' +
                          *TCAT '.file/' *CAT 'cnnlogp' *TCAT '.mbr')

             ChgVar Var(&RplDta)     Value(%sst(&MsgDta 1 &LenRplDta))
             CvtDts Dts(&MsgDts) RtnDate(&MsgYmd) RtnTime(&MsgHms)

             ChgVar &MsgTxt (&MsgId *CAT &Job *CAT &User *CAT &Nbr +
                                    *CAT %SST(&RplDta 1 10)        +
                                    *CAT &MsgYmd *CAT &MsgHms      +
                                    *CAT 'QSERVER   QSYS      '    +
                                    *CAT %SST(&RplDta 11 255))

             ChgVar     &CMD                                          +
                          (&CMD *TCAT &MsgTxt                         +
                                *TCAT  &Dq *BCAT &ReDir)

             StrQsh     Cmd(&CMD)
     EndDo

    EndDo /* End If &Type = *MSGID */

    ChgVar       Var(&Error) Value('          ')
    EndPgm



沒有留言: