专业化管理 > 站点维护 > 使用 Java Management Extensions (JMX) > 为方法服务器日志消息配置 JMX 电子邮件通知
  
为方法服务器日志消息配置 JMX 电子邮件通知
Windchill 可配置为当出现方法服务器日志条目时自动发送电子邮件。可为任何 log4j 消息配置这些通知。
以下示例显示了使用 Windchill JMX Emailer Mbean 配置通知的方法。
通过日志中的日志消息标识类或软件包
在方法服务器日志中找到消息,然后标识发送该消息的类或软件包。此例中,队列处于停止状态以便将消息强制设置为日志。
1. 以站点管理员的身份登录 Windchill,然后转至“站点” > “实用程序” > “队列管理”
2. 选择任意队列将其停止。本例中,停止 commonProcessQueue
3. 打开方法服务器日志,找到通知队列已停止的消息。标识作为消息源的类。本例中,该类为 wt.jmx.notif.queue。以下是示例日志条目:
2013-11-26 10:34:27,276 WARN [QueueCheckerThread-27] wt.jmx.notif.queue - Time=2013-11-26 16:34:27.272 +0000, Name=QueueNotifier, SourceObjectName=com.ptc:wt.subsystem=Monitors,wt.monitorType=Queues,Name=commonProcessQueue, class=class javax.management.Notification, type=wt.queue.QueueWatcherMBean.queueStopped, userData=commonProcessQueue, message=Queue commonProcessQueue has been stopped, JVM Name=4389@bla-ce6-utf1063, Queue Info=[WaitingReadyEntries=0,ExecutionThreadLoggerName=,TotalThreshold=100,MinEntryExecTimeSeconds=0.0,AveEntryExecTimeSeconds=0.0,MinMinutesBetweenNotifications=60,EntryExecutionTimeThresholdSec=900,TotalEntries=0,LoggerLevel=,WaitingReadyThreshold=15,TotalExecutionTime=0,LoggerName=wt.queue.QueueWatcherImpl.commonProcessQueue,MaxEntryExecTimeSeconds=0.0,Name=commonProcessQueue,ExecutionThreadLoggerLevel=,TotalEntriesExecuted=0]
配置 log4j
配置 log4j 附件器和相应的记录器 (要为其发送电子邮件的各类或软件包的记录器)。
1. 将附件器和记录器添加到 log4jMethodServer.properties 文件。以下代码示例显示了要为 wt.jmx.notif.queue 添加的附件器和记录器。
# Create a new appender that sends messages to a JMX MBean
log4j.appender.QueueEmailAppender=wt.log4j.jmx.JMXAppender
# Configure the class wt.jmx.notif.queue to use the
# QueueEmailAppender. The comma is important. It separates the
# (unspecified) level from the appender.
log4j.logger.wt.jmx.notif.queue=,QueueEmailAppender
# You may also want to specify a level threshold, so that log
# messages below the threshold are not emailed. ERROR would be a
# typical threshold, but in this case WARN has been selected for
# the demonstration.
log4j.appender.wt.jmx.notif.queue.threshold=WARN
2. 重新启动方法服务器,并强制其重新读取 log4jMethodServer.properties 文件。
配置通知处理程序 Mbean
1. 启动 JConsole。有关详细信息,请参阅 JConsole 中的“JConsole 入门”一节。
2. Local Process 下,选择 wt.method.MethodServerMain
3. 单击“连接”
4. MBeans 选项卡上,导航至 com.ptc > Logging > Appenders,然后验证 QueueEmailAppender 是否存在。如果不存在,则必须先进行创建才能继续操作。
5. MBeans 选项卡上,导航至 com.ptc > NotificationHandlers > Operations > addNotificationHandler,然后创建新的通知处理程序。
a. handlerName 字段中,输入要为处理程序指定的名称。本例中使用 QueueEmailNotificationHandler
b. targetMBeanObjectName 字段中,输入 log4j 附件器的名称。本例中使用 com.ptc:wt.subsystem=Logging,log4jType=Appenders,name=QueueEmailAppender
c. 单击 addNotificationHandler
6. 打开刚在 JConsole 中创建的 QueueEmailNotificationHandler MBean,然后对其配置如下:
a. 设置 EmailSubject 属性。
b. EmailRecipientListName 属性设置为 QueueEmailList
创建电子邮件列表
1. 导航至 com.ptc > Emailer MBean 并使用 Operations > addEmailList 来创建名为 QueueEmailList 的电子邮件列表。
2. 导航至 com.ptc > Emailer MBean,然后选择 EmailLists。通过将电子邮件地址添加到 AddressList 属性来配置 QueueEmailList。
进行测试
方法服务器现已配置为记录来自 wt.jmx.notif.queue 软件包的消息时向用户发送电子邮件。您可以通过停止队列进行测试,具体如通过日志中的日志消息标识包中所述。停止队列后,您应在电子邮件中接收到该日志消息。