I had looked at the tokens field but did not look to be easier.
I ended up doing this to get the IP address out of the message_text field
,TRIM(SUBSTR(Message_Text,(LOCATE_IN_STRING(Message_Text, 'client', 1)+7), -- start of IP
(LOCATE_IN_STRING(Message_Text, ' connected', 1) -
(LOCATE_IN_STRING(Message_Text, 'client ', 1)+7) -- end of IP address
))) AS IP_addr
seems to work on several different servers we have. Returns the IP address or host name (if a local connection)
------------------------------
Bryan Dietz
------------------------------
Original Message:
Sent: Tue November 07, 2023 09:26 AM
From: Robert Berendt
Subject: Auditting IPs accessing IBMi via port 446
Bryan,
The IP address would be easier to find if you search MESSAGE_TOKENS instead of MESSAGE_TEXT as it would be in a fixed position in tokens. (as would YOUR_USER). Then again, this may only apply if you're looking for a single message id, or two with identical tokens. Adding the CASE would probably work...
Clean this up and you're in
select trim(substring(message_tokens, 75, 15)) as IP_address, x.*
FROM TABLE (QSYS2.HISTORY_LOG_INFO(START_TIME => CURRENT DATE - 2 days
)) AS X
Where message_id='CPI3E34'
and from_job_name like 'QRWT%'
ORDER BY ORDINAL_POSITION desc;
------------------------------
Robert Berendt IBMChampion
Original Message:
Sent: Tue November 07, 2023 09:13 AM
From: Bryan Dietz
Subject: Auditting IPs accessing IBMi via port 446
thanks Rob,
to carry this one more step I use the following to find DRDA and ODBC like connections.
-- category: bryandietz
-- description: history log-find user from QZDASOINIT-QRWTSRVR
SELECT Message_Timestamp
,From_User
,From_Job
,Message_Id
,MESSAGE_TEXT
FROM TABLE(Qsys2.History_Log_Info(
Start_Time => current_timestamp - 1 day, -- pick your time frame
End_Time => current_timestamp
)) i
WHERE Message_Id in ('CPIAD09','CPI3E34')
-- AND MESSAGE_TEXT LIKE '%YOUR_USER%' -- if needing to "audit" for a single user
;
at one point, I sub stringed(or maybe LOCATE_in_STRING) out the IP address, but I cannot locate the example
------------------------------
Bryan Dietz
Original Message:
Sent: Tue November 07, 2023 08:55 AM
From: Robert Berendt
Subject: Auditting IPs accessing IBMi via port 446
That's a good catch Bryan. Based on that, this is another way of capturing that.
select *
FROM TABLE (QSYS2.HISTORY_LOG_INFO(START_TIME => CURRENT DATE - 2 days
)) AS X
Where message_id='CPI3E34'
and from_job_name like 'QRWT%'
ORDER BY ORDINAL_POSITION desc;
------------------------------
Robert Berendt IBMChampion
Original Message:
Sent: Tue November 07, 2023 08:34 AM
From: Bryan Dietz
Subject: Auditting IPs accessing IBMi via port 446
Port 446 is the DRDA port, QRWTLSTN is the job that is listening on that port, so a couple of ways I can think of:
1) exit program
2) look thru history log : DSPLOG msgid(CPI3E34) job(QRWT*)
------------------------------
Bryan Dietz
Original Message:
Sent: Mon November 06, 2023 12:16 AM
From: Thomas Varkey
Subject: Auditting IPs accessing IBMi via port 446
Hello team,
Is there any way to generate an audit report of IPs accessing IBMi via port 446. Your views would be appreciated.
Thank you
------------------------------
Thomas Varkey
------------------------------