#!/bin/bash

. sbs/exec/config/allg
. $(dirname $BASH_SOURCE)/config/functions

vacols="hostname,domain,nameserver,search,gw,readtime";
labels="Server,Domain,Nameserver,Suchdomain,Gateway,Lesezeit";
json_writeheader "$vacols" "$labels" "readtime:1000" "";

hostname=$(hostname)

prog='/inet[^6]/ { found=1; printf("addr='"'"'%s'"'"'; bcast='"'"'%s'"'"'; mask='"'"'%s'"'"'\n", $2, $6, $4); }
      /inet6/    { found=1; printf("addr='"'"'%s'"'"'; bcast='"'"''"'"'; mask='"'"'%s'"'"'\n", $2, $4); }
      END        { if ( ! found ) printf("addr='"'"''"'"'; bcast='"'"''"'"'; mask='"'"''"'"'\n");}'

        gw=`route -n             | awk 'BEGIN { gws=""; } /^0\.0\.0\.0/ { gws = gws $2 "," } END { print substr(gws, 1, length(gws)-1) }'`
    search=`cat /etc/resolv.conf | awk '/^search[ \t]/ { print $2 }'`
nameserver=$(cat /etc/resolv.conf | awk 'BEGIN { found=""; } /^nameserver[ \t]+/ { gsub(/%.*$/,"",$2); printf("%s%s",found,$2); found = "," }')
 
   domain=`hostname --domain`
  
echo '  "values"  : ['
json_writedata "$hostname" "$domain" "$nameserver" "$search" "$gw" "$acttime"
echo ']'

exit 0
