Python helper script for Logstash formatting

The preceding Logstash configuration will allow us to ingest network logs and create the index on Elasticsearch. What would happen if the text format we intend on putting into ELK is not a standard log format? This is where Python can help. In the next example, we will perform the following:

  1. Use the Python script to retrieve a list of IPs that the Spamhaus project considers to be a drop list (https://www.spamhaus.org/drop/drop.txt)
  2. Use the Python logging module to format the information in such a way that Logstash can ingest it
  3. Modify the Logstash configuration file so any new input could be sent to the AWS Elasticsearch Service

The chapter8_logstash_1.py script contains the code we will use. ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.