Create custom patterns

Still need help?

The Atlassian Community is here for you.

Ask the community

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 you copy and modifying an existing pattern of the Pattern-Type you want. The best practice to develop and test a new pattern is to extract a separate Discover-Tool Instance and setting up a connection to the Host or Device that returning the result data you want to handle with.

Then remove all Pattern 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 fast testing a new pattern without waiting of the response of all other Pattern.

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

The PerformAction Method is mandatory and the Discovery-Tool invoking it with an object array that are including the following 4 objects:

ParameterObject typeDescription
parameters[0]Command ResultContaining the result of the initial pattern command.
parameters[1]

IProvider

Containing the executing Provider-Class that is connected to the discovering system.

This provider will be used in the pattern to execute other commands if required.

parameters[2]object

Containing the HostInfo-/Device-Object that is initial created on the start of the scan.

Provider classes

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

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

SSH-Provider

The SSH-Provider-Class is connected to a Linux System and can be used insight of 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-Provider

The WMI-Provider-Class is connected to a Windows System and can be used insight of 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-Provider

The SNMP-Provider-Class is connected to a SNMP Device and can be used insight of 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-Provider

The SNMP-Provider-Class is connected to a VMWare ESXi System and can be used insight of 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");

Additional functions

ImportService

If you want to set a Date Attribute for a Discovery-Object like the InstallDate for an Application it must be in a specific Format ("MM/dd/yyyy").

You can use the delivered ImportService.ImportDate Method that will do the transformation for you:

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

If you want to write entries into the Discovery Logfile you can use the delivered LogService Class.

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);
}

Custom pattern examples

For examples, see Custom pattern examples.

Last modified on Jan 9, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.