NetXMS Support Forum

English Support => General Support => Topic started by: Egert143 on February 03, 2021, 11:42:19 AM

Title: Parsing DCI instance discovery name
Post by: Egert143 on February 03, 2021, 11:42:19 AM
Hello

When creating DCi with instance discovery how can i parse the name to remove text between "[" and "]" inlcuding brackets also?

Example name: Camera - Name a - b - c [4a613e60-77f3-4e32-8d8e-d4723d945b98]


Egert
Title: Re: Parsing DCI instance discovery name
Post by: Filipp Sudanov on February 04, 2021, 12:27:29 PM
You can modify instance name and display name in instance discovery filter script by supplying them in array that script returns. Just open "Hint" in filter script editor, it has the necessary information. Here's an example script:

m = $1 match "(.+)\[.+\]";
if (m) {
  return( %(true, m[1]) );
}
else
{
  return false;
}


First line matches instance against a regex. The regex has one capture group which returns anything that is prior to [.
If regex got matched we can get this capture group as first element of array m.
Title: Re: Parsing DCI instance discovery name
Post by: Egert143 on February 04, 2021, 01:11:31 PM
Many thanks, had to adjust script litle bit, but got it working.

m = $1 match "(.+)\[.+\]";

if (m) {

  return %(true, $2, m[1]);
 
}
else
{
  return false;
}