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

Fortressing the digital frontier: A comprehensive look at IBM Cloud network security services

6 min read - The cloud revolution has fundamentally transformed how businesses operate. Its superior scalability, agility and cost-effectiveness have made it the go-to platform for organizations of all sizes. However, this shift to the cloud has introduced a new landscape of ever-evolving security threats. Data breaches and cyberattacks continue to hit organizations, making robust cloud network security an absolute necessity. IBM®, a titan in the tech industry, recognizes this critical need, provides a comprehensive suite of tools and offers unmatched expertise to fortify…

How well do you know your hypervisor and firmware?

6 min read - IBM Cloud® Virtual Private Cloud (VPC) is designed for secured cloud computing, and several features of our platform planning, development and operations help ensure that design. However, because security in the cloud is typically a shared responsibility between the cloud service provider and the customer, it’s essential for you to fully understand the layers of security that your workloads run on here with us. That’s why here, we detail a few key security components of IBM Cloud VPC that aim…

New IBM study: How business leaders can harness the power of gen AI to drive sustainable IT transformation

3 min read - As organizations strive to balance productivity, innovation and environmental responsibility, the need for sustainable IT practices is even more pressing. A new global study from the IBM Institute for Business Value reveals that emerging technologies, particularly generative AI, can play a pivotal role in advancing sustainable IT initiatives. However, successful transformation of IT systems demands a strategic and enterprise-wide approach to sustainability. The power of generative AI in sustainable IT Generative AI is creating new opportunities to transform IT operations…

IBM Newsletters

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