カスタム パターンを作成する

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

カスタム パターンを作成するには Discovery/pattern フォルダーに移動します。ここで、末尾が.pat の新しいファイル (UTF-8) を作成するか、または必要なパターンタイプの既存のパターンをコピーして変更を加えることができます。新しいパターンを開発およびテストするためのベスト プラクティスは、別途 Discover-Tool インスタンスを抽出し、処理したい結果データを返すホストまたはデバイスへの接続を設定することです。

次に、「メイン」の HostInfo パターンを除くすべてのパターンを削除します(Linux_Hostinfo_Hostname.pat、Windows_Hostinfo_Hostname_Model.pat、SNMP_Deviceinfo_Default.pat)。Hostname が含まれている「メイン」の HostInfo オブジェクトは必ず必要です。このセットアップでは、他のすべてのパターンの応答を待たずに、新しいパターンを高速テストできます。

新しいパターンに、必要なすべての XML ノード、つまり Discovery-Object に対するコマンドの結果データを処理する C# クラスを含む <Processing>-Node が必ず含まれるようにしてください。この機能では、Discovery-Tool が <Processing>-Node を含む C# ソース コードを読み取り、PatternExec-Class の PerformAction-Method を呼び出します。

PerformAction Method は必須です。Discovery-Tool は次の 4 オブジェクトを含むオブジェクト配列を使用して、このメソッドを呼び出します。

パラメーターobjectType説明
parameters[0]コマンド結果初期パターン コマンドの結果を含みます。
parameters[1]

iProvider

検出システムに接続されている実行中のプロバイダークラスを含みます。

このプロバイダーは、必要に応じて他のコマンドを実行するためにパターンで使用されます。

parameters[2]オブジェクト

スキャンの開始時に最初に作成される HostInfo-/Device-オブジェクトを含みます。

プロバイダー クラス

ホストまたはデバイスへの接続では、 Discovery-Tool で使用するプロバイダーのタイプが 4 つあります。以下では、接続とデータ収集コマンドの実行を処理するプロバイダーについて説明します。

パターン内では、システムからさらに情報が必要な場合に、実際に接続されているプロバイダーを使用して追加のコマンドを実行できます。

SSH プロバイダー

SSH プロバイダー クラスは Linux システムに接続し、Insight のパターンで使用できます。

using Insight.Discovery.ProviderClasses; // Include the ProviderClasses Namespace at the Head of the PatternCode
using Insight.Discovery.InfoClasses; // Include the InfoClasses Namespace at the Head of the PatternCode

// Casting the connected Provider out of the parameters from the PerformAction-Method
SSHProvider ssh = (SSHProvider)parameters[1];
 
// using the SSH-Provider to execute a command and receiving the result.
var result = (SSHExecuteResult)ssh.ExecuteCommand("hostname"); // returning the hostname of a Linux System

たとえば、cast SSHProvider は "Linux_Hostinfo_Hostname.pat" パターンで使います。

WMI プロバイダー

WMI プロバイダー クラスは Windows システムに接続し、Insight のパターンで使用できます。

using Insight.Discovery.ProviderClasses; // Include the ProviderClasses Namespace at the Head of the PatternCode
using Insight.Discovery.InfoClasses; // Include the InfoClasses Namespace at the Head of the PatternCode

// Casting the connected Provider out of the parameters from the PerformAction-Method
WMIProvider wmiProvider = (WMIProvider)parameters[1];
 
// using the WMI-Provider to read a Registry Value.
var result = (WMIRegValueResult)wmiProvider.GetRegistryValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\<Key>", "DisplayName");
 
