Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON output for inspec check #411

Merged
merged 12 commits into from
Feb 4, 2016
Merged

JSON output for inspec check #411

merged 12 commits into from
Feb 4, 2016

Conversation

chris-rock
Copy link
Contributor

updated description

Current:

I, [2016-02-03T11:41:48.142745 #6714]  INFO -- : Checking profile in examples/profile
I, [2016-02-03T11:41:48.142902 #6714]  INFO -- : Metadata OK.
I, [2016-02-03T11:41:48.142962 #6714]  INFO -- : Found 3 controls.
I, [2016-02-03T11:41:48.142985 #6714]  INFO -- : Verify all controls in  examples/profile/controls/example.rb
W, [2016-02-03T11:41:48.143002 #6714]  WARN -- : Control profile/tmp-2.0 has no title
W, [2016-02-03T11:41:48.143012 #6714]  WARN -- : Control profile/tmp-2.0 has no description
I, [2016-02-03T11:41:48.143021 #6714]  INFO -- : Verify all controls in  examples/profile/controls/gordon.rb

New CLI Table output

Summary
-------
Location: examples/profile
Profile:  profile
Controls: 3
Time:     iso-timestamp

Details
-------
examples/profile/controls/example.rb:16:0: W: Control `profile/tmp-2.0` has no description

New JSON result

{
  "summary" : {
    valid: true
    timestamp: "iso-timestamp"
    location: "examples/profile"
    profile: "profile"
    controls: 3
  },
  errors: [],
  warnings: [{
    file: "examples/profile/controls/example.rb"
    line: 16
    column: 0
    id: profile/tmp-2.0
    msg: "has no description"
  }]
}

includes a very naive json streaming implementation for the logger

@chris-rock chris-rock added the Type: Enhancement Improves an existing feature label Feb 3, 2016
@arlimus
Copy link
Contributor

arlimus commented Feb 3, 2016

Great idea! Should we turn this into a JSON stream log or stick to JSON (as it is now)?

@chris-rock
Copy link
Contributor Author

@arlimus Great idea, just turned it into a line delimited JSON as described here: https://en.wikipedia.org/wiki/JSON_Streaming. You can use it with jq now.

inspec check examples/profile --format=json | jq --compact-output .
{"progname":null,"severity":"INFO","time":"2016-02-03 08:47:49 +0100","msg":"Checking profile in examples/profile"}
{"progname":null,"severity":"INFO","time":"2016-02-03 08:47:49 +0100","msg":"Metadata OK."}
{"progname":null,"severity":"INFO","time":"2016-02-03 08:47:49 +0100","msg":"Found 2 rules."}
{"progname":null,"severity":"INFO","time":"2016-02-03 08:47:49 +0100","msg":"Rule definitions OK."}

@chris-rock
Copy link
Contributor Author

This raises some conceptual issues:

  • logger output to stdout
  • command output to stdout

We have multiple options to format our response and our logging

  1. command output: human-readable or json structured response
  2. logging output: humand-readable stdout or json

Therefore we should have different options to control the output:
--format=json - how to format the command response
--log-format=json - how to format the logs
--log-file stderr - where we are logging to

@chris-rock chris-rock changed the title add json stream logger for inspec check JSON output for inspec check Feb 3, 2016
@chris-rock chris-rock changed the title JSON output for inspec check WIP: JSON output for inspec check Feb 3, 2016
@chris-rock chris-rock changed the title WIP: JSON output for inspec check JSON output for inspec check Feb 4, 2016
@jcreedcmu
Copy link
Contributor

Looks good, and works with the https://github.com/chef/chef-compliance/pull/428 I just pushed.

jcreedcmu added a commit that referenced this pull request Feb 4, 2016
@jcreedcmu jcreedcmu merged commit 3a704b5 into master Feb 4, 2016
@jcreedcmu jcreedcmu deleted the chris-rock/check-json branch February 4, 2016 21:18
@chris-rock chris-rock added this to the 0.9.12 milestone Feb 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants