Getting Data In

The Http Event Collector (HEC) accepts but doesn't index _json event with accented characters — is this a bug?

joelroth
Engager

Hi,

I've tracked down an issue we've been having where some events being sent through our HEC haven't been indexed, even though it responds with HTTP 200 and Success (0).

I've found two workarounds for this that resolve the issue, but I'm pretty sure the HEC should either have indexed the data anyway, or responded with some sort of error instead of Success.

My tests are done in PowerShell 5.1 with en-US culture.

The following snippet is an example of this, where it'll respond with 200 OK and not index the event:

Invoke-RestMethod -Method Post -Uri "https://splunk-hec.example.com:8088/services/collector/event" -Headers @{Authorization = "Splunk xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"} -ContentType "application/json" -Body @"
{
    "sourcetype":  "_json",
    "host":  "TESTHOST",
    "source":  "test:encoding",
    "event": { 
        "testtype": "charset not defined, sourcetype _json",
        "characterdata": "Têst vâlué thät has ąccents"
    }
}
"@

Also, if you specify charset=iso-8859-1 or charset=windows-1252, it also accepts and silently drops the event.

Workaround 1: Change the sourcetype to JSON (without the underscore)

# Change the sourcetype to json (no underscore)
Invoke-RestMethod -Method Post -Uri "https://splunk-hec.example.com:8088/services/collector/event" -Headers @{Authorization = "Splunk xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"} -ContentType "application/json" -Body @"
{
    "sourcetype":  "json",
    "host":  "TESTHOST",
    "source":  "test:encoding",
    "event": { 
        "testtype": "charset not defined, sourcetype json",
        "characterdata": "Têst vâlué thät has ąccents"
    }
}
"@

Workaround 2: Specify the charset with IRM

Invoke-RestMethod -Method Post -Uri "https://splunk-hec.example.com:8088/services/collector/event" -Headers @{Authorization = "Splunk xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"} -ContentType "application/json; charset=utf-8" -Body @"
{
    "sourcetype":  "_json",
    "host":  "TESTHOST",
    "source":  "test:encoding",
    "event": { 
        "testtype": "charset utf-8, sourcetype _json",
        "characterdata": "Têst vâlué thät has ąccents"
    }
}
"@

This is on Splunk Enterprise 7.1.2 using a heavy forwarder. Thanks!

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...