$MONIT_DESCRIPTION displays as such without error log

Issue #168 closed
Former user created an issue

HI Monit, We have a monit task to alert if the port 5000 fails with error from application log file as shown below. Is it a bug ? if not what i am doing wrong here. please update the script to correct me.. Its urgent please help me on this

set mail-format {message: Description: $MONIT_DESCRIPTION}

check host localhost with address 127.0.0.1 if failed port 5000 for 2 cycles then exec "/bin/bash -c '(awk -vw=\"TypeError\" \'{s=s$0}END{ m=split(s,str,w); print w str[m]}\' /var/log/app/app.log"

But we get email with message without error details and the message displays as "$MONIT_DESCRIPTION"

Also tried in another way like below but not able to get the log error in email

(1) check host localhost with address 127.0.0.1 if failed port 5000 for 2 cycles then exec "/etc/monit/error.sh"

error.sh

#!/bin/bash awk -vw="TypeError" '{s=s$0}END{ m=split(s,str,w); print w str[m]}' /var/log/app/app.log

(2) check host localhost with address 127.0.0.1 if failed port 5000 for 2 cycles then exec "bin/bash -c '(awk -vw=\"TypeError\" \'{s=s$0}END{ m=split(s,str,w); print w str[m]}\' /var/log/locutus/web.log) | mail -s top mail@host.com"

Comments (4)

  1. muthukumar murugesan

    Okay i also tried for the following with default email format without over writting with $MONIT_DESCRIPTION but i am not getting email with proper error log description. what should i edit in the following script to get the error log in email then. Could you please help me on this..

    check host localhost with address 127.0.0.1 if failed port 5000 for 2 cycles then exec "/bin/bash -c '(awk -vw=\"TypeError\" \'{s=s$0}END{ m=split(s,str,w); print w str[m]}\' /var/log/app/app.log"

  2. Tildeslash repo owner

    As mentioned by Christian, the correct token for mail-format statement is $DESCRIPTION, not $MONIT_DESCRIPTION.

    In addition setting mail format to: "set mail-format {message: Description: $DESCRIPTION}" has no effect at all, as it is equal to default settings.

    As you're using exec action and sending alert via "mail" command-line utility, the Monit alert channel is not used at all (Monit only executes your script) => the problem is in the script itself ... as it is quite complex, it is better to move it to standalone file as you did with "if failed port 5000 for 2 cycles then exec '/etc/monit/error.sh'". You should extend the script to log errors.

    It is also possible that the mailserver just rejects to deliver the mail sent by "mail" utility (for example due to sender address) ... check mailserver logs in such case.

  3. Log in to comment