Skip to content

[Backport master] Support network direction processor additions #5605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Nest/Ingest/Processors/NetworkDirectionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public interface INetworkDirectionProcessor : IProcessor

[DataMember(Name = "internal_networks")]
IEnumerable<string> InternalNetworks { get; set; }


[DataMember(Name = "internal_networks_field")]
Field InternalNetworksField { get; set; }

[DataMember(Name = "source_ip")]
Field SourceIp { get; set; }

Expand All @@ -36,6 +39,8 @@ public class NetworkDirectionProcessor : ProcessorBase, INetworkDirectionProcess
/// <inheritdoc />
public IEnumerable<string> InternalNetworks { get; set; }
/// <inheritdoc />
public Field InternalNetworksField { get; set; }
/// <inheritdoc />
public Field SourceIp { get; set; }
/// <inheritdoc />
public Field TargetField { get; set; }
Expand All @@ -51,6 +56,7 @@ public class NetworkDirectionProcessorDescriptor<T>
Field INetworkDirectionProcessor.DestinationIp { get; set; }
bool? INetworkDirectionProcessor.IgnoreMissing { get; set; }
IEnumerable<string> INetworkDirectionProcessor.InternalNetworks { get; set; }
Field INetworkDirectionProcessor.InternalNetworksField { get; set; }
Field INetworkDirectionProcessor.SourceIp { get; set; }
Field INetworkDirectionProcessor.TargetField { get; set; }

Expand All @@ -70,6 +76,13 @@ public NetworkDirectionProcessorDescriptor<T> DestinationIp<TValue>(Expression<F
/// <inheritdoc cref="INetworkDirectionProcessor.InternalNetworks" />
public NetworkDirectionProcessorDescriptor<T> InternalNetworks(params string[] internalNetworks) => Assign(internalNetworks, (a, v) => a.InternalNetworks = v);

/// <inheritdoc cref="INetworkDirectionProcessor.InternalNetworksField" />
public NetworkDirectionProcessorDescriptor<T> InternalNetworksField(Field internalNetworksField) => Assign(internalNetworksField, (a, v) => a.InternalNetworksField = v);

/// <inheritdoc cref="INetworkDirectionProcessor.InternalNetworksField" />
public NetworkDirectionProcessorDescriptor<T> InternalNetworksField<TValue>(Expression<Func<T, TValue>> objectPath) =>
Assign(objectPath, (a, v) => a.InternalNetworksField = v);

/// <inheritdoc cref="INetworkDirectionProcessor.SourceIp" />
public NetworkDirectionProcessorDescriptor<T> SourceIp(Field field) => Assign(field, (a, v) => a.SourceIp = v);

Expand Down
36 changes: 34 additions & 2 deletions tests/Tests/Ingest/ProcessorAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Nest;
using Tests.Core.Client;
using Tests.Core.Extensions;
using Tests.Core.Xunit;
using Tests.Domain;
using static Nest.Infer;

Expand Down Expand Up @@ -818,5 +816,39 @@ public class NetworkDirection : ProcessorAssertion

public override string Key => "network_direction";
}

[SkipVersion("<7.13.0", "Uses internal_networks_field added in 7.13.0")]
public class NetworkDirectionWithField : ProcessorAssertion
{
// for testing, we use the developer first name field for the network field

public override ProcFunc Fluent => d => d
.NetworkDirection<Project>(ud => ud
.DestinationIp(f => f.LeadDeveloper.IpAddress)
.SourceIp(f => f.LeadDeveloper.IpAddress)
.InternalNetworksField(f=> f.LeadDeveloper.FirstName)
.TargetField(p => p.Description)
.IgnoreMissing());

public override IProcessor Initializer => new NetworkDirectionProcessor
{
DestinationIp = Field<Project>(f => f.LeadDeveloper.IpAddress),
SourceIp = Field<Project>(f => f.LeadDeveloper.IpAddress),
InternalNetworksField = Field<Project>(f => f.LeadDeveloper.FirstName),
TargetField = "description",
IgnoreMissing = true
};

public override object Json => new
{
destination_ip = "leadDeveloper.ipAddress",
internal_networks_field = "leadDeveloper.firstName",
source_ip = "leadDeveloper.ipAddress",
target_field = "description",
ignore_missing = true
};

public override string Key => "network_direction";
}
}
}