外部ログのカスタムログ取得ストラテジー
概要
ThingWorx Platform では、さまざまなサードパーティのログアプリケーションを介したログのオブザーバビリティがサポートされています。これらのアプリケーションでは、複数の方法でログをプッシュおよび取得できます。カスタムログ取得ストラテジーを使用して、サードパーティのログアプリケーションからのログを表示できます。OpenTelemetry がログをこれらのアプリケーションにプッシュし、ThingWorx Platform がそれらのログを取得して表示します。これらのログは、「Composer」 > 「監視」 > 「ログ」で確認できます。
ThingWorx Platform では、次の機能が提供されています。
DefaultLogRetrievalStrategyThing - コンフィギュレーションに基づいて、ThingWorx ファイルログまたは Sumo Logic からログを取得します。
* 
DefaultLogRetrievalStrategyThing はシステムオブジェクトです。そのコンフィギュレーションを更新することはできますが、カスタムログ取得ストラテジーのテンプレートとして使用することはできません。
Extension SDK - カスタムログ取得ストラテジーを開発できるようにします。
RetrieveLogs サービス
ログの取得は、DefaultLogRetrievalStrategyThing に含まれる RetrieveLogs サービスで処理します。
ログの取得は、以下の設定によって決定されます。
ファイルログが無効で (DisableFileLoggingtrue)、OpenTelemetry が有効な場合 (EnableOpenTelemetryForLoggingtrue)、ログは Sumo Logic から取得されます。
その他の場合はすべて、ログは ThingWorx ファイルログから取得されます。
RetrieveLogs サービスは、次のいずれかの方法で実装できます。
JavaScript サービスを使用して Composer から取得
a. LogRetrievalStrategy ベーステンプレートを使用して、Composer で Thing を作成します。
b. 「サービス」をクリックし、RetriveLogs サービスをオーバーライドします。
c. JavaScript コードを入力して、外部ログプロバイダアプリケーションからログを取得します。
コンテンツローダーまたは同様の機能を使用して、サードパーティのシステムと通信します。
Extension SDK を使用して拡張機能を作成することにより取得
a. Eclipse で最新の SDK バージョンを使用して拡張機能を作成します。
b. LogRetrievalStrategy ベーステンプレートで Thing Template (Java クラス) を作成します。
クラスは LogRetrievalStrategy クラスを拡張する必要があります。
c. ログ取得 Java メソッドをオーバーライドし、外部ログプロバイダアプリケーションからログを取得するためのカスタムコードを実装します。
d. 拡張機能の metadata.xml ファイルを更新して Thing を作成できます。または、拡張機能をインポートした後で Composer で Thing を作成することもできます。
e. 拡張機能を構築し、ThingWorx Composer にインポートします。
どちらの場合でも、Thing を作成した後に、それをログサブシステムLogRetrievalStrategy Thing として設定します。
必要条件
始める前に、次のことを確認してください。
ThingWorx Platform 拡張機能の構築方法について理解している。
LogRetrievalStrategy Thing Template が含まれている Extension SDK バージョン 9.6.0 以降がインストールされている。
拡張機能を構築して ThingWorx Platform にインポートする方法について理解している。
カスタムログ取得ストラテジーの実装
Java でカスタムログ取得ストラテジーを作成するには、次の手順を実行します。
1. ストラテジー 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. 拡張機能をパッケージ化して構築します。詳細については、パス B: 拡張機能としてのソリューションのパッケージ化と展開を参照してください。
5. 拡張機能を ThingWorx Composer にインポートします。
6. CustomLogRetrievalStrategy Thing Template から Thing を作成します。
7. 「LoggingSubsystem」 > 「コンフィギュレーション」をクリックします。
8. 「ログ取得ストラテジー」として手順 6 で作成した Thing を選択します。
9. 「Composer」 > 「監視」 > 「ApplicationLog」に移動し、ログが外部ソースから取得されたものであるかどうかを確認します。
関連トピック
これは役に立ちましたか?