To have a mail in tabular format

Hello Guys,
developing a monitoring shell script to have my queue depth count over mail .

here is the sample input file to the script which has all the queue names [ e.g QL.GVR.ATA.CACHE.01) and corresponding queue depth in the next line (e.g 4).

 1 : DISPLAY QUEUE(*) WHERE (CURDEPTH GT 0)
ZFC8409: Display Queue details.
   QUEUE(QL.GVR.ATA.CACHE.01)              TYPE(QLOCAL)
   CURDEPTH(4)                          
ZFC8409: Display Queue details.
   QUEUE(QL.GVR.LSF.CACHE.01)              TYPE(QLOCAL)
   CURDEPTH(4)                          
ZFC8409: Display Queue details.
   QUEUE(QL.GVR.PBS.CACHE.01)              TYPE(QLOCAL)
   CURDEPTH(4)                          
ZFC8409: Display Queue details.
   QUEUE(QL.GVR.STMFLIST.CACHE.01)         TYPE(QLOCAL)
   CURDEPTH(4)                          
ZFC8409: Display Queue details.
   QUEUE(QL.FAILED.EMAIL.MIME)             TYPE(QLOCAL)
   CURDEPTH(1)                          
ZFC8409: Display Queue details.
   QUEUE(QL.PGHR.SWIFT.ERR.LOG)             TYPE(QLOCAL)
   CURDEPTH(4)                          
ZFC8409: Display Queue details.
   QUEUE(QL.PGHR.AUDIT.INMSG)              TYPE(QLOCAL)
   CURDEPTH(2)                          
ZFC8409: Display Queue details.
   QUEUE(QL.PGHR.GVR.ERR.LOG)              TYPE(QLOCAL)
   CURDEPTH(298)                        
ZFC8409: Display Queue details.
   QUEUE(QL.PGHR.EMAIL.FAIL)               TYPE(QLOCAL)
   CURDEPTH(124)                        
ZFC8409: Display Queue details.
   QUEUE(QL.PGHR.ERR.LOG)                  TYPE(QLOCAL)

expected output is ...

QL.GVR.ATA.CACHE.01  4
QL.GVR.LSF.CACHE.01   4

Currently by grep and awk command iam able to get the depth stats but in very scattered format .

Welcome to the forum.

Try this:

awk -F"[()]" 'NR<=2 {next}/QUEUE/ {NM = $2} /CURDEPTH/ {print NM, $2}' OFS="\t" file
QL.GVR.ATA.CACHE.01	4
QL.GVR.LSF.CACHE.01	4
QL.GVR.PBS.CACHE.01	4
QL.GVR.STMFLIST.CACHE.01	4
QL.FAILED.EMAIL.MIME	1
QL.PGHR.SWIFT.ERR.LOG	4
QL.PGHR.AUDIT.INMSG	2
QL.PGHR.GVR.ERR.LOG	298
QL.PGHR.EMAIL.FAIL	124
1 Like

Do it with the one command that commands them all: sed . (Short for: Saurons editor ;-)) )

Here it is. The sed-program is separated into its own file for readability, you can move it to the commandline as well. Remove the comments, sed won't undertand them):

sed -nf /path/to/sedscript /path/to/your/inputfile
/^ *QUEUE(/ {                # all lines starting with "QUEUE("
     s/^ *QUEUE(//                # remove the string "^QUEUE(" from the beginning of the line
     s/^\([^)]*\)).*/\1/          # keep everything up to the first ")" and throw away the rest
     N                            # load the next line, containing the depth
     s/CURDEPTH(\([0-9]*\))/\1/   # replace "CURDEPTH(nnn)" with "nnn"
     s/\n/\t/                     # substitute the newline between queue name and depth by a tab
     p                            # and print the result
}

