0

What I want is this:

  • netcat to the server, which streams json formatted loglines.
  • pipe the output of nc to "something" that will format the json as plaintext, in a customizable format (thinking something like perl or python here).
  • allow "something" to be greppable.

My small attempts at piping the output of nc to something else leads to the server outputting "Broken pipe".

c0dem4gnetic
  • 165
  • 7

2 Answers2

1

I'd start looking at the python JSON processors, to start you can format it in "pretty" style simply:

| python -mjson.tool

and there are many people who have extended on that, here are a few examples.

NickW
  • 10,183
  • 1
  • 18
  • 26
  • This one worked really nice and would be a good starting point on formatting the output. As stated in another comment, the issue I'm having is something that I suspect has to do with nc. – c0dem4gnetic Mar 26 '13 at 17:00
  • Yeah, remember all JSON is not created equal. – NickW Mar 26 '13 at 17:01
1

I use jq to parse JSON on the command line. I'm aware that your question asks for something to render it in plaintext for grepping, but I think this is closer to what you're trying to accomplish.

For instance:

{"chef_server": 
    {
    "server_url": "http://localhost:4000"
    },"run_list": 
        [ 
        "recipe[apt::default]",
        "recipe[build-essential::default]",
        "recipe[chef-server::rubygems-install]" 
        ]
    }

Can be parsed to yield:

    tristan.local]$  ~  cat chef.json| jq -c '.run_list[]' 
    "recipe[apt::default]"
    "recipe[build-essential::default]"
    "recipe[chef-server::rubygems-install]"

Check out the tutorial, it's quite useful.