Composer での ThingWorx モデルの定義 > システム > ログ > ThingWorx Platform ログ用 OpenTelemetry > 外部ソースからログを照会するためのカスタムログ取得ストラテジー
外部ソースからログを照会するためのカスタムログ取得ストラテジー
ログは、市場に流通している各種サードパーティのエンタープライズログプロバイダアプリケーションを介して確認できます。これらのアプリケーションでは複数の方法によってログをプッシュおよび取得できます。
OpenTelemetry では、ログはログプロバイダアプリケーションにプッシュされます。
このログ取得ストラテジーの主な目的は、サードパーティのソースからログを取得し、これらのログを「Composer」 > 「監視」 > 「ログ」ページに表示することです。
全体的な実装の一環として、ThingWorx は以下を提供しています。
コンフィギュレーションに応じて ThingWorx ファイルログと Sumo Logic からログを取得するデフォルトのストラテジー Thing DefaultLogRetrievalStrategyThing
カスタムログ取得ストラテジーを開発するための Extension SDK。
DefaultLogRetrievalStrategyThing はシステムオブジェクトです。そのコンフィギュレーションのみを更新できます。ユーザーがカスタムログ取得ストラテジーを実装するためにこの DefaultLogRetrievalStrategyThing テンプレートを使用することは想定されていません。
ログの取得は DefaultLogRetrievalStrategyThing で使用可能な RetrieveLogs サービスによって処理されます。ログの取得は以下に基づいています。
ファイルログが無効であり (DisableFileLoggingtrue に設定されている)、OpenTelemetry が有効である (EnableOpenTelemetryForLoggingtrue に設定されている) 場合にのみ、Sumo Logic からログが取得されます。
その他すべての場合、ログはファイルから取得されます。
ログ取得用のカスタム実装の場合、RetrieveLogs サービスは次の 2 つの方法で実装できます。
Composer で JavaScript サービスを使用
a. Composer で、ベーステンプレートとして LogRetrievalStrategy を使用して Thing を作成します。
b. 「サービス」に移動し、RetriveLogs サービスをオーバーライドします。
c. サードパーティのログソフトウェアからログを取得するための JavaScript コードを指定します。
* 
通常は、コンテンツローダー関数または同様の関数を使用してサードパーティとの通信が行われます。
ThingWorx で Extension SDK を使用して拡張機能を作成
a. Eclipse で最新の SDK (9.6.0 以上) を使用して拡張機能を作成します。
b. ベーステンプレートとして LogRetrievalStrategy を使用して Thing Template (Java クラス) を作成します。
クラスはログ取得ストラテジークラスを拡張する必要があります。
c. ログ取得 java メソッドをオーバーライドし、サードパーティのログソフトウェアからログを取得するためのカスタムコードを実装します。
d. (オプション) 拡張機能の metadata.xml を更新し、Thing を作成します。拡張機能をインポートした後で Composer で Thing を作成することもできます。
e. 拡張機能を構築し、ThingWorx にインポートします。
どちらの場合も、Thing が作成された後、ログサブシステムでこの Thing を LogRetrievalStrategy Thing として設定する必要があります。
このチュートリアルでは、ThingWorx 拡張機能の作成の基本については説明していません。以下を前提としています。
ThingWorx 拡張機能の構築方法について理解している。
LogRetrievalStrategy Thing Template が含まれている Extension SDK v.9.6.0 以降がインストールされている。
拡張機能を構築して ThingWorx Platform にインポートする方法について理解している。
カスタムログ取得ストラテジーの実装
1. Java でカスタムログ取得ストラテジーを作成するには、ストラテジー Thing Template を作成します。この Thing Template は Java ベースのアルゴリズムのコードベースとして機能します。Thing Template のクラス定義は以下のとおりです。
@ThingworxBaseTemplateDefinition(name = "LogRetrievalStrategy")
public class CustomLogRetrievalStrategy extends LogRetrievalStrategy{
2. RetrieveLogs メソッドを実装してオーバーライドします。
@ThingworxServiceDefinition(
name = LoggingConstants.RETRIEVE_LOGS_STRATEGY_SERVICE_NAME,
isAllowOverride = true,
description = "Retrieve Logs from the given source",
category = "Queries")
@ThingworxServiceResult(name = "result", description = "Table entries", baseType = "INFOTABLE", aspects = { "dataShape:LogEntry" })
@Override
public InfoTable RetrieveLogs(
@ThingworxServiceParameter(
name = LoggingConstants.MAX_ITEMS,
description = "Maximum number of items to return",
baseType = "NUMBER",
aspects = { "defaultValue:" + RESTAPIConstants.DEFAULT_ITEM_COUNT }) Double maxItems,
@ThingworxServiceParameter(
name = LoggingConstants.START_DATE,
description = "Start time",
baseType = "DATETIME") DateTime startDate,
@ThingworxServiceParameter(
name = LoggingConstants.END_DATE,
description = "End time",
baseType = "DATETIME") DateTime endDate,
@ThingworxServiceParameter(
name = LoggingConstants.FROM_LOG_LEVEL,
description = "From log level",
baseType = "STRING") String fromLogLevel,
@ThingworxServiceParameter(
name = LoggingConstants.TO_LOG_LEVEL,
description = "To log level",
baseType = "STRING") String toLogLevel,
@ThingworxServiceParameter(
name = LoggingConstants.USER,
description = "Log messages for a specific user",
baseType = "USERNAME") String user,
@ThingworxServiceParameter(
name = LoggingConstants.THREAD,
description = "Log messages for a specific thread",
baseType = "STRING") String thread,
@ThingworxServiceParameter(
name = LoggingConstants.PLATFORM_ID,
description = "Log message from a specific instance",
baseType = "STRING") String platformId,
@ThingworxServiceParameter(
name = LoggingConstants.ORIGIN,
description = "Specific class or log source",
baseType = "STRING") String origin,
@ThingworxServiceParameter(
name = LoggingConstants.INSTANCE,
description = "Specific class or log source",
baseType = "STRING") String instance,
@ThingworxServiceParameter(
name = LoggingConstants.SEARCH_EXPRESSION,
description = "Keywords to search content",
baseType = "STRING") String searchExpression,
@ThingworxServiceParameter(
name = LoggingConstants.SORT_FIELD_NAME,
description = "Sort field name",
baseType = "STRING") String sortFieldName,
@ThingworxServiceParameter(
name = LoggingConstants.ASCENDING_SEARCH,
description = "Ascending search indicator (true = ascending, false = descending)",
baseType = "BOOLEAN") Boolean ascendingSearch,
@ThingworxServiceParameter(
name = LoggingConstants.OLDEST_FIRST,
description = "Search/sort from oldest to newest",
baseType = "BOOLEAN") Boolean oldestFirst,
@ThingworxServiceParameter(
name = LoggingConstants.IS_REGEX,
description = "The Search expression should be treated as REGEX",
baseType = "BOOLEAN",
aspects = { "defaultValue:" + false }) Boolean isRegex,
@ThingworxServiceParameter(
name = "logName",
description = "Keywords to search content",
baseType = "STRING",
aspects = { Aspects.ASPECT_ISREQUIRED + ":true", Aspects.ASPECT_SELECTOPTIONS +
":ApplicationLog:ApplicationLog|CommunicationLog:CommunicationLog|" +
"ConfigurationLog:ConfigurationLog|ScriptLog:ScriptLog|SecurityLog:SecurityLog" }) String logName)
throws Exception {

// Create InfoTable to hold results
InfoTable logEntriesTable = new InfoTable();

// Add Field Definitions to InfoTable.
logEntriesTable.addField(new FieldDefinition(LoggingConstants.CONTENT, BaseTypes.STRING));
logEntriesTable.addField(new FieldDefinition(LoggingConstants.USER, BaseTypes.STRING));
logEntriesTable.addField(new FieldDefinition(LoggingConstants.THREAD, BaseTypes.STRING));
logEntriesTable.addField(new FieldDefinition(LoggingConstants.PLATFORM_ID, BaseTypes.STRING));
logEntriesTable.addField(new FieldDefinition(LoggingConstants.ORIGIN, BaseTypes.STRING));
logEntriesTable.addField(new FieldDefinition(LoggingConstants.INSTANCE, BaseTypes.STRING));

// TODO: Custom Log Retrieval Strategy implementation here. Add each log entry as row to logEntriesTable

return logEntriesTable;
3. 拡張機能の metadata.xml ファイルにストラテジー Thing を作成します。
<Things>
<Thing
enabled="true"
name="CustomLogRetrievalStrategyThing"
published="true"
thingTemplate="CustomLogRetrievalStrategy">
</Thing>
</Things>
4. 拡張機能をパッケージ化して構築します。
5. ThingWorx Composer を介して拡張機能をインポートします。
6. ThingTemplate CustomLogRetrievalStrategy から Thing を作成します。
7. 「LoggingSubsystem」 > 「コンフィギュレーション」ページに移動します。
8. 「ログ取得ストラテジー」として、手順 6 で作成した Thing を選択します。
9. 「Composer」 > 「監視」 > 「アプリケーションログ」に移動し、ログが外部ソースから取得されたものであるかどうかを確認します。
これは役に立ちましたか?