public class IpRangeOperator extends FetchOperator<IpRangeOperator> implements IResourceBuilder
IpRangeOperator
is an efficient and more powerful
implementation of the CidrRangeOperator
.
Here is a basic example. Say you have a CSV resource files containing the following :
network;geo_point;cc;country_name
1.0.0.0/24;-34.9281,138.5999;AU;Australia
1.0.1.0/24;34.7725,113.7266;CN;China
223.255.255.0/24;-33.494,143.2104;AU;Australia
The following example checks for the ""223.255.255.1" ip address.
if (ipRange().ipv4().url("file:/etc/geoipv4.csv")
// indicate which CSV field is the one containing the CIDR range
.cidrField("network")
// this is the ip you look for
.on("223.255.255.1")
.into([match]) {
// there is a match. What you have in [match] is :
// "match": {
// "geo_point": "-34.9281,138.5999",
// "cc": "AU",
// "country_name": "Australia",
// }
//
}
The cidrRange operator has the same capabilities for fetching remote resource files than the FetchCsvOperator. That is, you can write:
if (ipRange().ipv4().url("https://your.resource.server/cidrs.csv")
... .into([match]) {
// handle the match ...
}
You can add CRON expression to periodically re-fetch the remote resource file.
Check the FetchOperator class for examples.
IResourceBuilder.CompactionType
compactionType, hashKey, logger, lowerCaseKeys, requiredResource, runtimeContext, s3Bucket, s3endpoint, s3KeyPath, s3Object, s3SecretPath, silent, url, uuid
Constructor and Description |
---|
IpRangeOperator(RuntimeContext r)
Constructor.
|
IpRangeOperator(RuntimeContext r,
String url)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
IpRangeOperator |
cidrField(String cidrField)
Set the csv field to be used as the cidr range.
|
IpRangeOperator |
columns(String... columns) |
IResourceBuilder |
getResourceBuilder()
Implemented by subclasses to return the adequate resource builder.
|
boolean |
into(Tuple result)
Fire the operator and store the result in the provided tuple.
|
IpRangeOperator |
ipv4()
Make the operator work assuming ipv4 ip address format.
|
IpRangeOperator |
ipv6() |
IpRangeOperator |
matchFields(String... cidrMatchFields)
Set the csv field to be used as the cidr range.
|
IpRangeOperator |
on(String ip)
Set the input value you want to match.
|
IpRangeOperator |
on(Tuple ip)
Set the input ip value you want to match.
|
Tuple |
onEnd()
Callback that tells you the scan is done.
|
void |
onStart()
Callback to tell you you are about to receive new lines.
|
void |
onStream(Reader reader)
Callback for you to stream the remote resource file.
|
bestEffort, compact, compactDirect, compactInPlace, getResource, hashKey, loadAtStartup, lowerCaseKeys, refresh, required, s3AccessKey, s3AccessKeyPath, s3Bucket, s3Endpoint, s3Object, s3Secret, silent, url
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
prepare
public IpRangeOperator(RuntimeContext r)
r
- the punchlet runtime context@Deprecated public IpRangeOperator(RuntimeContext r, String url)
r
- url
- public IpRangeOperator cidrField(String cidrField)
cidrField
- the cidr field name.public IpRangeOperator matchFields(String... cidrMatchFields)
cidrMatchFields
- the matched field names.public IpRangeOperator on(String ip)
ip
- the ip input value as a Stringpublic IpRangeOperator on(Tuple ip)
ip
- the ip as a Tuple. This only works if the tuple contains a String leaf value.public boolean into(Tuple result)
result
- public IpRangeOperator columns(String... columns)
public IpRangeOperator ipv4()
This is the defult mode.
public IpRangeOperator ipv6()
public void onStart()
IResourceBuilder
onStart
in interface IResourceBuilder
public void onStream(Reader reader) throws IOException
IResourceBuilder
onStream
in interface IResourceBuilder
reader
- the input stream to consume the resource fileIOException
- in case of IO errorpublic Tuple onEnd()
IResourceBuilder
You should typically free any temporary storage, if any, used to build your resource.
onEnd
in interface IResourceBuilder
public IResourceBuilder getResourceBuilder()
FetchOperator
FetchCsvOperator
returns a builder to construct a tuple from a CSV document
while the FetchJsonOperator
returns builders to deal with JSON files.
This is called only once at init time.
getResourceBuilder
in class FetchOperator<IpRangeOperator>
Copyright © 2022. All rights reserved.