Graylog Query to Retrieve Stream Name

  • Share this:

Code introduction


This function sends a query through the Graylog client and returns the stream name of the first message that matches the query. If the query does not match any messages, it returns None.


Technology Stack : graylog

Code Type : Function

Code Difficulty : Intermediate


                
                    
def graylog_query_stream_name(graylog_client, query):
    """
    Query the Graylog API to get the stream name based on the given query.
    """
    response = graylog_client.search(query)
    for message in response.messages:
        return message['message']['fields'].get('stream')
    return None                
              
Tags: