#!/usr/bin/sh
[[ $1 == -t ]] && pretty=( column -t -s $'\t' -T 5 ) || pretty=( cat )
cols=( "$@" ); [[ -z $cols ]] && cols=( last_check plugin_output )
{ printf 'GET hosts\nColumns: host_name state %s\nOutputFormat: csv\nSeparators: 10 9 44 124\n' "${cols[*]}" |unixcat /var/spool/nagios/cmd/live.sock |sed -re 's,^([^\t]+\t),\1--host--\t,'; printf 'GET services\nColumns: host_name description state %s\nOutputFormat: csv\nSeparators: 10 9 44 124\n' "${cols[*]}" |unixcat /var/spool/nagios/cmd/live.sock; } |sort -t $'\t' -k 1,2 |"${pretty[@]}"
