You've already built this in chapter 5 but if not visit here.
You can build a visualization to compare the traffic from one week to another. This can help you identify any anomalies in the network traffic.
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Timeline" as the visualization type.
- Then on the right hand side, type the following:
.es(index=logstash*, metric=sum:flow.total_bytes, timefield=@timestamp, offset=-1w).label('Last Week').color(pink).divide(1048576),
.es(index=logstash*, metric=sum:flow.total_bytes, timefield=@timestamp).label('This Week').color(blue).divide(1048576)
This may seem like a silly visualization but it has been useful to only keep a benchmark on total traffic but to also prove that my traffic limits imposed by my ISP are being met. True story!
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Gauge" as the visualization type.
- On the right hand side, select "Sum" and then "flow.total_bytes" as the field.
- Restrict the visualization using the following filter
event_type.keyword:flow
. - Click on the "Save" button to save the visualization as "Total Bytes on Network".
You cannot show pairs of source and destination IPs in a single column. For that, you'll need to create a scripted field that concatenates them (in theory you could do this before ingestion too at the cost of increasing storage size for your data).
- Go to the Opensearch Dashboards web interface.
- Click on the "Dashboards Management" tab in the left top area.
- Click on "Index Patterns".
- Click on the index pattern you're using (logstash*).
- Click on the "Scripted fields" tab.
- Click on "Add scripted field".
- Name the field "src_dest_ip" and scroll all the way down to "Script" and type the following:
doc['src_ip.keyword'].value + '-' + doc['dest_ip.keyword'].value
- Click on "Save field".
Now, let's build the visualizations.
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Data table" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Split rows" and then "Aggregation" as "Terms".
- Select "Field" as
src_dest_ip
and click "Apply". - For "Metric" select "Sum" and then "Field" as
flow.total_bytes
. - You'll need to add a filter for
event_type.keyword:flow
. - You'll also need to restrict so that the data shown are for outgoing traffic from your local network. Add the following filter:
src_ip: "192.168.0.0/16" or src_ip: "10.0.0.0/8" or src_ip: "172.16.0.0/12" or src_ip: "fe80::/10"
and not dest_ip: "192.168.0.0/16" and not dest_ip: "10.0.0.0/8" and not dest_ip: "172.16.0.0/12" and not dest_ip: "fe80::/10"
- Save the visualization as "Data Table - Outgoing Byte Traffic".
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Data table" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Split rows" and then "Aggregation" as "Terms".
- Select "Field" as
src_dest_ip
and click "Apply". - For "Metric" select "Sum" and then "Field" as
flow.total_bytes
. - You'll need to add a filter for
event_type.keyword:flow
. - You'll also need to restrict so that the data shown are for incoming traffic to your local network. Add the following filter:
(dest_ip: "192.168.0.0/16" or dest_ip: "10.0.0.0/8" or dest_ip: "172.16.0.0/12" or dest_ip: "fe80::/10")
and not (src_ip: "192.168.0.0/16" or src_ip: "10.0.0.0/8" or src_ip: "172.16.0.0/12" or src_ip: "fe80::/10")
- Save the visualization as "Data Table - Incoming Byte Traffic".
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Data table" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Split rows" and then "Aggregation" as "Terms".
- Select "Field" as
src_dest_ip
and click "Apply". - For "Metric" select "Max" and then "Field" as
flow.age
. - You'll need to add a filter for
event_type.keyword:flow
. - Save the visualization as "Data Table - Longest Connections".
You can build a visualization to show the geolocation of the traffic. This can help you identify any traffic that is coming from unexpected locations.
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Coordinate Map" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Geohash" as the aggregation and then "Field" as
geoip.geohash
. - In "Metrics" select "Sum" and then "Field" as
flow.total_bytes
. - You'll need to add a filter for
event_type.keyword:flow
. - Save the visualization as "Coordinate Map - Geolocation of Traffic".
You'll need a scripted field that can show you the total bytes over the age of a connection. This can help you identify the fastest connections in your network, which for large data transfers can be useful to identify data exfiltration or just large downloads.
- Go to the Opensearch Dashboards web interface.
- Click on the "Dashboards Management" tab in the left top area.
- Click on "Index Patterns".
- Click on the index pattern you're using (logstash*).
- Click on the "Scripted fields" tab.
- Click on "Add scripted field".
- Name the field "avg_bytes_per_second" and scroll all the way down to "Script" and type the following:
if (doc.containsKey('flow.age') && doc['flow.age'].size() > 0 && doc['flow.age'].value > 0) {
return doc['flow.total_bytes'].value / doc['flow.age'].value;
} else {
return null; // or any other default value, or simply omit the field
}
- Click on "Save field".
Then its time to build your visualization.
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Data table" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Split rows" and then "Aggregation" as "Terms".
- Select "Field" as
src_dest_ip
and click "Apply". - For "Metric" select "Max" and then "Field" as
avg_bytes_per_second
. - You'll need to add a filter for
event_type.keyword:flow
. - Save the visualization as "Data Table - Fastest Connections".
You can build a visualization to show the speed of data transmission. This can help you identify any anomalies in the network traffic.
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Timeline" as the visualization type.
- Then on the right hand side, type the following:
.es(index=logstash*, metric='sum:avg_bytes_per_second').divide(1048576).label('Avg MBytes per second')
You can create a dashboard that has all the visualizations you've created so far. This can help you get a quick overview of the network traffic.
- Go to the Opensearch Dashboards web interface.
- Click on the "Dashboard" tab in the left top area.
- Click on "Create dashboard".
- Click on "Add" and then select the visualizations you've created so far.
- Just in case restrict filter to
event_type.keyword:flow
. - Click on "Save" to save the dashboard.
Here's how it looks like: