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?
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With