基于RHQ配置邮件预警(Email Alert)
写在前面
关于Rhq的安装,请参考《RHQ简介与安装》,之前安装演示中对应的版本为rhq3.0,现在配置邮件预警使用的版本为RHQ4.2,不过安装过程大同小异,还是具有参考价值的。
实现原理
Rhq发送预警邮件的实现原理是通过调用其内置jboss服务器的mail服务来完成的。Rhq安装过程中会要求用户填写smtp服务器地址、smtp服务器端口以及账户信息。但是对于某些需要授权信息的邮件服务器来说,这还是不够的,还需要修改其内置服务器中关于mail服务的相关配置。
mail服务的配置文件是%RHQ_Hom%e\jbossas\server\default\deploy下的mail-service.xml文件
修改前的实例:
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: mail-service.xml 62349 2007-04-15 16:48:15Z dimitris@jboss.org $ -->
<server> <!-- RHQ Server Mail Connection Factory --> <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail"> <attribute name="JNDIName">java:/Mail</attribute> <attribute name="User">nobody</attribute> <attribute name="Password">password</attribute> <attribute name="Configuration"> <!-- A test configuration --> <configuration> <!-- Change to your mail server prototocol --> <property name="mail.store.protocol" value="pop3"/> <property name="mail.transport.protocol" value="smtp"/> <!-- Change to the user who will receive mail --> <property name="mail.user" value="nobody"/> <!-- Change to the mail server --> <property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/> <!-- Change to the SMTP gateway server --> <property name="mail.smtp.host" value="${rhq.server.email.smtp-host:127.0.0.1}"/> <!-- The mail server port --> <property name="mail.smtp.port" value="${rhq.server.email.smtp-port:25}"/> <!-- Change to the address mail will be from --> <property name="mail.from" value="${rhq.server.email.from-address:rhqadmin@127.0.0.1}"/> <!-- Enable debugging output from the javamail classes --> <property name="mail.debug" value="false"/> </configuration> </attribute> <depends>jboss:service=Naming</depends> </mbean></server>
<?xml version="1.0" encoding="UTF-8"?><!-- $Id: mail-service.xml 62349 2007-04-15 16:48:15Z dimitris@jboss.org $ --><server> <!-- RHQ Server Mail Connection Factory --> <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail"> <attribute name="JNDIName">java:/Mail</attribute> <attribute name="User">jombowang@gmail.com</attribute> <attribute name="Password">****<!--修改为你的密码--></attribute> <attribute name="Configuration"> <!-- A test configuration --> <configuration> <property name="mail.smtp.auth" value="true"/><!--这里很关键,对于需要授权的属性,需要增加此配置--> <!-- Change to your mail server prototocol --> <property name="mail.store.protocol" value="pop3"/> <property name="mail.transport.protocol" value="smtp"/> <!-- Change to the user who will receive mail --> <property name="mail.user" value="nobody"/> <!-- Change to the mail server --> <property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/> <!-- Change to the SMTP gateway server --> <property name="mail.smtp.host" value="${rhq.server.email.smtp-host:127.0.0.1}"/> <!-- The mail server port --> <property name="mail.smtp.port" value="${rhq.server.email.smtp-port:25}"/> <!-- Change to the address mail will be from --> <property name="mail.from" value="${rhq.server.email.from-address:rhqadmin@127.0.0.1}"/> <!-- Enable debugging output from the javamail classes --> <property name="mail.debug" value="false"/> </configuration> </attribute> <depends>jboss:service=Naming</depends> </mbean></server>