特殊な管理 > サイトメンテナンス > 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. 「Connect」をクリックします。
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. 作成した QueueEmailNotificationHandler MBean を JConsole で開き、次のように設定します。
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 パッケージからのメッセージをログに記録したときに電子メールを送信するように設定されました。ログメッセージでのログ内のパッケージの識別の手順に従ってキューを停止し、これをテストします。キューを停止したときに、ログメッセージを電子メールで受信できることを確認します。