nerdexam
Cisco

300-910 · Question #125

Refer to the exhibit. An engineer must find application log file entries when a user named user1 makes an HTTP GET request and return only the time of the query. Which command completes the Bash scrip

The correct answer is B. jq 'select(.user=="user1" and .method=="GET").time' app.log. To filter JSON log entries for a specific user and HTTP method, then extract only the timestamp, the jq command must use select for conditional filtering and then dot notation to project the desired field.

Monitoring and Logging

Question

Refer to the exhibit. An engineer must find application log file entries when a user named user1 makes an HTTP GET request and return only the time of the query. Which command completes the Bash script? cat app.log {"user":"john","time":"2021-11-12 20:13:44","method":"GET"} {"user":"john","time":"2021-11-12 20:13:48","method":"POST"} {"user":"john","time":"2021-11-12 20:13:54","method":"POST"} {"user":"dave","time":"2021-11-12 20:14:04","method":"GET"} {"user":"john","time":"2021-11-12 20:14:44","method":"GET"} {"user":"alice","time":"2021-11-12 20:19:01","method":"GET"} {"user":"alice","time":"2021-11-12 20:23:21","method":"GET"} {"user":"john","time":"2021-11-12 20:49:38","method":"PATCH"}
2021-11-12 20:13:44 2021-11-12 20:14:44

Options

  • Ajq '.time' app.log
  • Bjq 'select(.user=="user1" and .method=="GET").time' app.log
  • Cjq 'select(.user=="user1" and .method=="GET")' app.log
  • Djq 'select(.user=="user1" and .GET).time' app.log

How the community answered

(43 responses)
  • A
    9% (4)
  • B
    81% (35)
  • C
    2% (1)
  • D
    7% (3)

Why each option

To filter JSON log entries for a specific user and HTTP method, then extract only the timestamp, the `jq` command must use `select` for conditional filtering and then dot notation to project the desired field.

Ajq '.time' app.log

`jq '.time' app.log` would extract the `time` field from every log entry without applying any filters for user or method, which does not match the requirement.

Bjq 'select(.user=="user1" and .method=="GET").time' app.logCorrect

The `jq 'select(.user=="user1" and .method=="GET").time' app.log` command correctly uses `select` to filter for objects where the `user` field is "user1" AND the `method` field is "GET", then uses `.time` to project only the value of the `time` field for the selected entries, matching the desired output.

Cjq 'select(.user=="user1" and .method=="GET")' app.log

`jq 'select(.user=="user1" and .method=="GET')' app.log` would correctly filter the log entries but would return the entire JSON object for matching entries, not just the `time` field as required.

Djq 'select(.user=="user1" and .GET).time' app.log

`jq 'select(.user=="user1" and .GET).time' app.log` incorrectly attempts to filter for `.GET` as a property rather than checking the value of the `method` property, which would result in incorrect filtering or a syntax error.

Concept tested: JSON parsing and filtering with jq.

Source: https://stedolan.github.io/jq/manual/

Topics

#jq#JSON processing#Log parsing#Command-line tools

Community Discussion

No community discussion yet for this question.

Full 300-910 Practice