Kaspersky Industrial CyberSecurity for Networks API Developer's Guide

Using sorting for events

This section explains how sorting works, describes sorting syntax for events, and provides sorting examples.

About sorting

Sorting is a special string that can be specified in RPC calls. Sorting can be combined with filters or used separately from them. A sorting is a group of conditions that specify the order of returned events.

For example, if you want to get events with the GetItemsById method of EventProviderService, and you also want those events to be sorted by event identifier (in descending order), then you can use the following sorting to do so:

sort: {

event_id: desc

}

For examples of using sorting, see subsection "Making event requests with sorting" below.

Combining sorting with filters

Sorting can be combined with filters.

sort: {

event_id: desc

}

filter: {

event_id = 100, 101, 102, 103

}

For an example of using filters with sorting, see subsection "Making event requests with sorting" below.

Sorting condition syntax

Sorting conditions use the following syntax:

field : order

Above, field is the name of the field affected by the condition, and order is one of the following two values:

  • asc

    Field values are sorted in ascending order.

  • desc

    Field values are sorted in descending order.

For compound fields use the following syntax:

field.subfield : order

Above, field is the name of the field, subfield is the name of the subfield affected by the condition, and order is the order of sorting.

To combine several sorting conditions, separate them with commas (,):

field_1 : order, field_2 : order, field_3 : order

The following are examples of sorting conditions:

event_id : asc

src_address.port: desc

occurred : desc

monitoring_point : asc, occurred : desc

Field names (event requests)

The following table summarizes field names that can be used in event requests:

Field names (event requests)

Field name

Subfields

Description

title

No

Event title

description

No

Event description

mark

No

User mark

occurred

No

Date and time when an event occurred

severity

No

Event severity

technology

No

Technology that generated the event

technology_rule

No

Name of the rule that generated the event

src_address

Yes

Source address

dst_address

Yes

Destination address

protocol

No

Protocol name

event_id

No

Event identifier

event_type_id

No

Event type identifier

monitoring_point

No

Monitoring point

Subfield names

The following table summarizes subfield names can be used in sorting conditions for fields that can have subfields:

Subfield names

Field name

Description

ip

IPv4 address

port

Port

mac

MAC address

vlan_id

Virtual LAN (VLAN) ID

Making event requests with filters

The following EventProviderService methods use sorting:

  • GetItemsById

    You can specify a sorting in the ItemsByIdRequest message.

  • RequestItems

    You can specify a sorting in the Filter message.

The following is an example of using sorting to get events with the GetItemsById method:

eventStub = event_provider_service_pb2_grpc.EventProviderStub(channel)

 

request = common_pb2.ItemsByIdRequest(

maxCount=3,

filter="sort:{monitoring_point : asc, occurred : desc}"

)

response = eventStub.GetItemsById(request)

for event in response:

print("\nEvent id:", event.eventId)

The following is an example of combining sorting and filters to get events with the GetItemsById method:

eventStub = event_provider_service_pb2_grpc.EventProviderStub(channel)

 

request = common_pb2.ItemsByIdRequest(

maxCount=3,

filter="filter: {severity = critical} sort: {event_id: desc}"

)

response = eventStub.GetItemsById(request)

for event in response:

print("\nEvent id:", event.eventId)