Work with Watches - V5R4
I was looking for an API to run that would read thru
The QHST file and send me a message when…
Lets say….. When this message appears.
Then I found this article somewhere in webland about
Starting Watchs.
First you have to have special authority of *SERVICE in profile
Of userid starting the watch. It also looks like by default
(at least on my system) you have *PUBLIC exclude on the
API QSCSWCH (start watch) and the command(s) WRKWCH and ENDWCH.
I recommend you give yourself authority prior to running the example program.
Use the command WRKWCH to see your job running. You can use
Strsrvjob to debug the program if you wanna mess with it.
I added an email out to send to the help desk blackberry, could
Have been a distribution group in exchange for all of IT…whatever.
Program can be modified to monitor any messages within QHST
Or changed to QSYSOPR… blah blah blah
Just thought it was kinda cool and haven’t heard of it till today.
@WATCHSTR
And the actual exit program for the watch
I was looking for an API to run that would read thru
The QHST file and send me a message when…
Lets say….. When this message appears.
Serious storage condition may exist. Press HELP. CPF0907
Starting Watchs.
First you have to have special authority of *SERVICE in profile
Of userid starting the watch. It also looks like by default
(at least on my system) you have *PUBLIC exclude on the
API QSCSWCH (start watch) and the command(s) WRKWCH and ENDWCH.
I recommend you give yourself authority prior to running the example program.
Use the command WRKWCH to see your job running. You can use
Strsrvjob to debug the program if you wanna mess with it.
I added an email out to send to the help desk blackberry, could
Have been a distribution group in exchange for all of IT…whatever.
Program can be modified to monitor any messages within QHST
Or changed to QSYSOPR… blah blah blah
Just thought it was kinda cool and haven’t heard of it till today.
@WATCHSTR
Code:
D***************************************************************** DQSCWFMF DS D* Qsc Watch For Msg Fmt D QSCLMI 1 4B 0 D* Length Message Informati D QSCMID 5 11 D* Message ID D QSCERVED 12 12 D* Reserved D QSCMQN02 13 22 D* Message Queue Name D QSCMQL 23 32 D* Message Queue Lib D QSCJN 33 42 D* Job Name D QSCUN 43 52 D* User Name D QSCJNBR 53 58 D* Job Number D QSCRSV2 59 64 D* Reserved2 D QSCOCD 65 68B 0 D* Offset Comparison Data D QSCLOCD 69 72B 0 D* Length Of Comparison Dat D QSCCA 73 82 D* Compare Against D*QSCCD 83 83 D* D* variable length data D QUSEC DS D ErrBytesProv 10I 0 Inz(%size(QUSEC)) D ErrBytesAvail 10I 0 Inz D ErrMsgID 7A D 1 D ErrMsgDta 512A dWatchPgm ds d Pgm 10 inz('@WATCH') d Lib 10 inz('JAMIELIB') dMessages ds qualified d NbrMsgs 10i 0 d MsgFormat likeds(QSCWFMF) dLICs ds qualified d NbrLICs 10i 0 d StartWatch pr extpgm('QSCSWCH') d SessionID 10 const d StrSsnID 10 d WatchPgm 20 const d Messages 65535 const options(*varsize) d LICs 65535 const options(*varsize) d QUSEC likeds(QUSEC) * * program varibles * dStrSsnID s 10 /free ErrBytesProv = 0; // Watch for CPF1124 in the QHST message queue Messages.NbrMsgs = 1; Messages.MsgFormat = *loval; Messages.MsgFormat.QSCLMI = %size(Messages.MsgFormat); Messages.MsgFormat.QSCMID = 'CPF1124'; Messages.MsgFormat.QSCMQN02 = '*HSTLOG'; Messages.MsgFormat.QSCJN = *blanks; Messages.MsgFormat.QSCUN = *blanks; Messages.MsgFormat.QSCJNBR = *blanks; Messages.MsgFormat.QSCCA = *blanks; // No LIC logs are being watched for LICs.NbrLICs = 0; StartWatch('HISTWATCH' :StrSsnID :WatchPgm :Messages :LICs :QUSEC); *inlr = *on; return; /end-free
Code:
D***************************************************************** D*Watch Exit Program called because a message id and any D*associated comparison data is matched. D*This structure is for the user exit program called by D*STRWCH cmd or Start Watch (QSCSWCH) API D***************************************************************** DESCQWFM DS D ESCLWI 1 4B 0 D* Length Watch Information D ESCMID00 5 11 D* Message ID D ESCERVED01 12 12 D* Reserved D ESCMQN 13 22 D* Message Queue Name D ESCMQL 23 32 D* Message Queue Lib D ESCJN 33 42 D* Job Name D ESCUN 43 52 D* User Name D ESCJNBR 53 58 D* Job Number D ESCRSV2 59 62 D* Reserved2 D ESCSPGMN 63 318 D* Sending Program Name D ESCSPGMM 319 328 D* Sending Program Module D ESCOSP 329 332B 0 D* Offset Sending Procedure D ESCLOSP 333 336B 0 D* Length Of Sending Proced D ESCRPGMN 337 346 D* Receiving Program Name D ESCRPGMM 347 356 D* Receiving Program Module D ESCORP 357 360B 0 D* Offset Receiving Procedu D ESCLORP 361 364B 0 D* Length Of Receiving Proc D ESCMS 365 368B 0 D* Msg Severity D ESCMT 369 378 D* Msg Type D ESCMT00 379 386 D* Msg Timestamp D ESCMK 387 390 D* Msg Key D ESCMFILN 391 400 D* Msg File Name D ESCMFILL 401 410 D* Msg File Library D ESCRSV3 411 412 D* Reserved3 D ESCOCD01 413 416B 0 D* Offset Comparison Data D ESCLOCD01 417 420B 0 D* Length Of Comparison Dat D ESCCA 421 430 D* Compare Against D ESCRSV4 431 432 D* Reserved4 D ESCCCSID 433 436B 0 D* Comparison Data CCSID D ESCOCDF 437 440B 0 D* Offset Comparison Data F D ESCORD 441 444B 0 D* Offset Replacement Data D ESCLORD 445 448B 0 D* Length Of Replacement Da D ESCCCSID00 449 452B 0 D* Replacement Data CCSID D*ESCSP 453 453 D* D* variable length data @B2M D*ESCRP 454 454 D* D* variable length data @B2M D*ESCCD01 455 455 D* D* variable length data @B2M D*ESCRD 456 456 D* D* variable length data @B2M *----------------------------------------------------------------- d @WATCH pr d Type 10 const d Session 10 const d Error 10 d Data likeds(ESCQWFM) * d@WATCH pi d Type 10 const d Session 10 const d Error 10 d Data likeds(ESCQWFM) *----------------------------------------------------------------- d MsgDtaPtr s * d MsgDta ds 75 based(MsgDtaPtr) d File 1 10 d Lib 11 20 *----------------------------------------------------------------- * program status dataarea *----------------------------------------------------------------- d PgmSts SDS d P1User 254 263 d @PGM *PROC d @JOB 244 253 *--------------------------------------------------------------* * work fields * *--------------------------------------------------------------* d Variables ds d Q 1 inz( '''' ) * d qcmdexc pr extpgm( 'QCMDEXC' ) d os400_cmd 2000A options( *varsize ) const d cmdlength 15P 5 const * * variables * d emailaddress s 50 inz('helpdesk@somewhere.com') d OS400_Cmd s 2000 inz d wait s 1 * /free Error = *blanks; // assume all is well until shown otherwise // Check to make sure this is a *MSGID watch if (Type = '*MSGID'); // select CPF to monitor testing with job started..message to qhst if (Data.ESCMID00 = 'CPF1124'); // Get to the message replacement data MsgDtaPtr = %addr(Data) + Data.ESCORD; // Send email to address os400_cmd = 'snddst type(*lmsg) ' + 'tointnet((' + Q + %trim(EmailAddress) + Q + ')) dstd(' + Q + 'Hey Its me ' + ' ' + %char(%time()) + Q + ') longmsg(' + Q + 'Job in Message wait: ' + Q + ')'; qcmdexc ( os400_cmd : %size ( os400_cmd ) ); endif; endif; *inlr = *on; /end-free
Comment