PowerWire.eu

Independent IBM i, AIX and Linux news and tech tips for Europe and beyond

  • Home
  • News
  • Technical Articles
    • IBM i
    • AIX
    • Linux
    • VIOS
  • Subscribe
  • About Us
  • Contact Us
  • Advertise with PowerWire.eu

Ping unto eternity

June 4, 2019 by David Shears

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 🙂 )

Filed Under: IBM i, Technical Articles Tagged With: IBM i, IBM Power Systems

Comments

  1. Steve Bradshaw says

    June 5, 2019 at 2:15 pm

    Nice one Dave, very useful!

Free monthly newsletter signup

News

A screen a story – Not our problem anymore

Last week I ran into an issue, which did teach me something new about the command WRKPRB. After checking a … [Read More...]

Raspberry Pi and Machine Learning

In my last article, I demonstrated how I used Machine Learning on the Raspberry Pi to determine if a … [Read More...]

Shield Advanced Solutions – new Messaging and Monitoring solutions

September 2022 – Toronto As Shield Advanced Solutions celebrates the significant milestone, 25 years of … [Read More...]

More articles from this section

Quick Links

  • Advertise
  • Subscribe

Follow Us…

  • Email
  • LinkedIn
  • Twitter

Search This Website

Copyright © 2023 · Cue Communications · All Rights Reserved

Log in