Skip to content

[pkg/ottl] Add function to check if IP belongs to given CIDR #42215

@byehn

Description

@byehn

Component(s)

pkg/ottl

Is your feature request related to a problem? Please describe.

It seems that OTTL currently does not provide a function to check whether an IP address falls within a specific IP range. As a workaround, we have to rely on functions like IsMatch.

Describe the solution you'd like

The IsInCIDR function checks whether a given IPv4 or IPv6 address belongs to one or more IP ranges defined in CIDR notation, and returns a boolean value.

IsInCIDR(resource.attributes["server.ip"], ["192.168.0.0/16"])
IsInCIDR(resource.attributes["server.ip"], ["192.168.0.0/16", "10.0.0.0/8"])
IsInCIDR(resource.attributes["server.ip"], ["2001:db8::/32"])

Describe alternatives you've considered

No response

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions