papertrail / papertrail-cli

Command-line client for Papertrail hosted syslog & app log management service
http://papertrailapp.com/
MIT License
427 stars 46 forks source link

add papertrail-systems command to list systems #98

Open samuelcolvin opened 6 years ago

samuelcolvin commented 6 years ago

currently I'm using

papertrail-systems() {
    curl -s -H "X-Papertrail-Token: `cat ~/.papertrail.yml | sed -r 's/token://'`" https://papertrailapp.com/api/v1/systems.json | python -m json.tool | grep '"name":' | sed -r 's/ +"name": "(.*)",/\1/'
}

in my .bashrc file.

But it was a faff to setup, would be greate if there was a simpler way of getting this.

bobpaul commented 4 years ago

I agree it should be added. But here it is using jq to parse json and yj to convert yml to json (so it can be parsed with jq). While less portable, it's a tad more elegant then regex:

papertrail-systems() {                                                                              
    curl -s -H "X-Papertrail-Token: `cat ~/.papertrail.yml | yj | jq --raw-output .token`" https://papertrailapp.com/api/v1/systems.json | jq --raw-output .[].name
}