You could also combine these so that you'll only get back the inquiry messages for jobs that are still sitting in MSGW.
SELECT MESSAGE_ID, MESSAGE_TEXT, MESSAGE_TIMESTAMP, FROM_JOB
FROM TABLE ( QSYS2.MESSAGE_QUEUE_INFO(MESSAGE_FILTER => 'INQUIRY') )
JOIN TABLE (
SELECT JOB_NAME
FROM TABLE ( QSYS2.ACTIVE_JOB_INFO() )
WHERE JOB_STATUS IN ('MSGW') )
ON JOB_NAME = FROM_JOB;
You could even incorporate QSYS2.QCMDEXC() and dynamically build SNDSMTPEMM commands so that executing the SQL itself will generate the alerts. So many cool ways to accomplish things like this nowadays!
------------------------------
Steven Riedmueller
Certified IBM i Admin
Speaker, Mentor, and Advocate
------------------------------
Original Message:
Sent: Fri October 27, 2023 07:17 AM
From: ace ace
Subject: Checking all systems for MSGW
Nice feature to have.
But rarely is a thing to check "synchronously" or willingly.... so I just let my monitoring system to hit the partition with a query like
SELECT JOB_NAME FROM TABLE(QSYS2.ACTIVE_JOB_INFO()) WHERE JOB_STATUS IN ('MSGW')
and alert the interested parties.
To check messages (but they can have a running job or not, maybe the job with the exception ended... so I just prefer to directly check for job_status) one can use something like
SELECT MESSAGE_ID, MESSAGE_TEXT, MESSAGE_TIMESTAMP
FROM TABLE(QSYS2.MESSAGE_QUEUE_INFO(MESSAGE_FILTER => 'INQUIRY'));
------------------------------
--ft
------------------------------