1. Enable email alert in monit
By default, if you don't define a notify statement, monit will not send alert messsages. There are two forms of alert statement:
-Global: enable alert to all services.
-Local: enable alert for individual service.
Recipients in global and local lists are notified when service failed, recovered or changed. If you define both global and local recipients, the local recipient will override.
To set a global alert message, in global section using the "set" keyword
set alert recipient@domain.fooWhen this statement is defined, all services being monitored will send messages to address recipient@domain.foo when something goes wrong.
To locally set alert function for each service
check file test_alert with path "/home/cuong/testfile"
alert abc@localhost
if failed permission 0777 then alert
2. Configurations for email notifications
2.1. Define mail server
Mail server is defined in global section using "set" keyword:
2.2. Alert message layoutSET MAILSERVER [hostname/ip] [port]
monit provides a default layout for notification message, you can define of your own style. An example of standard layout
set mail-format {
from: monit@$HOST
subject: monit alert -- $EVENT $SERVICE
message: $EVENT Service $SERVICE
Date: $DATE
Action: $ACTION
Host: $HOST
Description: $DESCRIPTION
monit by cuongnv at $DATE
}
Result:
From: monit@Deb6
To: cuong@localhost
Subject: monit alert -- Connection failed exim4
Date: Sat, 20 Apr 2013 14:25:12 GMT
X-Mailer: monit 5.5
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Connection failed Service exim4
Date: Sat, 20 Apr 2013 21:25:12
Action: restart
Host: Deb6
Description: failed protocol test [SMTP] at INET[localhost:25] via TCP -- SMTP: error receiving data -- Resource temporarily unavailable
monit by cuongnv at Sat, 20 Apr 2013 21:25:12