Skip to content

Commit

Permalink
Support network direction processor additions (#5603)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon authored and github-actions[bot] committed Apr 22, 2021
1 parent a30f7fa commit fbc8594
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
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";
}
}
}

0 comments on commit fbc8594

Please sign in to comment.