// using the WMI-Provider to get a List of all Registry-Sub-Keys.
var result = (WMIRegValueListResult)wmiProvider.GetSubKeysFromRegistry("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\");

//using the WMI-Provider to execute a WMI query receiving the result.
var result = (WMIQueryResult)wmiProvider.ExecuteWMIQuery("netstat -an");

//using the WMI-Provider to execute a command and receiving the result.
var result = (WMIExecuteResult)wmiProvider.ExecuteWMICommand("netstat -an");

SNMP プロバイダー

SNMP プロバイダー クラスは SNMP デバイスに接続し、Insight のパターンで使用できます。

using Insight.Discovery.ProviderClasses; // Include the ProviderClasses Namespace at the Head of the PatternCode
using Insight.Discovery.InfoClasses; // Include the InfoClasses Namespace at the Head of the PatternCode
using System.Text;

// Casting the connected Provider out of the parameters from the PerformAction-Method
SNMPProvider snmp = (SNMPProvider)parameters[1];

// (Optional) Return octet strings as HEX
snmp.OctetStringAsHex = true;

// (Optional) Set encoding for octet string (Encoding.ASCII, Encoding.UTF8, Encoding.Unicode, or Encoding.UTF32)
snmp.OctetStringEncoding = Encoding.ASCII;

// using the SNMP-Provider to execute a SNMPGet command and receiving the results
var result = (SNMPExecuteResult)snmp.ExecuteCommand("1.3.6.1.2.1.1.6.0", ScanProcessType.SNMP_GET, true);
 
// using the SNMP-Provider to execute a SNMPWalk command and receiving the results
var result = (SNMPExecuteResult)snmp.ExecuteCommand("1.3.6.1.2.1.2.2.1.2", ScanProcessType.SNMP_WALK, true);

// using the SNMP-Provider to execute a SNMPWalk command with contextName and receiving the results
var result = (SNMPExecuteResult)snmp.ExecuteCommand("1.3.6.1.2.1.2.2.1.2", ScanProcessType.SNMP_WALK, "myContext",true);

VIM プロバイダー

SNMP プロバイダー クラスは VMware ESXi システムに接続し、Insight のパターンで使用できます。

using Insight.Discovery.ProviderClasses; // Include the ProviderClasses Namespace at the Head of the PatternCode
using Insight.Discovery.InfoClasses; // Include the InfoClasses Namespace at the Head of the PatternCode
 
// Casting the connected Provider out of the parameters from the PerformAction-Method
VIMProvider snmp = (SNMPProvider)parameters[1];
 
// using the VIM-Provider to execute a command and receiving the results
var result = (VIMCommandResult)snmp.ExecuteCommand("HostSystem");

その他の機能

ImportService

アプリの InstallDate など Discovery-Object の Date 属性を設定する場合は、特定の形式 ("MM/dd/yyyy") にする必要があります。

提供される ImportService.ImportDate メソッドを使って変換を実行できます。

using Insight.Discovery.Tools; // Include the Discovery Tools Namespace at the Head of the PatternCode
 
// using the ImportDate Method to transform the Date string of a result Object
discoveryObject.InstallDate = ImportService.Instance.ImportDate("resultDateString");
 
// The following input formats will be transformed:
// "MM/dd/yy", "M/dd/yy", "MM/dd/yyyy", "M/dd/yyyy", "MM/dd/yy", "M/d/yy", "MM/d/yyyy", "M/d/yyyy", "yyyyMMdd", "yyMMdd", "dd.MM.yy", "dd.MM.yyyy", "MMM-dd-yy", "MMM-dd-yyyy", "yyyy-MM-dd"

LogService

Discovery ログファイルにエントリを書き込む場合は、提供される LogService クラスが使えます。

using Insight.Discovery.Tools; // Include the Discovery Tools Namespace at the Head of the PatternCode
 
// creating a "normal" log entry
LogService.Instance.LogNormal("My normal log entry");
 
// creating a "debug" log entry with additional Exception object
try
{
	LogService.Instance.LogDebug("a debug log entry");
	// Code that could raise an exception
}
catch (Exception ex)
{
	LogService.Instance.LogError("Log of an exception", ex);
}

カスタム パターンの例

例については、カスタム パターンの例を参照してください。

最終更新日: 2024 年 1 月 9 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.