---
title: "OpenNMS扩展 - 事件通知"
author: "diy8187"
date: "2011-04-24T20:28:00Z"
tags: []
slug: "opennms"
draft: false
lastmod: "2011-04-24T20:28:00Z"
id: 1055985
url: "https://diy8187.iteye.com/blog/1055985"
---

# OpenNMS扩展 - 事件通知

## 1. 概述（Overview）

OpenNMS事件产生后，通过相应的配置，通过通知告知事件。一般的通知方式主要用Email、页面，但通知的机制也存在如下情况：

l XMPP协议（Jabber ，一种即时通讯协议）

l 任意外部程序

l SNMP Trap

l 任意的HTTP GETs/POSTs

通知能够发送到用户、组及任何合法的Email地址。通知本身包含文字信息和主题，文字信息与主题可以根据特定的事件进行定制，比如可以定制节点的名字，IP地址，服务名，错误信息等等。

为了给相应的用户发送事件通知，用户需要设置一个合法的Email，针对admin用户，设置Email的步骤：以admin身份登录，进入菜单Admin -&gt;设置Notification Status为On，单击Update按钮-&gt; 进入Configure Users and Groups-&gt;Configure Users-&gt;单击Modify修改用户信息，填写用户合法Email地址，单击Finish保存完成设置。

## 2. 通知配置（Notification Configuration）

### 2.1 配置文件（Configuration File）

通知通过守护进程“notifd”进行处理。这个守护进程默认情况下通过destinationPaths.xml，notifd-configuration.xml与notifications.xml三个配置文件运行管理，而三个配置文件的内容可以通知Web UI来进修改设置。

#### 2.1.1 destinationPaths.xml

设定目标路径，指定谁得到任何通知和扩展（escalations）。

#### 2.1.2 notifd-configuration.xml

为通知守护进程配置全局属性，如：处理事件队列和自动发现（映射“下降”的事件与“向上”的事件，自动发现事件，承认（acknowledge）通知，无需执行更多的扩展）。

#### 2.1.3 notifications.xml

实际配置的通知。配置发送通知IP地址过滤规则，目标路径及主题与内容信息，如下表示一个结点down时的通知配置：

&lt;notification name="nodeDown" status="on"&gt;

&lt;uei&gt;uei.opennms.org/nodes/nodeDown&lt;/uei&gt;

&lt;rule&gt;IPADDR IPLIKE \*.\*.\*.\*&lt;/rule&gt;

&lt;destinationPath&gt;Email-Admin&lt;/destinationPath&gt;

&lt;text-message&gt;All services are down on node %nodelabel%. New Outage records have

been created and service level availability calculations will

be impacted until this outage is resolved.

&lt;/text-message&gt;

&lt;subject&gt;Notice #%noticeid%: node %nodelabel% down.&lt;/subject&gt;

&lt;numeric-message&gt;111-%noticeid%&lt;/numeric-message&gt;

&lt;/notification&gt;

#### 2.1.4 notificationCommands.xml

定义如何达成在destinationPaths.xml中所使用的各种配置通知方式. 如Email,Java Mail，页面， XMPP协议， SNMP陷阱等，Java的通知方式通常是首选，因为他们有更高的性能，更重要的低开销比调用一个外部程序。最通知方式实施这种方式。一个标准的接口存在， org.opennms.netmgt.notifd.notificationstrategy ，可以用来执行定制的Java通知方式。当然，通过命令行程序和shell脚本也是允许的。

,此文件包括了可执行文件的所在位置, 各种联络方式的别名(aliases), 以及特定传送方式尚需的其它信息等。

&lt;command binary="false"&gt;

&lt;name&gt;javaEmail&lt;/name&gt; &lt;execute&gt;org.opennms.netmgt.notifd.JavaMailNotificationStrategy&lt;/execute&gt;

&lt;comment&gt;class for sending email notifications&lt;/comment&gt;

&lt;argument streamed="false"&gt;

&lt;switch&gt;-subject&lt;/switch&gt;

&lt;/argument&gt;

&lt;argument streamed="false"&gt;

&lt;switch&gt;-email&lt;/switch&gt;

&lt;/argument&gt;

&lt;argument streamed="false"&gt;

&lt;switch&gt;-tm&lt;/switch&gt;

&lt;/argument&gt;

&lt;/command&gt;

### 2.2 Java Mail配置

OpenNMS中的Java Mail采用了Sun JavaMail API ，利用些API可以创建邮件用户代理，通过一个默认的帐户发送通知给客户，Java Mail的配置包含在$OPENNMS\_HOME/etc/javamail-configuration.properties文件中。

#### 2.2.1 javamail-configuration.properties.xml

###############################################################################

\#

\# This file is the configuration for the the JavaMailer class. It is used to

\# specify the details of the JavaMailer system properties

###############################################################################

\#

\#

\# Properties are defined but commented out indicating the default values.

\#

\#

\# This property defines system sender account.

\#

\# The default setting is root@\[127.0.0.1]

org.opennms.core.utils.fromAddress=support@suretech.com.hk

\#

\# This property defines SMTP Host.

\#

org.opennms.core.utils.mailHost=stmail.suretech.com

org.opennms.core.utils.mailer=smtpsend

org.opennms.core.utils.transport=smtp

org.opennms.core.utils.debug=true

\#

\# This property defines Mail authentication.

\# The default setting is false

org.opennms.core.utils.authenticate=true

org.opennms.core.utils.authenticateUser=jacky

org.opennms.core.utils.authenticatePassword=suretech

\# This property controls the use of the JMTA, the

\# default is true

org.opennms.core.utils.useJMTA=false

此配置系统采用用户jacky来发送Email.而用户收到的显示发送人为：[support@suretech.com.hk](mailto:support@suretech.com.hk)

为了保障信息安全，用户也可以在Linux下架设自己的Email Server，如SendMail,然后将进行相应的设置。

注：配置事件相关的XML文件后需重启OpenNMS。