How can I retrieve the initial IP address from the 'X-Forwarded-For' using a Log Insight Query?

Can someone help me with extracting the initial IP address from the given data:

X-Forwarded-For":"1.1.1.1, 2.2.2.2
?

This is the query I am currently using:

fields @timestamp, @message
| filter @message like /Endpoint request body after transformations/
| parse @message "X-Forwarded-For\":\"*\"" as @IP
| stats count(*) by @IP
| limit 20

However, the results I am getting look like this:

1.1.1.1, 2.2.2.4
1.1.1.1, 2.2.2.5
1.1.1.1, 2.2.2.6

What modifications should I make in my query to only retrieve the first IP address?

Answer №1

When dealing with multiple IP addresses separated by commas, you can simplify the parsing process by stopping at the comma instead of the end quote, like so:

| parse @message "X-Forwarded-For\":\"*," as @IP

If there is a possibility of having only one IP address without a comma at the end, you can modify the code like this:

| parse @message /X-Forwarded-For\":\"(?<@IP>.*?)[,\"]/

This will capture everything up to the first comma or the closing quote, adjusting for scenarios where the comma may not be present.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtain PHP array after making an AJAX request

I'm using $.post() to send a JavaScript object and I need to receive an array in return. JavaScript Code var ajaxData = {action:"createuser"} $("input[required]").each(function(){ var attr = $(this).attr("name"); ajaxData[attr] = $(this).val ...

Extract the body.req object within a loop in a Node.js application

I'm looking to efficiently parse and save the body of a POST request using Mongoose in Node.js. Is there a way to use a for loop to accomplish this task, rather than manually saving every property? My ideal solution would involve something like: for ...

Error: The node is unable to parse JSON data through the API

After loading a JSON file as a string, attempting to parse it back to JSON and send it as a response: router.get('/todos', (req,res) =>{ let todos = fs.readFile('todos.json', 'utf8',(err, data) =>{ if (err) ...

Python script in PowerShell has arguments that include double quotes and whitespace

I am attempting to execute a python script using PowerShell. Within the python script, I am trying to include a command line argument with double quotes and whitespace, but it is not working as expected. It seems like there may be an issue with PowerShell. ...

Are there any methods available for capturing JSON data serverlessly using jQuery?

Currently, I am developing a serverless web application using JS + jQuery, CSS, and HTML stored in a flat file. My goal is to retrieve JSON data by making a GET request. Most methods I have come across involve AJAX techniques that necessitate the presence ...

Sending JSON data from an AJAX request to a PHP script

JavaScript file: var jsonData = []; var dataObject = new Object(); dataObject.name = "bob"; dataObject.age = "000"; dataObject.test = "test"; var json = JSON.stringify(dataObject); jsonData.push(json); $.ajax({ type: "POST", ...

The promise catch method does not handle JSON parsing correctly

Utilizing Angular's Http to interact with my API has been successful for handling responses with a status of 200. The data is parsed correctly and outputted as expected within the first .then() block. However, when encountering an error with a status ...

Unable to assign to array in VBA

There seems to be an issue in my code that I can't figure out. Specifically, the line "Key = decode.GetKeys(issue)" is causing the error mentioned in the title of this question. Public Sub Import_JSON_From_URL(url As JiraJSONGet) ThisWorkbook.Sheets ...

Sending post parameters from Angular and receiving JSON data from PHP using $http

Exploring the world of Angular and delving into the realm of $http, I find myself faced with a perplexing challenge: How to post parameters using $http (necessary for PHP to execute the call) Retrieve a JSON response from that call Here's what I&ap ...

Exploring the functionality of LINQ for sorting and searching through IEnumerable collections

I am currently new to MVC and LINQ, and I am in the process of learning how to use AngularJs and MVC for a new project that has been assigned to me. To accelerate my learning, I have turned to an online video tutorial. The tutor in the video utilizes a cod ...

issues with jquery's .each() method not functioning properly

I am looking to iterate over each item in lists and then each list within lists to calculate the number of items in list if the number of items in list is 3, I want to display an alert with the value of each item JSON Data { "lists":[ { ...

Readable JSON for a user-friendly browsing experience

I've been working on a web service that outputs data in JSON format. During the debugging process, I simply open the index.php file in my browser and view the JSON data without any proper formatting or indentation. However, I found a useful tool call ...

Error on Network: 400 BAD REQUEST in Ionic framework

I recently implemented push notifications successfully, but I am facing a network error with a 400 bad request when trying to access a specific API endpoint. The error message states: "NetworkError: 400 BAD REQUEST - https://apps.ionic.io/api/v1/app/77c3 ...

Having trouble decoding a potentially JSON string in Laravel controller without throwing any exceptions

After printing the results of \Input:all() in the laravel.log, I noticed the following output: Input : {"val":{"postID":"22","tags":["3"],"forwardComment":"aaaaaaa"}} [] It appears to be JSON format, so I attempted to decode it using json_d ...

Something is seriously wrong with the datetime in fullcalendar JavaScript

I've been diving into a tutorial for creating a calendar scheduler in asp.net MVC5 from this link. One issue I'm facing is the datetime being passed and stored as the min value in the database (1/1/0001 12:00:00 AM), almost like it's null b ...

Strategies for rapidly increasing user numbers in Amazon Cognito

Our team recently encountered an issue with hitting the request limit on Cognito due to trying to retrieve too many users at once. These users are grouped in game pools. Currently, our only method of obtaining users is through adminGetUser in parallel. Is ...

Gson Library: transform JSON containing null array field into an empty array

Is there a way to instruct GSON to create an empty array instead of setting it to null when a JSON with an array field has a NULL value? Are there any specific properties or flags that can be used for this purpose? ...

Retrieve data from MySQL using a count query and convert the results into a JSON format

In my table, there is a column with datetimes and corresponding IDs. +----+---------------------+ | id | datetime | +----+---------------------+ | 0 | 2016-09-02 12:13:13 | | 1 | 2016-09-02 10:16:11 | | 2 | 2016-09-05 11:03:23 | | 3 | 2016- ...

I am unsure about how to properly implement the reduce function

I am struggling with implementing the reduce function in my code. I have data output from a map function that consists of two documents. For example, one document contains: key "_id":"AD" "values" { "numtweets" : 1, "hastags" : ...

When code is obfuscated, JsonConvert.DeserializeObject() may return unexpected object types

In my C# solution, I have two projects: the main application and a license project. Both projects are functioning smoothly. I used JSON to serialize the license details, and now I want to obfuscate the licensing project to enhance security against frauds o ...