Blocking values from being displayed?

I am currently creating a glance view for our servers using the following script:-

<i>{{Name}}</i> | <b><u>CPU’s</u></b> <i>{{LogicalProcessors}}</i> | <b><u>IP Address</u></b> <i>{{IPAddress}}</i> | <b><u>VM</u></b> <i>{{IsVirtualMachine}}</i> | <b><u>Host</u></b> <i>{{HostServerName}}</i>

Which for the most part is great, however some of the strings are long for the servers, causing them to go off screen, which kind of defeats the point of the glance. I have noticed that it is picking up IPv4 and IPv6 addresses, as we haven’t adopted IPv6 as of yet I was wondering if it is possible to block the IPv6 values from being displayed to save on space.

1 Like

You can use the JavaScript function match to find all IPv4 address and then print them out.

Using an IPv4 regular expressions string from here, we can select all valid IPv4 addresses.

/((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/g

I’ve added in /g for multiple matches.

IPAddress.match(/((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/g)

This returns an array of all the IPv4 addresses, we can then join them back into a string by using join().

{{IPAddress.match(/((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/g).join(', ')}}

So your final custom template string will be:

<i>{{Name}}</i> | <b><u>CPU’s</u></b> <i>{{LogicalProcessors}}</i> | <b><u>IP Address</u></b> <i>{{IPAddress.match(/((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/g).join(', ')}}</i> | <b><u>VM</u></b> <i>{{IsVirtualMachine}}</i> | <b><u>Host</u></b> <i>{{HostServerName}}</i>
2 Likes

[Moderation: moved answer by Chris_Watson 16 May, to comment]
Hello,

I have tried this and this works thank you for the quick response.

Chris