Skip to content

Instantly share code, notes, and snippets.

@MikeWills
Created January 21, 2014 22:15
Show Gist options
  • Save MikeWills/8549554 to your computer and use it in GitHub Desktop.
Save MikeWills/8549554 to your computer and use it in GitHub Desktop.
A simple tool to monitor for MSGW on your IBM i

A simple MSGW alert tool

  1. Place the source in QGPL or your tool library of choice
  2. To call add a job schedule entry of SBMJOB CMD(CALL PGM(ALERT) PARM('MSGW')) JOB(MONMSGW) JOBQ(QINTER)
/* ********************************************************************** */
/* Program . . . . . ALERT */
/* */
/* Created on . . . 04/09/2010 */
/* by . . . Mike Wills (http://mikewills.me) */
/* */
/* Description . . . */
/* */
/* CHANGE LOG: */
/* Date | Name | Description */
/* ---------------------------------------------------------------------- */
/* | | */
/* | | */
/* | | */
/* ************************************************************************/
PGM PARM(&STS)
DCL VAR(&ERROR) TYPE(*CHAR) LEN(1)
DCL VAR(&STS) TYPE(*CHAR) LEN(4)
DCL VAR(&TXT) TYPE(*CHAR) LEN(60)
DCL VAR(&TIME) TYPE(*CHAR) LEN(6)
DCL VAR(&STOPTIME) TYPE(*CHAR) LEN(6) VALUE('200000')
ADDLIBLE LIB(MAILTOOL)
MONMSG MSGID(CPF0000)
START:
OVRPRTF FILE(QPDSPAJB) HOLD(*YES)
WRKACTJOB OUTPUT(*PRINT)
DLTOVR FILE(QPDSPAJB)
CHKOBJ OBJ(QTEMP/ALERTJOB) OBJTYPE(*FILE)
MONMSG MSGID(CPF9801) EXEC(DO)
CRTPF FILE(QTEMP/ALERTJOB) RCDLEN(132)
ENDDO
CPYSPLF FILE(QPDSPAJB) TOFILE(QTEMP/ALERTJOB) SPLNBR(*LAST)
DLTSPLF FILE(QPDSPAJB) SPLNBR(*LAST)
CALL PGM(QGPL/ALERTW) PARM(&STS &ERROR &TXT)
IF COND(&ERROR *EQ '1') THEN(DO)
MAILTOOL TOADDR('[email protected]') +
FROMADDR('[email protected]') +
SUBJECT(&TXT)
/*SNDDST TYPE(*LMSG) +
TOINTNET(([email protected])) +
DSTD('alert') LONGMSG(B) SUBJECT(&TXT) */
SNDBRKMSG MSG(&TXT) TOMSGQ(ISPA2S1 ISPA1S1)
/*GOTO CMDLBL(END) */
ENDDO
RTVSYSVAL SYSVAL(QTIME) RTNVAR(&TIME)
IF COND(&TIME *GE &STOPTIME) THEN(GOTO CMDLBL(END))
DLYJOB DLY(180)
GOTO CMDLBL(START)
END:
ENDPGM
/* ********************************************************************** */
/* Program . . . . . ALERTW */
/* */
/* Created on . . . 04/09/2010 */
/* by . . . Mike Wills (http://mikewills.me) */
/* */
/* Description . . . */
/* */
/* CHANGE LOG: */
/* Date | Name | Description */
/* ---------------------------------------------------------------------- */
/* | | */
/* | | */
/* | | */
/* ************************************************************************/
PGM PARM(&STS &ERROR &TXT)
DCL VAR(&STS) TYPE(*CHAR) LEN(4)
DCL VAR(&ERROR) TYPE(*CHAR) LEN(1)
DCL VAR(&TXT) TYPE(*CHAR) LEN(60)
DCLF FILE(QTEMP/ALERTJOB)
CHGVAR VAR(&ERROR) VALUE('0')
READ:
RCVF RCDFMT(ALERTJOB)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END))
IF COND(%SST(&ALERTJOB 116 4) *EQ &STS) THEN(DO)
CHGVAR VAR(&ERROR) VALUE('1')
CHGVAR VAR(&TXT) VALUE(&STS *CAT ' status : ' *CAT +
%SST(&ALERTJOB 29 6) *CAT '/' *CAT +
%SST(&ALERTJOB 17 10) *TCAT '/' *CAT +
%SST(&ALERTJOB 4 10) *TCAT '!!!')
ENDDO
GOTO READ
END:
ENDPGM
@Kurt-Anderson
Copy link

Great tool, thanks.
As a note, to compile ALERTW you'll need to do so interactively, for example calling CRTBNDCL directly, since it is expecting to find the file in QTEMP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment