Parsing DCI instance discovery name

Started by Egert143, February 03, 2021, 11:42:19 AM

Previous topic - Next topic

Egert143

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

Filipp Sudanov

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.

Egert143

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