Query and fetch log data using WebSockets

Steps

  1. Login to the SMC API with the login method.
  2. Transfer the session cookie to the WebSocket session or share the socket itself.
  3. Connect to the WebSocket using the following URL:
     ws://[server]:[port]/[version]/monitoring/log/socket
  4. To query for log data, send a command with the following syntax:
    {"query":{}}

    This request queries all types of stored log data.

  5. To fetch the result of the query, send a command with the following syntax:
    {"fetch":{}}

    This request retrieves any stores log entries.

    Tip: You can also combine the command into a single request: {"query":{},"fetch":{}}.

    You can retrieve the full syntax for queries using the following request:

    GET http://[server]:[port]/[version]/monitoring/log/schemas

Result

After you send your request, you receive an immediate response that indicates whether the request has succeeded or failed.

Response Description
{"failure":
FAILURE_REASON}
The request failed. FAILURE_REASON is a message that describes the cause of the failure.
{"success":"No fetch"}
A request that does not include a fetch command succeeded.
{"success":"Fetch started",
"fetch":FETCH_ID}
A fetch request succeeded. FETCH_ID is an integer that identifies search results that match the query. This result might also contain field descriptions, depending on the selected format type and options.

When a request contains a fetch command, you receive one or more fetch results. Each fetch result references the fetch ID that was sent during the initial response to the fetch request. Each result contains intermediate information about the status of the fetch operation. The last result indicates why the fetch operation ended.

Example

Example of a response to a simple fetch request:

{"fetch":1,"end":"end of data"}
{"fetch":1,"status":"Querying..."}
{"fetch":1,"status":"Querying, filtering at 2012-03-26 16:00:05, scanned 659 days, 1 hour, 47 seconds (604471 mins/sec)",
"records":["1389711476185/1727/13","1389711476108/1727/4062434450241469840",
"1389711475658/1833/-9223372036854775807","1389711475182/1724/40",
"1389711474640/1722/4062434450241469840","1389711474609/1724/4062434450241469840",
"1389711474499/1722/-9223372036854775807","1389711472655/1833/-9223372036854775807",
"1389711469589/1725/27","1389711469502/1725/4062434450241469840",
"1389711468899/1720/-9223372036854775802"]}
{"fetch":1,"status":"Querying, filtering at 2012-03-26 16:00:05, scanned 659 days, 1 hour, 47 seconds (604471 mins/sec)",
"records":["1389711648533/1833/-9223372036854775790","1389711647530/1727/482",
"1389711646362/1498/874","1389711646019/1724/512","1389711644988/1722/-9223372036854775790",
"1389711641938/1730/-3475223237406465276","1389711641021/1497/846","1389711640797/1725/501",
"1389711640173/1728/515","1389711640029/1732/390”,…"1389711579459/1720/-9223372036854775788",
"1389711578481/1833/-9223372036854775797","1389711576984/1727/285","1389711576364/1498/531",
"1389711576127/1727/4062547184543063856",”1389711481520/1730/4062434450241469840",
"1389711481004/1497/29","1389711479826/1728/69","1389711479713/1728/4062434450241469840",
"1389711479661/1725/53","1389711478949/1720/-9223372036854775799",
"1389711478450/1833/-9223372036854775807"]}
{"fetch":1,"status":"Querying, filtering at 2014-01-14 15:58:45, scanned 2 minutes, 7 seconds (1 mins/sec)",
"records":["1389711651959/1730/-3475223237406465266","1389711651020/1497/895",
"1389711650868/1725/529","1389711650194/1728/543","1389711650066/1732/418",
"1389711649817/1720/-9223372036854775780"]}
{"success":"Fetch started","fetch":1}

To cancel an ongoing fetch, you can use the abort request with the appropriate fetch ID. To cancel the fetch in the previous example:

{"abort": 1}

Result:

{"fetch":1,"end":"aborted"}
{"success":"No fetch"}