Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create patterns that can distinguish between printer models I scan

Odd-Laurits Andreassen September 26, 2024

We have many printers that are different models. I need to be able to have pattern for almost every model as OID is not the same on all models for serialnumber/model/Vendor. 

 

Have tried to make several patterns for different printers with different OIDs. The last printer pattern that is run overwrites the printer information.

I need help understanding how to get the pattern to only run for specific Model.

2 answers

1 accepted

2 votes
Answer accepted
Evgenii
Community Champion
September 27, 2024

Hi, @Odd-Laurits Andreassen 


It's very abstract question, without examples, how names can look like.

Of course, I can advice you to use https://regex101.com/ and chatGPT, but if you want us to help, we need more input information. Regexp depends from names. No names = no regexp :)

Evgenii
Community Champion
September 27, 2024

Hm, so, you're asking not for regexp pattern, but for pattern for discovery.
Honestly to say - not a good specialist in it, but you can try this code. It's made with latest model of openai and looks like code, that can solve your problem. Can't check it though


<?xml version="1.0" encoding="utf-8"?>
<ScanPattern xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Version>1.0</Version>
<PatternID>_NAV-Network-Printer-Lexmark-C792-SNMP-1</PatternID>
<OrderNr>999</OrderNr>
<ProcessType>SNMP_GET</ProcessType>
<PatternType>Device</PatternType>

<Command>
<![CDATA[
1.3.6.1.2.1.43.5.1.1.17.1; // Serial Number
1.3.6.1.4.1.641.2.1.2.1.2.1; // Printer Model
1.3.6.1.4.1.641.1.5.7.6.0; // Hostname
1.3.6.1.2.1.43.9.2.1.8.1.1 // Page Count
]]>
</Command>

<Processing>
<![CDATA[
using System;
using System.Collections.Generic;
using Insight.Discovery.InfoClasses.CommandResult.ResultTypes;
using Insight.Discovery.Tools;
using Insight.Discovery.InfoClasses;
using Insight.Discovery.InfoClasses.CommandResult;

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

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

string model = null;

// Extract the model information
foreach (KeyValuePair<string, object> item in commandResult)
{
if (item.Key == "1.3.6.1.4.1.641.2.1.2.1.2.1") // OID for the printer model
{
if (item.Value != null)
{
model = item.Value.ToString();
}
break;
}
}

// Check if the model is "C792"
if (model == null || !model.Equals("C792", StringComparison.OrdinalIgnoreCase))
{
// Not the target model, exit the method
return;
}

// Proceed with further processing for C792 model
foreach (KeyValuePair<string, object> item in commandResult)
{
switch (item.Key)
{
case "1.3.6.1.4.1.641.1.5.7.6.0": // OID to get Hostname
if (item.Value != null)
{
deviceInfo.DeviceName = item.Value.ToString();
}
break;

case "1.3.6.1.2.1.43.5.1.1.17.1": // OID to get Serial Number
if (item.Value != null)
{
deviceInfo.SerialNumber = item.Value.ToString();
}
break;

case "1.3.6.1.2.1.43.9.2.1.8.1.1": // OID to get Page Count
if (item.Value != null)
{
deviceInfo.PagesPrinted = item.Value.ToString();
}
break;
}
}
}
catch (Exception ex)
{
InsightLogger.Error(ex);
}
}
}
}
]]>
</Processing>
</ScanPattern>
Like Odd-Laurits Andreassen likes this
Odd-Laurits Andreassen September 27, 2024

Hi. Thank`s! This made my day. 

 

// Check if the model is "C792"
if (model == null || !model.Equals("C792", StringComparison.OrdinalIgnoreCase))
{
// Not the target model, exit the method
return;

and where the code is in the pattern. I will try this :)

 

Odd

Like Evgenii likes this
0 votes
Odd-Laurits Andreassen September 27, 2024

Hi. Sorry for the lack of information. 

We have Lexmark printers and some of the models:

CX735adse
MS521dn
MS811
C792
CX510de
CX635adwe

C792

The pattern I am using is starting like this and i don`t understand where to put the code that makes this pattern to only trigger on the printer model C792.

 

<?xml version="1.0" encoding="utf-8"?>
<ScanPattern xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Version>1.0</Version>
<PatternID>_NAV-Network-Printer-Lexmark-C792-SNMP-1</PatternID>
<OrderNr>999</OrderNr>
<ProcessType>SNMP_GET</ProcessType>
<PatternType>Device</PatternType>

<Command>
<![CDATA[

1.3.6.1.2.1.43.5.1.1.17.1;1.3.6.1.4.1.641.2.1.2.1.2.1;1.3.6.1.4.1.641.1.5.7.6.0;1.3.6.1.2.1.43.9.2.1.8.1.1
]]>

</Command>
<Processing>

<![CDATA[
using System;
using System.Collections.Generic;
using Insight.Discovery.InfoClasses.CommandResult.ResultTypes;
using Insight.Discovery.Tools;
using Insight.Discovery.InfoClasses;
using Insight.Discovery.InfoClasses.CommandResult;


namespace Insight.Discovery

{

public class PatternExec

{

public void PerformAction(object[] parameters)

{

DeviceInfo deviceInfo = (DeviceInfo)parameters[2];

 

try

{

var commandResult = (SNMPExecuteResult)parameters[0];

commandResult.LogResult();

 

foreach (KeyValuePair<string, object> item in commandResult)

{

switch (item.Key)

{

 

case "1.3.6.1.4.1.641.1.5.7.6.0": // OID to get Hostname

if (item.Value != null)

{

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events