Is there a way to create tags for assets that their IP address matches a specific pattern like 10.*.112.* ?
I was thinking of groovy scripts but I don't know how to do it! Any asset having an IP like 10.*.112.*
// Skip testing on non-VM hosts.if(asset.getAssetType()!=Asset.AssetType.HOST) return false;
current_asset_ip = asset.getAddress().toString();
//Now you could split the IP up into seperate Octets and check that but I went with a RegEx.//This should work for the example: 10.*.112.*return current_asset_ip.matches("10\\.[0-9]*?\\.112\\.[0-9]*");
//This if matches will return true else return false adn the function is done.
//Example for 10.55.*.12return current_asset_ip.matches("10\\.55\\.[0-9]*?\\.12");
//Example - 10.*.*.1return current_asset_ip.matches("10\\.[0-9]*?\\.[0-9]*?\\.1");
You could also right this as a series of if and or statements if you wish.
Let me know if you need more help.
You want to create a tag on a pattern of the IP not a RANGE of the IP correct?
For instance you want to create two TAGS one that would look at an IP that starts with 10. and the second OCTET is say 12 and the last OCTET is 12
A second TAG might match where the IP starts with 10. and the second and 4th OCTET are 200.
Did I correctly re-state?
I can write this up for you and it would indeed be a groovy because your actually doing a string/number match. I need to split the IP by a period and then match the relevant portions.
I want to make sure I correctly re-state your issue so I can give you the correct and tested answer.
I am doing a test and It looks working!
What is the difference between these 2 expressions?
pulled from older code but the question mark really should not be needed. I think the * will do as it is one or more numbers 0-9. Try them both and let me know how that works for you.
The results are equal!
I did a test in regexr.com and this was explained there:
Retrieving data ...