Replace the tab character (line #6) by anything else if you want a different output format.

I hope this helps.

bakunin

1 Like

Thanks Rudie , let me try and get back to you on the same if any problem.

Hi bakunin,
Thanks for your sed code, code gives the almost correct response .
two conditions have to add in your code

  1. queues to be ignore if it QL.FAILED ****
    e.g
ZFC8409: Display Queue details.
   QUEUE(QL.FAILED.EMAIL.MIME)  

2.couple of queues are extra check means if for those queue count is more than 300 then only it should appear in the output.
for example QL.PHGR limit needs to be validated by hardcode number defined somewhere in the script .if it crosesss the limit then only it should appear in the final output.

e.g

 QUEUE(QL.PGHR.GVR.ERR.LOG)              TYPE(QLOCAL)
   CURDEPTH(298)

Hope iam not making it so complicated .

Sorry if this sounds a bit over-zealous, but: no. It gives a completely correct answer to an almost correctly stated problem. It is always a good idea to state the problem as clearly as possible and as complete as possible. If you start to say "i want a brick there" and then "and another brick there" you might end up eventually with a wall, but knowing you are after a wall in the end "use concrete" might have been a viable suggestion in first place.

OK, this is easy:

/^ *QUEUE(/ {
     s/^ *QUEUE(//
     s/^\([^)]*\)).*/\1/
     N
     s/CURDEPTH(\([0-9]*\))/\1/
     s/\n/\t/
     /QT.FAILED/ ! p     # only print if line does not contain QT.FAILED
}

Now we have exactly this situation: knowing this condition makes sed a poorly suited tool for the problem. In fact it is possible to do arithmetic, integer comparisons and whatnot in sed (after all, it is a Turing-complete language), but it is, in fact too, very complicated to do so. Furthermore it is plainly ugly and - see the provided addition program in the link - not for the faint of heart. It is fun to stretch the limits of what can be done but in a professional environment you wouldn't want a colleague who churns out such monstrosities as seriously-meant solutions. It is great to be able to do double-somersaults but they are not a seriously suggestible means of getting from A to B.

I suggest going with RudiC's awk -script and add the additional conditions there.

There is another problem with your requirements:

OK, and: which ones?? Will this just be a fixed list, will they come from a file with queue names, is there some pattern (like the "any queue named QT.SOMETHING* is to be...") or anything else? Again: you want specific answers, please ask specific questions. Everything else is indeed wasting everybodies time. I have no problem at all spending time to come up with solutions and explain whatever needs to be explained but i hate going over the same problem in little variations again and again only to find out after the umpteenth iteration that what i did up to now was nonsense because i should have started on a completely different track.

I hope this helps.

bakunin

2 Likes

Thanks Rudie for the AWK code , as Bukinin suggested to have awk for validation , any advise from you on top of your provided code.

Instead of asking us to keep up with your changing requirements, why don't you take the code RudiC suggested and try modifying it to meet your added requirements? We are here to help you learn how to write your own code; not to act as your unpaid programming staff for constantly changing requirements.

If you can't figure out what his code is doing after reading the awk man page on your system, ask us to explain what the code that you don't understand is doing. We want to help you learn how to write your own awk scripts.

Show us how you tried to modify it and tell us where you have problems if you can't get it to work.

If you do get it to work, show us what you came up with. Maybe we'll be able to show you shortcuts that will make your code work faster or more reliably. Again... we want to help you learn how to write your own code. (And, please use CODE tags when displaying sample input, sample output, and code segments.)

2 Likes

Hello bukinin,

reply to your questions : yes it fixed list three or 4 fixed queue names with specified limit . if it crosses the limit then only should pop out the result and trigger mail else should not consider in the output.
for example for QL.PGHR.GVR.ERR.LOG 298 this queue limit is 300 so should not appear in mail/output.

Hello wims,

pls. read, understand, and apply Don Cragun's post #8. Feel free to post here again for help if you get stuck. If so, provide (broad, and detailed) enough information to enable people in here to understand and work upon your problem.

Half baked answers (like yours in post #9) usually DON'T help. Where does the list come from - a file? An array? Divine revelation? How formatted? In other words - show data!

Hello wums,

My suggestion is to - for reasons of extensibility and maintainability - not to include it into the code directly but to create a file with queue names and their threshholds, like this:

QL.QUEUE1     50
QL.QUEUE2     75
QL.QUEUE3     100

At the start of your program you read in this file line by line and create an associative array of integers with the queue names as index and the threshhold values as values. When a line with a queue name is to be printed you first consult this array and if the queue name is in there you compare the queues length with the threshhold value and decide upon this if it is to ve included in the report or not.

Decisions you will have to make still are: what will happen if a queue is not included in this list. You have several options i could think of: a queue not included in the list is considered to have a threshhold of 0. This resembles what we started with. Another possibility is to ignore every queue not included in the list (so that in fact their "threshhold value is infinite". This way the list in your file would contain an extensive list of the queues you are interested in. Another possibility is to declare a general threshhold so that queues only get reported when they are crossing this threshhold. ONly the queues in the list will have their own differing threshhold value set according to this list. This is quite similar to the first possibility but there you'd have a general threshhold of zero.

I hope this helps.

bakunin