Skip to content

Instantly share code, notes, and snippets.

@dsingley
Last active August 29, 2015 13:56
Show Gist options
  • Save dsingley/9160450 to your computer and use it in GitHub Desktop.
Save dsingley/9160450 to your computer and use it in GitHub Desktop.
#!/bin/bash
LOGGLY_TOKEN=''
TAG='ifup'
URL="https://logs-01.loggly.com/inputs/${LOGGLY_TOKEN}/tag/${TAG}"
interfaces='{'
for interface in $(ip addr | awk '/state UP/ {print $2}' | sed -e 's/://'); do
ip_address=$(ip addr show ${interface} 2>/dev/null | awk '/inet / {print $2}' | sed -e 's/\/.*//')
mac_address=$(ip addr show ${interface} 2>/dev/null | awk '/link\/ether/ {print $2}')
interfaces="${interfaces} \"${interface}\": { \"ip-address\": \"${ip_address}\", \"mac-address\": \"${mac_address}\" }"
done
interfaces_json="$(echo ${interfaces} | sed -e 's/} "/}, "/g') }"
if [ "${interfaces}" != '{ }' ]; then
uptime=$(uptime | sed -e 's/.*up //' -e 's/,.*//')
uname_json="{
\"kernel-name\": \"$(uname -s)\",
\"nodename\": \"$(uname -n)\",
\"kernel-release\": \"$(uname -r)\",
\"kernel-version\": \"$(uname -v)\",
\"machine\": \"$(uname -m)\",
\"processor\": \"$(uname -p)\",
\"hardware-platform\": \"$(uname -i)\",
\"operating-system\": \"$(uname -o)\"
}"
internet_ip_info_json=$(curl -s http://ipinfo.io)
combined_json="{
\"timestamp\": \"$(date -u +'%Y-%m-%dT%H:%M:%S.%6NZ')\",
\"uptime\": \"${uptime}\",
\"hostname\": \"$(hostname -f)\",
\"interfaces\": ${interfaces_json},
\"uname\": ${uname_json},
\"internet-ip-info\": ${internet_ip_info_json}
}"
tempfile=$(mktemp)
echo ${combined_json} > ${tempfile}
curl -s -X POST -T ${tempfile} ${URL}
rm -f ${tempfile}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment