HTTP sending

Token-based authentication is employed to secure HTTP connections used to send data to Devo. To set up an HTTP connection you need to generate the token, then configure the endpoint.

In case any error occurs during data sending it will be logged in the bad.illegal table of your domain.

Create an HTTP token

The HTTP token is a 32-character alphanumeric string that authenticates a connection to Devo. To create it:

  1. Go to Administration → Credentials and select the HTTP/Apiv2 Tokens tab.
  2. Click Create new token.



  3. The Create new token window opens. Select Http Send.



  4. Enter a Token name and identify the destination Target table(s). This is the tag or tags that will be used by Devo to classify the events. You can use wildcards to send the data to multiple tables. See the HTTP/APIv2 tokens section to learn how to use wildcards to specify your target tables.

  5. Click Accept. The token is generated and appears in the HTTP Tokens list.

Configuring the endpoints

Once the token has been generated, you can configure the endpoint. The URL to send the HTTP request follows this format:

<endpoint>/<mode>/<domain>/token!<token>/<host>/<tag>?<message>

Each element in the URL is described below:

  • <endpoint> - Use the endpoint that corresponds to the account you use.

    USA EU VDC/Spain
    http[s]://http-us.logtrust.io http[s]://http-eu.logtrust.io http[s]://http-es.logtrust.io
  • <mode> - It can be either event (for sending single events) or stream (for sending multiple events). Each mode accepts HTTP methods as follows:

      event stream
    GET
    POST
    PUT
  • .<domain> - The Devo account to send the events to.
  •  <token> - The token you generated in Devo to authenticate your connection. 
  •  <host> - The name of the sending host. If unknown, enter "-".
  •  <tag> - The tag added to the data
  •  <message> - The message to be logged.

Here is an example of an endpoint URL:

http://<endpoint>/event/domain/token!a53702g8592241eg2ee84fe75d7edf9d/local1/my.app.http.js?this%20is%20a%20example%20of%20log

Code samples

See below some code samples for different programming languages:

Java

package lt.example.http.send;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

public class Main {
  // /event/<identity>/token!<signature>/<host>/<tag>?<message>

  public static void main(String[] args) {
    try {
      final String url = generateUrl(
        "http://logtrustServerHostname",
        "demoDomain",
        "example_token_1234abcd",
        "my_src_hostname",
        "my.app.demo.send",
        encodeToHttp("example_of_log"));

      URL obj = new URL(url);
      HttpURLConnection con = (HttpURLConnection) obj.openConnection();
      con.setRequestMethod("GET");
      int responseCode = con.getResponseCode();
      System.out.println("Response Code : " + responseCode);
      System.out.println("Response: " + con.getResponseMessage());
    } catch (UnsupportedEncodingException e) {
      System.err.println("Cannot encode message: " + e.getMessage());
      e.printStackTrace();
    } catch (IOException e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
    }
  }

  public static String encodeToHttp(String str)
    throws UnsupportedEncodingException {
    return URLEncoder.encode(str, "UTF-8").replace("+","%20");
  }

  public static String generateUrl(String serverPath, String domain,
                                   String token, String hostname,
                                   String tag, String msg) {

    return new StringBuilder(serverPath)
            .append("/event/")
            .append(domain).append("/token!")
            .append(token).append("/")
            .append(hostname).append("/")
            .append(tag).append("?")
            .append(msg)
            .toString();
  }
}

Java (POST example)

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.DataOutputStream;

public class Main {
    public static void  main(String[] args) {
        try{
            final String url = generateUrl(
                    "http://logtrustServerHostname",
                    "demoDomain",
                    "example_token_1234abcd",
                    "my_src_hostname",
                    "my.app.demo.send");

            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
            con.setRequestMethod("POST");
            con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            con.setRequestProperty("charset", "utf-8");
            con.setDoOutput(true);
            
            String urlParameters;
            DataOutputStream wr = new DataOutputStream(con.getOutputStream());
            
            for (int i = 0; i < 3; i++) {
                urlParameters = "PostExample" + i + "\n"; // \n needed to send multiple events, otherwise the stream will be sent as a single event
                wr.writeBytes(urlParameters);
            }

            wr.flush();
            wr.close();
            int responseCode = con.getResponseCode();
            System.out.println("Response Code : " + responseCode);
            System.out.println("Response: " + con.getResponseMessage());

        } catch (UnsupportedEncodingException e) {
            System.err.println("Cannot encode message: " + e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }

    public static String generateUrl(String serverPath, String domain,
                                     String token, String hostname,
                                     String tag) {

        return new StringBuilder(serverPath)
                .append("/stream/")
                .append(domain).append("/token!")
                .append(token).append("/")
                .append(hostname).append("/")
                .append(tag).append("?")
                .toString();
    }
}

Web

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>LT: JQuery Example</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script>
    var serverPath = "http://logtrustServerHostname";
    var domain = "demoDomain";
    var token = "example_token_1234abcd";
    var hostname = "my_src_hostname";
    var tag = "my.app.demo.send";
    var msg = "this is a example of log";

    function generateUrl(domain, token, hostname, tag, msg) {
      return serverPath + "/event/" + domain + "/token!" + token + "/" +
        hostname + "/" + tag + "?" + msg;
    }

    $(document).ready(function() {
      $.get(generateUrl(domain, token, hostname, tag, msg),
        function(data, status) {
          alert("Data: " + data + "\nStatus: " + status);
        });
    });
  </script>
</head>
<body>
  <h1>JQuery Example</h1>
</body>
</html>

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>LT: JS Example</title>
  <script>
    var serverPath = "http://logtrustServerHostname";
    var domain = "demoDomain";
    var token = "example_token_1234abcd";
    var hostname = "my_src_hostname";
    var tag = "my.app.demo.send";
    var msg = "this is a example of log";

    function generateUrl(domain, token, hostname, tag, msg) {
      return serverPath + "/event/" + domain + "/token!" + token + "/" +
        hostname + "/" + tag + "?" + msg;
    }

    var req;

    if (window.XMLHttpRequest) {
      req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {

        try {
          req = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
      }
    }

    req.open("GET", generateUrl(domain, token, hostname, tag, msg), true);
    req.send(null);
  </script>
</head>
<body>
  <h1>JS Example</h1>
</body>
</html>

Have we answered your question?

If not, please contact our technical support team via email by clicking the button below.

CONTACT US