October 6, 2020 By Dimitri Prosper 3 min read

How to use Databases for Elasticsearch to index and search your VPC Flow Logs.

You may have set up VPC Flow Logs for your entire VPC to write to a Cloud Object Storage (COS) bucket. I did it a few weeks ago for a VPC that I use mainly for short-term projects and with no real-world production workload. Recently, I was looking for a method to search through the data stored in the Flow Logs COS bucket that had been accumulating for over one month. I knew of this excellent post and associated Python code repository from my colleague Powell Quiring that walk you through ingesting the Flow Logs objects into IBM Log Analysis with LogDNA.  

In addition to searching through this data, I envisioned integrating the search results with an ongoing pet development project of mine. In that other project, the environment is built and destroyed frequently, and I needed a fast method to bring back the data from the COS bucket. The Python sample referenced above is geared mostly to handle objects as they are added to the bucket, not for weeks worth of Flow Logs objects. For my use case, I determined that having a tool written in the same language I was using in my project — Golang — and indexing in IBM Cloud Databases for Elasticsearch was going to be the solution.  

In this post, I will share my configuration and a sample of the code I am using to index VPC Flow Logs to Elasticsearch.  

Deployment scenario

As mentioned earlier, I started with an existing VPC and already had a Flow Logs collector configured to a COS bucket. If you are new to VPC or VPC Flow Logs, you can read through Powell’s post and code sample — he provides the steps and scripts to generate VPC resources and configure Flow Logs. You can also check out our more extensive tutorials on VPC.

  1. A Flow Logs collector is configured for the VPC.
  2. The collector interfaces with IBM Cloud Object Storage and writes to the “flowlogs” bucket.
  3. A Databases for Elasticsearch is provisioned to be used for indexing and searching of the Flow Logs.
  4. A second COS bucket “indexed-flowlogs” is created to store objects that have already been indexed in Elasticsearch.
  5. The vpc-flowlogs-elasticsearch tool is configured to read the objects from the flowlogs bucket…
  6. …, index to Elasticsearch …
  7. … and write the indexed objects to the indexed-flowlogs bucket and deleted them from the flowlogs bucket.
  8. Once indexed, the tool, Postman, or any other application can be used to query Elasticsearch. 

Downloading, configuring, and running the tool

The tool demonstrates how to do the following:

The source code is available on GitHub, and you can copy and tailor it to your needs. The README.md in the repository will guide you on how to create a Databases for Elasticsearch instance, clone the repository, configure, and run the tool.  

Once configured to interact with your COS and Elasticsearch instances, indexing is a simple command: 

Searching can be performed straight from the tool using some pre-configured queries (are you one of the IPs trying to hack my server?):

You can also use Postman or another client; some example Elasticsearch queries are also made available in the repository. 

Questions and feedback

The GitHub repository has an Issues tab where you can comment on the content and code. If you have suggestions or issues, please submit your feedback.

Was this article helpful?
YesNo

More from Cloud

How a US bank modernized its mainframe applications with IBM Consulting and Microsoft Azure

9 min read - As organizations strive to stay ahead of the curve in today's fast-paced digital landscape, mainframe application modernization has emerged as a critical component of any digital transformation strategy. In this blog, we'll discuss the example of a fictional US bank which embarked on a journey to modernize its mainframe applications. This strategic project has helped it to transform into a more modern, flexible and agile business. In looking at the ways in which it approached the problem, you’ll gain insights…

Attention new clients: exciting financial incentives for VMware Cloud Foundation on IBM Cloud

4 min read - New client specials: Get up to 50% off when you commit to a 1- or 3-year term contract on new VCF-as-a-Service offerings, plus an additional value of up to USD 200K in credits through 30 June 2025 when you migrate your VMware workloads to IBM Cloud®.1 Low starting prices: On-demand VCF-as-a-Service deployments begin under USD 200 per month.2 The IBM Cloud benefit: See the potential for a 201%3 return on investment (ROI) over 3 years with reduced downtime, cost and…

24 IBM offerings winning TrustRadius 2024 Top Rated Awards

2 min read - TrustRadius is a buyer intelligence platform for business technology. Comprehensive product information, in-depth customer insights and peer conversations enable buyers to make confident decisions. “Earning a Top Rated Award means the vendor has excellent customer satisfaction and proven credibility. It’s based entirely on reviews and customer sentiment,” said Becky Susko, TrustRadius, Marketing Program Manager of Awards. Top Rated Awards have to be earned: Gain 10+ new reviews in the past 12 months Earn a trScore of 7.5 or higher from…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters