Community FAQ
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
swright
Engaged Sweeper III

Is there a way to filter for Asset Names that are IP addresses?

1 ACCEPTED SOLUTION
Vicente_SC
Moderator
Moderator

There are a couple of ways to do this.

The best option is filtering in the "List of Assets" action, so you only get the assets whose name is an IP address. Just one consideration, as you are passing a string, you need to escape special characters. But in this case, you'll need to escape them twice. For example, if your expression contains "\.", you should write "\\\\.". Here is a code example:

 

{
conjunction: OR,
conditions: [
{
path: "assetBasicInfo.name",
operator: REGEXP,
value: "^[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}$"
}]
}

Another option is using the "Filter" action after a "List of Assets" action. In this case, you'll get all the assets in the first step, and will filter that list in the second step. Here, as you are using Javascript code, you can add forward slashes at the beginning and the end of the regular expression, so you don't need to escape characters. Example:

(item, index) => { 
const IpRegex = /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/;
return IpRegex.test(item.assetBasicInfo?.name);
}

You can test your regular expressions here (remember to select the RE2 syntax) : https://regex101.com/

View solution in original post

3 REPLIES 3
Vicente_SC
Moderator
Moderator

@swright, with the new Lansweeper connector version, there is no need to escape twice the special characters in the regex. So now, the previous filter expression in the List of Assets action will look like this:

{
 conjunction: OR,
 conditions: [
 {
  path: "asset.general.name",
  operator: REGEXP,
  value: "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$"
 }]
}

 

swright
Engaged Sweeper III

Thank you.  This is what I needed.

Vicente_SC
Moderator
Moderator

There are a couple of ways to do this.

The best option is filtering in the "List of Assets" action, so you only get the assets whose name is an IP address. Just one consideration, as you are passing a string, you need to escape special characters. But in this case, you'll need to escape them twice. For example, if your expression contains "\.", you should write "\\\\.". Here is a code example:

 

{
conjunction: OR,
conditions: [
{
path: "assetBasicInfo.name",
operator: REGEXP,
value: "^[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}$"
}]
}

Another option is using the "Filter" action after a "List of Assets" action. In this case, you'll get all the assets in the first step, and will filter that list in the second step. Here, as you are using Javascript code, you can add forward slashes at the beginning and the end of the regular expression, so you don't need to escape characters. Example:

(item, index) => { 
const IpRegex = /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/;
return IpRegex.test(item.assetBasicInfo?.name);
}

You can test your regular expressions here (remember to select the RE2 syntax) : https://regex101.com/

Forum

New to Lansweeper?

Try Lansweeper For Free

Experience Lansweeper with your own data.
Sign up now for a 14-day free trial.

Try Now