Requirements

  • Valid JSON content
  • API key (find this on your dashboard) sent in the headers
  • Content-Type header set as application/json
  • Either POST or PUT to https://api.logit.io/v2
  • You can send JSON content directly via any protocol if you wish

Sending logs via a curl request

The first example takes a string in JSON format and passes it through to Logstash via our API

curl -i -H "ApiKey: your-api-key" -i -H "Content-Type: application/json" -H "LogType: default" https://api.logit.io/v2 -d '{"test":"This is a test", "Country":"United Kingdom", "Weather":"Sunny" }'

The ApiKey can be found by going to the stack that will receive the log, navigating to the dashboard and clicking settings. The Stack Api Key is displayed on the default page when entering settings, which is the details page.

Executing the above command, ensuring that the ApiKey value has the value of the stack where the data is to be logged, will send the string through to Logstash. This can now be viewed by opening Kibana.

If the receiving stack has been set up to parse JSON, the data will have been logged as three new values. If the stack has not been set up to parse JSON the message field will contain a string coresponding with the data that has been sent.

Section 4 of this document has an example of how to update a filter to parse JSON data.

Sending logs via curl using a JSON file

It is also possible to test sending a JSON file to Logstash for logging. This example will show how to do this.

Sample Json file

{
"name": "Gandalf",
"city": "The Shire",
"display": "Hello there from JSON file",
"value": 5
}

The following command should now be entered into the command prompt, this will send the file to Logstash:

curl -i -H "ApiKey: your-api-key" -i -H "Content-Type: application/json" -H "LogType: json" https://api.logit.io/v2 -d @sample.json

As mentioned previously the ApiKey value can be found by going to the stack that will receive the logs, navigating to the dashboard and going to the details page in settings.

You should be able to see the new log record in Kibana. As also mentioned earlier, if the receiving stack has been set up to parse JSON, the data will have been logged as four new values. If the stack has not been set up to parse JSON the message field will contain a string coresponding with the data that has been sent.

The next section shows an example of how to update a filter to parse JSON data.

Logstash filter example for JSON

Below is an example of the code that needs to be added to a Logstash filter in order to have the string or file content sent through identified as JSON and processed as distinct fields and values (if this is required by the user):

if [type] == "json" 
{
    json
    {
        source => "message"
    }
}

or

if [message] =~ /^{.*}/  
{
    json 
    {
        source => "message"
    }
}

Without a filter like this the data sent to Logstash will be treated as a string and logged accordingly in the message field.