Need queue size notification script

nobaloney

NoBaloney Internet Svcs - In Memoriam †
Joined
Jun 16, 2003
Messages
26,119
Location
California
Anyone have or care to write a program we can run periodically on our servers to monitor exim queue size?

Perhaps something like this:
Code:
 if output of 'exim bpc' > x then send email
or perhaps a bit more sophisticated:
Code:
if output of 'exim -bpc' > x then run 'exiqgrep -z -i | xargs exim -Mrm'
  if output of 'exim -bpc' > x then send an email
endif
Something like this would be helpful to a lot of us who often don't learn about email issues until our users tell us, or we notice we're not getting email ourselves.

Either donate one if you have it, or tell me how much you want to write it, and if it's reasonable and well done I'll buy it and offer it to the community.

Jeff
 

sysdev

Verified User
Joined
Jul 16, 2007
Messages
181
Something like this?

#!/bin/sh

NUM=`exim -bpc`
if [ $NUM -ne '0' ]; then
exiggrep -z -i | xargs exim -Mrm
NUM=`exim -bpc`
if [ $NUM -ne '0' ]; then
mail your@email 'bladiebla'
fi
fi
 

nobaloney

NoBaloney Internet Svcs - In Memoriam †
Joined
Jun 16, 2003
Messages
26,119
Location
California
Thanks! This is very close to what I'm thinking about.

I've decided I want the count before removing the frozen emails; in the specific case that prompted me to decide I needed this notification we had to grep through over a hundred thousand emails in a queue to delete only the ones from one lspammer, then thaw and retry all the remaining emails to send some which had been delayed on the queue for over a week., undelivered because server load had been over 10.

And I'd like to check only if the number is greater than a figure I can enter at the command line (possibly different for different servers). We're looking for server overloads which indicate a problem, not a few occasionally undeliverable emailsl which end up taking some time in the queue.

If you can help refine this, it would be very helpful. I don't need help with the mail line; I can write that myself.

Again, thanks. I think this is going to be very helpful for the DirectAdmin community.

Jeff
 

sysdev

Verified User
Joined
Jul 16, 2007
Messages
181
Hi Jeff,

I'm not sure what you exactly want. Our exim drops mails after 4d bij default.
Why not change the defaults to something more convenient?

exim.conf:
begin retry

* * F,2h,15m; G,16h,1h,1.5; F,4d,8h
 

nobaloney

NoBaloney Internet Svcs - In Memoriam †
Joined
Jun 16, 2003
Messages
26,119
Location
California
I'm sorry if I've confused the issue.

I want the frozen emails counted in the count. That's easy enough to implement; just one line to remove.

The other change I'd like is to not get emails each time there's anything in the queue, but only if the number of emails in the queue exceeds a certain amount.

For example, send me an email if the number in the queue exceeds X, where X is iput on the calling line.

I hope this is more clear.

Jeff
 

sysdev

Verified User
Joined
Jul 16, 2007
Messages
181
No problem, that would be something like:

#!/bin/sh

NUMFROZEN=`exiqgrep -zc| awk '{print $1}'`
THRESHOLD=$1
MSG="Frozen: $NUMFROZEN - Threshold: $THRESHOLD"
if [ "$NUMFROZEN" -gt "$THRESHOLD" ]
then
mail -s "Frozen mail threshold reached" your@email.hehe <<EOF
$MSG
EOF
# uncomment to delete frozen messages
# exiqgrep -z -i | xargs exim -Mrm
fi

run as: <scriptname> <number>

Edit: typo ;)
 
Last edited:

nobaloney

NoBaloney Internet Svcs - In Memoriam †
Joined
Jun 16, 2003
Messages
26,119
Location
California
Thanks, sysdev.

I don't really care about doing anything with frozen emails at this point. If I receive an email showing me that the queue is getting too big, I think it needs a human to look at it before making any decisions.

I think I can move on from here.

Again, Thanks!

Jeff
 

nobaloney

NoBaloney Internet Svcs - In Memoriam †
Joined
Jun 16, 2003
Messages
26,119
Location
California
This is what I finally came up with; it does what I want it to do. Note that it has to run as root. I've tested it, and it does work in my environment. In yours you may want a more complicated message, and possibly you may want to create a file to send, so the file will give you a better 'From' address and other headers which may help your email get delivered.
Code:
#!/bin/sh
MSG="Mail queue limit is over the threshold you set."
MAXNUM=`exim -bpc`
THRESHOLD=$1
if [ "$MAXNUM" -gt "$THRESHOLD" ]
then
mail -s "Mail que is over threshold" your@email.hehe <<EOF
$MSG
EOF
fi
Jeff
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,932
Location
GMT +7.00
Why don't you simply use munin or anything else similar to it?! It monitors exim queue and alerts as how you need it.
 

nobaloney

NoBaloney Internet Svcs - In Memoriam †
Joined
Jun 16, 2003
Messages
26,119
Location
California
Because this is easy to set up and install :).

And it tells me when the queue is getting too large, which for this client's managed server is all I need to know.

Jeff
 

Alfred

New member
Joined
Nov 10, 2010
Messages
4
Mail command not found

Thank you for the script.
I'm running DirectAdmin under Apache
The line
Code:
mail -s "Mail que is over threshold" your@email.hehe <<EOF
rises a "Command not found".
What do I have to do to have mail working from the script?
 

Alfred

New member
Joined
Nov 10, 2010
Messages
4
Thanks for answering.

I'm on Apache/2.2.27 on debian7_64
It does not know yum (Command unknown)

What would be the correct line then?
 
Top