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?

More from Cloud

The history of the central processing unit (CPU)

10 min read - The central processing unit (CPU) is the computer’s brain. It handles the assignment and processing of tasks, in addition to functions that make a computer run. There’s no way to overstate the importance of the CPU to computing. Virtually all computer systems contain, at the least, some type of basic CPU. Regardless of whether they’re used in personal computers (PCs), laptops, tablets, smartphones or even in supercomputers whose output is so strong it must be measured in floating-point operations per…

A clear path to value: Overcome challenges on your FinOps journey 

3 min read - In recent years, cloud adoption services have accelerated, with companies increasingly moving from traditional on-premises hosting to public cloud solutions. However, the rise of hybrid and multi-cloud patterns has led to challenges in optimizing value and controlling cloud expenditure, resulting in a shift from capital to operational expenses.   According to a Gartner report, cloud operational expenses are expected to surpass traditional IT spending, reflecting the ongoing transformation in expenditure patterns by 2025. FinOps is an evolving cloud financial management discipline…

IBM Power8 end of service: What are my options?

3 min read - IBM Power8® generation of IBM Power Systems was introduced ten years ago and it is now time to retire that generation. The end-of-service (EoS) support for the entire IBM Power8 server line is scheduled for this year, commencing in March 2024 and concluding in October 2024. EoS dates vary by model: 31 March 2024: maintenance expires for Power Systems S812LC, S822, S822L, 822LC, 824 and 824L. 31 May 2024: maintenance expires for Power Systems S812L, S814 and 822LC. 31 October…

IBM Newsletters

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