Add Custom pattern to insight discovery agent

Pavel Rusakov October 14, 2021

Hi everyone! I tried to add custom pattern Windows Chassis Type to my local insight discovery agent folder. I used https://confluence.atlassian.com/insightapps/download-custom-patterns-1085184075.html documentation.
But in log i see:

13.10.2021 17:38:43 : Using pattern: Windows_Hostinfo_ChassisType.pat (v4.0.1)
13.10.2021 17:38:43 : CompilerException script:

using System;
using System.Management;
using System.ComponentModel;
using System.Collections.Generic;
using Insight.Discovery.InfoClasses.CommandResult;
using Insight.Discovery.Tools;
using Insight.Discovery.InfoClasses;
using Insight.Discovery.InfoClasses.CommandResult.ResultTypes;

namespace Insight.Discovery {
public class PatternExec {
public void PerformAction(object[] parameters)
{
HostInfo hostInfo = (HostInfo)parameters[2];

try
{
var commandResult = (WMIQueryResult)parameters[0];
commandResult.LogResult();

foreach (DictionaryCommandResult item in commandResult)
{
try
{
if (item.ContainsKey("ChassisTypes") && item["ChassisTypes"].ToString() != string.Empty)
{
ushort[] values = (ushort[])item["ChassisTypes"];

//values = new ushort[] { 1, 3, 11, 16 }; // <-- Demo Data

if (values != null && values.Length > 0)
{
LogService.Instance.LogDebug(string.Format("We get {0} ChassisTypes.", values.Length));

hostInfo.ExtendedInformations = new List<ExtendedInformation>();

for (int i = 0;
i < values.Length;
i++) // It can happend that we get more than one ChassisTypes as result
{
ChassisTypes chassisTypes = ChassisTypes.Undefined;

try
{
chassisTypes = (ChassisTypes)values[i];

if (chassisTypes != ChassisTypes.Undefined)
{
LogService.Instance.LogDebug(
"We get chassis type: " + chassisTypes.EnumToString());

ExtendedInformation extendedInformation = new ExtendedInformation()
{
Name = i == 0 ? "ChassisType" : "ChassisType_" + i,
Value = chassisTypes.EnumToString()
};
hostInfo.ExtendedInformations.Add(extendedInformation);

extendedInformation = new ExtendedInformation()
{
Name = i == 0 ? "ChassisTypeId" : "ChassisTypeId_" + i,
Value = ((int)chassisTypes).ToString()
};
hostInfo.ExtendedInformations.Add(extendedInformation);
}
}
catch (Exception cex)
{
LogService.Instance.LogError(
"Error getting ChassisTypes from value: " + values[i], cex);
}
}
}
}
}
catch (Exception ex)
{
//
}
}
}
catch (Exception ex)
{ LogService.Instance.LogDebug("Error getting ChassisType Information", ex); }

}

private enum ChassisTypes
{
Undefined = 0,

Other = 1,

Unknown = 2,

Desktop = 3,

[System.ComponentModel.Description("Low Profile Desktop")]
Low_Profile_Desktop = 4,

[System.ComponentModel.Description("Pizza Box")]
Pizza_Box = 5,

[System.ComponentModel.Description("Mini Tower")]
Mini_Tower = 6,

Tower = 7,

Portable = 8,

Laptop = 9,

Notebook = 10,

[System.ComponentModel.Description("Hand Held")]
Hand_Held = 11,

[System.ComponentModel.Description("Docking Station")]
Docking_Station = 12,

[System.ComponentModel.Description("All in One")]
All_in_One = 13,

[System.ComponentModel.Description("Sub Notebook")]
Sub_Notebook = 14,

[System.ComponentModel.Description("Space-Saving")]
Space_Saving = 15,

[System.ComponentModel.Description("Lunch Box")]
Lunch_Box = 16,

[System.ComponentModel.Description("Main System Chassis")]
Main_System_Chassis = 17,

[System.ComponentModel.Description("Expansion Chassis")]
Expansion_Chassis = 18,

[System.ComponentModel.Description("Sub Chassis")]
Sub_Chassis = 19,

[System.ComponentModel.Description("Bus Expansion Chassis")]
Bus_Expansion_Chassis = 20,

[System.ComponentModel.Description("Peripheral Chassis")]
Peripheral_Chassis = 21,

[System.ComponentModel.Description("Storage Chassis")]
Storage_Chassis = 22,

[System.ComponentModel.Description("Rack Mount Chassis")]
Rack_Mount_Chassis = 23,

[System.ComponentModel.Description("Sealed-Case PC")]
Sealed_Case_PC = 24

}

}
}

13.10.2021 17:38:43 : ScriptException: Имя типа или пространства имен "CommandResult" отсутствует в пространстве имен "Insight.Discovery.InfoClasses" (пропущена ссылка на сборку?) at Line=6 Column=41
13.10.2021 17:38:43 : ScriptException: Имя типа или пространства имен "CommandResult" отсутствует в пространстве имен "Insight.Discovery.InfoClasses" (пропущена ссылка на сборку?) at Line=9 Column=41
13.10.2021 17:38:43 : pattern executed in 0,1723908 seconds

Is anybody can help me? 
Thanks in advance!

0 answers

Suggest an answer

Log in or Sign up to answer