Using SQL for QSYSOPR Messages and Replies #IBMi

I'm always monitoring remote IBM i systems. I use SQL for the bulk of that monitoring because between #SQLTools and the IBM Services I can get just about anything I need. Whether that's using ACS Run SQL Scripts or, from the Green Screen, using SQL iQuery, monitoring remote IBM i partitions or systems has never been easier.

One thing I do a lot of is look at QSYSOPR message queue. I have an early morning Scheduled Job that emails a list of any jobs sitting in MSGW (Message Wait) status so that the day's work can being when User begin arriving to work or signing on remotely. But I also periodically check the active jobs. If I see one that has an unusual task or is in MSGW, I'll do a quick query of the QSYSOPR message.

But using just the standard IBM Service MESSAGE_QUEUE_INFO table function is well, kind of verbose. So I like to pair it down a bit. My preference is to see the message type, severity, message text and the from name. To do that I simply include the column names in the SELECT statement.

?SELECT M.message_type
???????? M.severity AS SEV,
???????? CAST(M.MESSAGE_TIMESTAMP AS TIMESTAMP(0)) AS POSTED,
???????? FROM_PROGRAM,
???????? M.MESSAGE_TEXT
????? FROM TABLE (
?????????????? qsys2.MESSAGE_QUEUE_INFO()
?????????? ) M;,        

I've been using this for a while. I created a source file member named QSYSOPR with this routine in it, and then using SQL iQuery I would just run it as follows:

RUNiQRY SRCMBR(QSYSOPR)        

The RUNiQRY command default to SRCFILE(*LIBL/QSQLSRC) so just using the SRCMBR parameter usually works the way you need it to. Also, remember, last month I made SQL iQuery a no-charge licensed program. Anyone can download and install it for free. We only charge for support if you request support so there really isn't anything stopping you for getting a copy onto your system any longer.

After using this SELECT statement for a while I was seeing a new location being installed that had a number of MSGW showing up. So I thought, "wouldn't it be great to see the message reply as well as just the message?"

So I solved this requirement by simply coding an outer join to the MESAGE_QUEUE_INFO function itself. I did a bit a inside-baseball research and found that the Message Key of the message and the associated Message Key for Replies is included in the resultSet. So I join them and used that to connect the two independent messages.

It looks like this:


? SELECT M.message_type
???????? M.severity AS SEV,
???????? CAST(M2.MESSAGE_TIMESTAMP AS TIMESTAMP(0)) AS REPLY_TIME,
???????? CASE
???????????? WHEN M.MESSAGE_TYPE = 'INQUIRY'
???????????????? AND M2.MESSAGE_TEXT IS NULL THEN '*WAITING'
???????????? ELSE M2.message_text
???????? END AS REPLY,
???????? CAST(M.MESSAGE_TIMESTAMP AS TIMESTAMP(0)) AS POSTED,
???????? M.FROM_PROGRAM,
???????? M.MESSAGE_TEXT
????? FROM TABLE (
?????????????? qsys2.MESSAGE_QUEUE_INFO()
?????????? ) M
?????????? LEFT OUTER JOIN (
?????????????????? SELECT M1.message_type,
????????????????????????? M1.severity AS SEV,
????????????????????????? M1.message_text,
????????????????????????? M1.ASSOCIATED_MESSAGE_KEY,
????????????????????????? MESSAGE_TIMESTAMP
?????????????????????? FROM TABLE (
?????????????????????????????? qsys2.MESSAGE_QUEUE_INFO()
?????????????????????????? ) M1
?????????????????????? WHERE M1.ASSOCIATED_MESSAGE_KEY IS NOT NULL
?????????????? ) M2
?????????????? ON M2.ASSOCIATED_MESSAGE_KEY = M.MESSAGE_KEY
????? WHERE M.ASSOCIATED_MESSAGE_KEY IS NULL
?? ORDER BY m.message_timestamp DESC;        

I thought this was awesome, except that it is a bit verbose. Storing it in a source member solved that issue when using iQuery, but while I'm in ASC RUN SQL Scripts I don't have the ability to run iQuery Scripts (we asked IBM if they'd open up ACS Run SQL Scripts to allow it t run iQuery Scripts as well; they told us to go pound sand) so I decided to create a VIEW instead.

Creating a view for this SELECT statement is painlessly easy:

create or repalce VIEW SQLTOOLS.QSYSOPR AS
( <include the above SQL statment (without the ;) here.
);        

In fact, we are now shipping this VIEW with SQL Tools but you can just as easily enter it into your own system using cut/paste.

The benefit of the VIEW is not just brevity. If you put this view on all your systems (hence, including it in SQL Tools) I can not only use SQL iQuery to run it, but I can just type a short SELECT * FROM CHICAGO.SQLTOOLS.QSYSOPR in ACS RUN SQL Scripts or even STRSQL and get the results you need.

That's all there is to it.

要查看或添加评论,请登录

Bob Cozzi的更多文章

  • Using my READSPLF SQL Function

    Using my READSPLF SQL Function

    A SQL Table Function to Directly Read IBM i Spooled Files Managing spooled files on IBM i has always been a critical…

    7 条评论
  • Example SQL iQuery Script for IBM i

    Example SQL iQuery Script for IBM i

    Since releasing SQL iQuery for the IBM i operating system, my customers have primarily been using a very cool feature…

    3 条评论
  • Reading Source File Members Using SQL

    Reading Source File Members Using SQL

    With the introduction of my SQL Tools product several years ago, I created a number of "READ" SQL functions that…

    1 条评论
  • IBM i SQL Function Adoption Rate

    IBM i SQL Function Adoption Rate

    IBM i Developers have long relied on various interfaces and tools to navigate system functions, but many remain unaware…

    3 条评论
  • SQL iQuery for Web Config Directives

    SQL iQuery for Web Config Directives

    Last time I showed how to use the no-charge SQL iQuery for Web product to create a simple File Inquiry web app for the…

    1 条评论
  • HTML/Browser Apps for IBM i

    HTML/Browser Apps for IBM i

    There have been myriad methods for creating HTML browser enabled applications that use IBM i database files. For the…

    12 条评论
  • SQL iQuery is Free (tell your friends)

    SQL iQuery is Free (tell your friends)

    Challenges of Pricing Software in the IBM i Ecosystem In the dynamic arena of technology services and software support…

    9 条评论
  • IBM i SQL UDTF: SYSINFO

    IBM i SQL UDTF: SYSINFO

    I had a post about a simple SQL Function I created that gives me everything I need to know about the physical Power…

  • Reading Stuff using SQL for IBM i

    Reading Stuff using SQL for IBM i

    My SQL Tools licensed program (product) has 4 so called read functions. These functions allow users to retrieve data…

    1 条评论
  • Add it Up in RPG

    Add it Up in RPG

    One of the features that has been re-introduced to RPG over the decades is the myriad methods to perform an ADD…

    17 条评论

社区洞察

其他会员也浏览了