Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monit check program returns "no output"

Tags:

monit

I want to try to monitor postfix queue with monit. I have taken a example from people of Stackoverflow. My version of monit is the latest

This is Monit version 5.10

In /etc/monit.d I have postfixlocal with

check program postfixcola with path "/usr/local/bin/postfixcola.sh"
    #if status != 0 then alert
    if status > 1 then alert

and then in /usr/local/bin/ I have postfixcola.sh with

#!/bin/sh
QUEUE=`/usr/sbin/postqueue -p | tail -n1 | awk '{print $5}'`
exit $QUEUE

But Monit complaints every time about the output of the script. I have made a test, setting and echo before exit and in the moment of test it returned a 1 (because the queue of postfix was 1)

But the error remains: [CET Dec 9 11:10:07] error : 'postfixcola' '/usr/local/bin/postfixcola.sh' failed with exit status (2) -- no output

I really don't know what is the problem here, any thoughts?

like image 797
Rubendob Avatar asked Dec 09 '14 10:12

Rubendob


1 Answers

In your bash script you should echo a message into /dev/stderr:

#!/bin/bash
QUEUE=`/usr/sbin/postqueue -p | tail -n1 | awk '{print $5}'`
if [ $QUEUE -ne 0 ] ; then
   echo "Queue length > $QUEUE" > /dev/stderr
fi
exit $QUEUE
like image 53
Alain Beauvois Avatar answered Sep 27 '22 20:09

Alain Beauvois