Informing the IBM Community

Ping unto eternity

0
(0)

A slightly pretentious title for an article that doesn’t deserve it, but you must indulge yourself every so often.

If you’ve ever used the PING command from a windows command line I imagine you’re familiar with the -t option that will leave it running until you have the information you want. I found myself needing to run a ping test from the IBMi to a device and was interested to note there doesn’t seem to be an inbuilt way to do this (answers in the comments if I’ve missed it.) The NBRPKT keyword seems to stop you at a maximum of 999, which is fine unless you’re trying to capture an occasional dropout that could happen at any time of day.

Being a coder with time on my hands I decided this wasn’t on, if the windows community can have it then so can we, and the solution was to write my own wrapper around the command.

A nice simple CL to begin with: accept an address input and write a loop, SBMJOB and you can look at the joblog to monitor for dropouts. Something like the below (heavily simplified from the eventual program.)

PGM        PARM(&P#IP)

DCL        VAR(&P#IP)  TYPE(*CHAR) LEN(15)

DCL        VAR(&DLYSEC)  TYPE(*CHAR) LEN(3) value(‘010’)

TOPLOOP:

PING       RMTSYS(&P#IP)

DLYJOB     DLY(&DLYSEC)   

GOTO       CMDLBL(TOPLOOP)

ENDPGM

Now that’s all well and good if you’re fine scrolling up/down the joblog to find your dropouts. But what if you want a nice simple summary somewhere? Well you can RCVMSG to pull back the message data and return the percentage of packets:

DCL        VAR(&MSGDATA) TYPE(*CHAR) LEN(12)        

DCL        VAR(&PCT_GOOD) TYPE(*INT) STG(*DEFINED) +

             LEN(4) DEFVAR(&MSGDATA 9)              

DCL        VAR(&PCT_RTRN) TYPE(*DEC) LEN(3 0)       

PING RMTSYS(&P#IP)

RCVMSG     MSGTYPE(*LAST) RMV(*NO) MSGDTA(&MSGDATA)

             MSGID(&MSGID)                         

CHGVAR     VAR(&PCT_RTRN) VALUE(&PCT_GOOD)         

IF         COND((&MSGID = TCP3210) *AND (&PCT_GOOD < 100) ) THEN(DO)    

Now you have a percentage that you can output somewhere, for my purposes I’ve got a little table with the address, percentage, and date/time of record.

You can also do more advanced things if you want, for example in my finished program I also pass in a mode to determine whether I’m checking for device being online/offline (change the PCT_GOOD check to be > 0.) I’ve also got some error handling and checking for the job ENDSTS to pad out a bit and make the job more robust in day to day usage.

RMTSYS obviously allows a much larger parameter than I have so if you wanted to ping by hostname you could expand that, you could also pass in more of the parameters for the PING command if you wanted more customization.

I imagine most of you if you need this functionality have already written your own, probably far more advanced than this one. Why not give some suggestions in the comments as to what other features/functions people might use it for? (I always like having things I can improve on 🙂 )

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.


Comments

One response to “Ping unto eternity”

  1. Nice one Dave, very useful!