Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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".

share|improve this question
    
What are you trying to accomplish? Would parsing the JSON be acceptable or do you prefer to grep? –  tristan Mar 26 '13 at 11:28

2 Answers 2

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.

share|improve this answer
    
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

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.

share|improve this answer
    
Neat tool! Although I suspect that this won't work with a nc pipe (see my edit) –  c0dem4gnetic Mar 26 '13 at 16:58
    
Ah, track down why you're getting disconnected when trying to stream data first. –  tristan Mar 26 '13 at 18:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.