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

お困りですか?

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

コミュニティに質問

You can create your own custom patterns and even edit or disable patterns. However, we recommend that you don’t edit the default patterns.

Create a custom pattern

For creating a custom pattern navigate to the Discovery/pattern folder. Here you can create a new file (UTF-8) with the ending .pat or copy and modify an existing pattern of the Pattern-Type you want. We recommend that you develop and test a new pattern in a non-production environment and set up a connection to the Host or Device that returns the result data you want to handle with from Discovery.

Then remove all Patterns excluding a "main" HostInfo Pattern (Linux_Hostinfo_Hostname.pat, Windows_Hostinfo_Hostname_Model.pat, SNMP_Deviceinfo_Default.pat) it is mandatory to have a "main" HostInfo Object with the including Hostname. With this Setup it is possible to quickly test a new pattern without waiting for the response of all other Patterns.

Be sure that your new Pattern contains all required XML-Nodes, the <Processing>-Node contains the C# class to process the result data from the command to a Discovery-Object. The functionality is that the Discovery-Tool reads the C# Source Code, which includs the <Processing>-Node and invokes the PerformAction-Method of the PatternExec-Class.

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

The PerformAction Method is mandatory and the Discovery-Tool invokes it with an object array that includes the following 3 objects:

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

iProvider

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

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

parameters[2]オブジェクト

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

public void PerformAction(object[] parameters)
{
  HostInfo hostInfo = (HostInfo)parameters[2];
  try
{

プロバイダー クラス

For connecting to Host or Devices, there are 4 Types of Providers used by the Discovery-Tool. The following sections describe Providers handling the connection and execution of commands to collect data.

Inside a Pattern you have the availability to use the actual connected Provider to execute additional commands if more information from the System is needed.

SSH プロバイダー

The SSH-Provider-Class is connected to a Linux System and can be used inside a Pattern:

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

For example, a cast SSHProvider is used in the "Linux_Hostinfo_Hostname.pat" Pattern.

WMI プロバイダー

The WMI-Provider-Class is connected to a Windows System and can be used inside a Pattern:

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 プロバイダー

The SNMP-Provider-Class is connected to a SNMP Device and can be used inside a Pattern:

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 プロバイダー

The SNMP-Provider-Class is connected to a VMWare ESXi System and can be used inside a Pattern:

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 年 5 月 21 日

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

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