search

Prev Next

Overview

You can look up Effective Log Search & Analytics logs by project.

Request

API URL

POST
https://elsa.apigw.ntruss.com/api/v1/logs/search

Request header

The request headers specified in common settings are required.
Go to the creation guide of NAVER Cloud Platform authentication key and signature

x-ncp-apigw-timestamp: {current timestamp}
x-ncp-iam-access-key: {your iam access key}
x-ncp-apigw-signature-v2: {generated signature}

Request parameter

Parameter name Requirement status Type Restrictions Description
projectKey Yes string 1-53 Project key

Example:
“projectKey”:“Pbxxxxx_elsa-test”
projectId Yes int Project ID

Example:
"projectId":8171
from Yes int The timestamp at which to start the search (UTC milliseconds).

Example:
"from":1381190400000
to Yes int The timestamp at which to end the search (UTC milliseconds).

Example:
"to"1381190400000
offset No int offset+limit<=10000 Default value: 0
You can specify an offset value at the beginning of the search results. 0 signifies the starting at the beginning of the first record.

Example:
"offset": 100
limit No int 1 - 1000 Default value: 10
This is the number of logs to return upon request. Returns the number of logs as specified as the offset value.

Example:
"limit": 500
sorts No Default value: [{"logTime":"DESC"}]
You can specify the sorting method.
This can only be applied when using the sorts feature. If the sorting field is a string field other than the specific fields (projectName, logTime, logLevel, host, projectVersion), ".raw" must be placed after the field.
If you're not sure if the field that requires sorts needs ".raw" to be placed, then you can find out in the /api/v1/fields API.

Example:
“sorts”: [{"logType.raw":"DESC"}]
“sorts”: [{"projectVersion":"ASC"},{"logType.raw":"DESC"}]
query No string Bool operators
AND OR NOT + -
Please refer to Query String Syntax / Lucene Query Syntax for more help.

JSON special characters
To search for the JSON special characters, such as the following, put \ before the characters.
"
\


Example:
Source: "query": "NOT logLevel:"FATAL" AND projectName:"elsa-test" AND (agent:"iPhone" OR agent:"iPod")"

After applying the escape character: "query": "NOT logLevel:\"FATAL\" AND projectName:\"elsa-test\" AND (agent:\"iPhone\" OR agent:\"iPod\")"
includeFields No [string] This is the list of field names needed to look up logs.

Example:
“includeFields”: [“logSource”,” logType”,”body”]
excludeFields No [string] This is the list of field names that is not needed to look up logs.

Example:
“excludeFields”: [“DmpReport”,” logType”]

Request body

{
  "projectId": 8171,
  "projectKey": "Pbxxxxx_elsa-test",
  "from": 1381190400000,
  "to": 1381190400000,
  "offset": 0,
  "limit": 1000,
  "query": "NOT logLevel:\"FATAL\" AND projectName:\" elsa-test\" AND (agent:\"iPhone\" OR agent:\"iPod\")",
  "includeFields": [
    "logSource",
    "logType",
    "body"
  ],
  "sorts": [
    {
      "projectVersion": "ASC"
    },
    {
      "logType.raw": "DESC"
    }
  ]
}

Request examples

import hashlib
import hmac
import base64
import time
import requests

def make_signature(access_key, secret_key, timestamp, url):
    timestamp = str(timestamp)
    secret_key = bytes(secret_key, 'UTF-8')
    method = "POST"

    message = method + " " + url + "\n" + timestamp + "\n" + access_key
    message = bytes(message, 'UTF-8')
    signingKey = base64.b64encode(hmac.new(secret_key, message, digestmod=hashlib.sha256).digest())
    return signingKey.decode('UTF-8')


def log_search():
    baseurl = "https://elsa.apigw.ntruss.com" #{OpenAPI endpoint}
    url = "/api/v1/logs/search"

    access_key = "accessKey" #{Main / Sub Account Access Key}
    secret_key = "secretKey" #{Main / Sub Account Secret Key}
    timestamp = int(time.time() * 1000)

    signature = make_signature(access_key, secret_key, timestamp, url)
    url = baseurl + url

    payload = {
      "projectId": 8171,
      "projectKey": "Pbxxxxx_elsa-test",
      "from": 1381190400000,
      "to": 1381190400000,
      "offset": 0,
      "limit": 1000,
      "query": "NOT logLevel:\"FATAL\" AND projectName:\" elsa-test\" AND (agent:\"iPhone\" OR agent:\"iPod\")",
      "includeFields": ["logSource","logType","body"],
      "sorts":[{"projectVersion":"ASC"},{"logType.raw":"DESC"}]
    }


    headers = {
        "x-ncp-apigw-timestamp": str(timestamp),
        "x-ncp-iam-access-key": access_key,
        "x-ncp-apigw-signature-v2": str(signature)
    }

    response = requests.post(url=url,
                  json=payload,
                  verify=True,
                  headers=headers
                  )

Response

Response body

{
  "data": {
    "total": 2,
    "logs": [
      {
        "sort": [
          "9.9.9",
          "elsa-log"
        ],
        "id": "27mt7eQqk9xILgiLdJcgxxxx",
        "existDmp": false,
        "source": {
          "logType": "elsa-log",
          "logSource": "json",
          "body": "Hello, I am [ xxx ], Nice to meet you !"
        }
      },
      {
        "sort": [
          "9.9.9",
          "nelo2-log"
        ],
        "id": "55mt7eQqk9xILgiLdJcgxxxx",
        "existDmp": false,
        "source": {
          "logType": " elsa-log ",
          "logSource": "json",
          "body": "Hello, I am [ xxx ], Nice to meet you !"
        }
      }
    ]
  },
  "status": 200
}