Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Monit support multiple email recipients with the same format?

Tags:

monit

I use monit to monitor the status of a service,when the service is down, I want to send alert email to multiple recipients with the same format. here is part of my monit configuration:

set mail-format { from: [email protected] }
check host hostA with address hostA
  alert [email protected]
  MAIL-FORMAT {     # use local format
     subject: redis is down on hostA
     message:   redis is down on hostA on port 6379

  Yours sincerely,
  monit
  }
  alert [email protected]
  MAIL-FORMAT {     # use local format
     subject: redis is down on hostA
     message:   redis is down on hostA on port 6379

  Yours sincerely,
  monit
  }
  if failed port 6379 retry 3 then exec "/monit/scripts/myscripts.sh"

it works but have some redundant things (e.g. the same MAIL-FORMAT for 2 users) . there will be multiple email formats I will use in the same configuration file. Dose monit support multiple recipients with the same and only one local email format?

like image 609
fudy Avatar asked Sep 06 '25 03:09

fudy


1 Answers

From the official documentation:

If you want to send alert messages to more email addresses, add a set alert 'email' statement for each address.

Following this, the following configuration should work:

set mail-format { from: [email protected] }
check host hostA with address hostA
  alert [email protected]
  alert [email protected]
  MAIL-FORMAT {     # use local format
     subject: redis is down on hostA
     message:   redis is down on hostA on port 6379

  Yours sincerely,
  monit
  }

Regards

EDIT:

The documentation does not state it, but the position of the elements might play a role here. Try to define the alert addresses AFTER the mail-format declaration. Also, note you use two mail-format declaration in your code - If this is not necessary, try to use only one (the latter).

set mail-format {
      from: [email protected]
  reply-to: [email protected]
   subject: $SERVICE $EVENT at $DATE
   message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
            Yours sincerely,
            monit
 }
 alert [email protected]
 alert [email protected]
like image 136
Eduardo López Avatar answered Sep 08 '25 00:09

Eduardo López