XSIAM HTTP Log Collector Testing

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

XSIAM HTTP Log Collector Testing

L1 Bithead

Hello everyone,

 

We are currently considering to us a HTTP Log Collector.

 

However, before this can be started, I wanted to test the collection. 

 

Now, in theory, this should not be hard, due to the examples provided after setting up the integration.

Nonetheless, either the Python Example is faulty in some way, or I am being exceedingly stupid.

 

Currently, my code looks like this, very close to the provided example:

 

def test_http_collector(api_key: str) -> requests.Response:
    headers = {
        "Authorization": api_key,
        "Content-Type": "text/plain"
    }
    # Note: the logs must be separated by a new line
    body = "{'example1': 'test', 'timestamp': 1609100113039}\n{'example2': [12321,546456,45687,1]}"
    res = requests.post(url="https://api-<name>.xdr.de.paloaltonetworks.com/logs/v1/event",
                        headers=headers,
                        data=body,
                        timeout=600
                        )
    return res

I've only added a timeout and changed the linebreak (which would not add a newline) to a \n.

 

This consistently seems to return HTTP 500 for me.

 

The best I've managed in trying multiple ways for hours is HTTP 400 and I cannot even replicate it right now.

 

Does someone who is running a working HTTP log collector have any idea?

Or maybe a tested and proven, minimal working example?

 

Is there anywhere I can check what actually happened in XSIAM?

 

2 accepted solutions

Accepted Solutions

L0 Member

Hi there,

I tested the example in the documentation, and I could not get it to work until I fixed the single/double quotes.

Please test by replacing them as such:

body = '{"example": "test", "timestamp": 1609100113039}\n{"example2": [12321,546456,45687,1]}'

 

Let me know if this helps.

 

BR

Raúl

View solution in original post

L1 Bithead

A bit of testing has turned out a few more things, and likely the cause of the specific HTTP 400:

 

While Raúl was correct about the quotes being an issue with Python, the HTTP 400 error seems to arise whenever a HTTP collector instance is changed - e.g. the input type is changed from RAW to JSON, or the compression is changed from Gzip to uncompressed or ...

 

As this has cost me a lot of nerves and testing, here are some of my findings

 

  • Set up the HTTP based Collector - set it up in the way you want it to run. If you ever have to change anything about it, create a new one and redistribute the API key
  • JSON-collectors do not actually seem to care if the application type is set to application/json or text/plain 
  • Sending uncompressed data to a gzip collector works, too
  • Multiple JSON log lines must be sent as on json object per line, separated by line breaks

Working Python example function:

def test_http_collector(api_key: str, collector_url: str) -> requests.Response:
    headers = {"Authorization": api_key, "Content-Type": "application/json"}
    # Note: the logs must be separated by a new line
    msg_1 = '{"msg": "This is my test!", "severity": "High", "id": "EJhn90nsdui2", "duration": 432, "timestamp": 1609100113039}'
    msg_2 = '{"msg": "I am also a test", "severity": "Low", "id": "kdrjhWo834jhz", "duration": 20, "timestamp": 1609100113052}'
    body = f"{msg_1}\n{msg_2}"

    return requests.post(
        url=collector_url,
        headers=headers,
        data=body,
        timeout=600
    )

View solution in original post

3 REPLIES 3

L0 Member

Hi there,

I tested the example in the documentation, and I could not get it to work until I fixed the single/double quotes.

Please test by replacing them as such:

body = '{"example": "test", "timestamp": 1609100113039}\n{"example2": [12321,546456,45687,1]}'

 

Let me know if this helps.

 

BR

Raúl

Thank you!

 

This is what I must have done once, because it at least produces a 400 - Bad Request.

Which is further then I got, but I still do not know why this is happening.

 

L1 Bithead

A bit of testing has turned out a few more things, and likely the cause of the specific HTTP 400:

 

While Raúl was correct about the quotes being an issue with Python, the HTTP 400 error seems to arise whenever a HTTP collector instance is changed - e.g. the input type is changed from RAW to JSON, or the compression is changed from Gzip to uncompressed or ...

 

As this has cost me a lot of nerves and testing, here are some of my findings

 

  • Set up the HTTP based Collector - set it up in the way you want it to run. If you ever have to change anything about it, create a new one and redistribute the API key
  • JSON-collectors do not actually seem to care if the application type is set to application/json or text/plain 
  • Sending uncompressed data to a gzip collector works, too
  • Multiple JSON log lines must be sent as on json object per line, separated by line breaks

Working Python example function:

def test_http_collector(api_key: str, collector_url: str) -> requests.Response:
    headers = {"Authorization": api_key, "Content-Type": "application/json"}
    # Note: the logs must be separated by a new line
    msg_1 = '{"msg": "This is my test!", "severity": "High", "id": "EJhn90nsdui2", "duration": 432, "timestamp": 1609100113039}'
    msg_2 = '{"msg": "I am also a test", "severity": "Low", "id": "kdrjhWo834jhz", "duration": 20, "timestamp": 1609100113052}'
    body = f"{msg_1}\n{msg_2}"

    return requests.post(
        url=collector_url,
        headers=headers,
        data=body,
        timeout=600
    )
  • 2 accepted solutions
  • 148 Views
  • 3 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!