2

I currently have two monit checks for each host I have running HTTPS:

check host www-example-https with address www.example.org
  if failed
    port 443
    protocol https
  then alert

check host www-example-certificate with address www.example.org
  every "25 10 * * *"
  if failed
    port 443
    protocol https
    and certificate valid > 30 days
  then alert

The first one warns me of a failure to connect at all, and runs every 2 minutes, whereas the second reminds me that a certificate has fewer that 30 days until expiry and only runs once a day.

At the moment both checks result in a similar alert message, which means that a certificate nearing expiry looks like a complete failure of HTTPS. I'd therefore like to override the default mail options on a per-alert basis.

I know I can do this with set mail-format if I want to change all alerts, but I can't figure out the syntax for a single alert if I'm using an if failed ... then alert block, and I can't find any examples of this specific use case in the manual.

Is it possible to override mail-format on a per-alert basis for the types of alerts I've defined above?

pwaring
  • 209
  • 2
  • 7
  • Did you look at this topic http://stackoverflow.com/questions/33666707/does-monit-support-multiple-email-recipients-with-the-same-format – DevOps Jan 17 '17 at 18:13
  • I hadn't seen that topic - possibly because the problem it is trying to solve is different (I want to override the subject, rather than email multiple users). It also doesn't use an `if failed ... then alert` block. – pwaring Jan 17 '17 at 21:46

1 Answers1

1

There is a sample in the documentation here https://mmonit.com/monit/documentation/#CONFIGURATION-EXAMPLES

From personnal test, you cannot avoid the "alert a@b.c" part, so to resume, to fit your needs, it leads to:

check host www-example-https with address www.example.org
  if failed
    port 443
    protocol https
  then alert
  alert me@example.com with mail-format {     # use local format
     subject: https is down on www.example.org
     message: https is down on www.example.org with port 443
  Yours sincerely,
  monit
  }


check host www-example-certificate with address www.example.org
  every "25 10 * * *"
  if failed
    port 443
    protocol https
    and certificate valid > 30 days
  then alert
  alert metwo@exmaple.com with mail-format  {     # use local format
     subject: https certificate expiration for www.example.org
     message: https is certificate is less than 30 days  on www.example.org with port 443
  $SERVICE $EVENT at $DATE
  Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
  Yours Pal,
  MoMoMonit
  }

Also it seems that if host is "failed", the certificate check will not be performed.

Using a "set mail-format" anywhere, change it for ALL notifications

DevOps
  • 720
  • 3
  • 15
  • Thanks, I've been testing that for a few weeks and it seems to work as I want. It's slightly annoying that I have to repeat the email address as I like to specify that once at the top of the file, but I think I can work round that by turning the configuration into a Jinja template. – pwaring Feb 27 '17 at 11:28
  • The link is now https://mmonit.com/monit/documentation/monit.html#Message-format – Roland Pihlakas Apr 15 '22 at 16:59