Skip to content

Instantly share code, notes, and snippets.

@glisha
Created June 24, 2012 09:19
Show Gist options
  • Save glisha/2982606 to your computer and use it in GitHub Desktop.
Save glisha/2982606 to your computer and use it in GitHub Desktop.
Number of lan devices to cosm.com
#!/bin/bash
## Send number of arp entries to cosm for graphing.
##
## It tries to guess the number of people currently present in
## the Hacklab (every person has on average one lan connected device) by
## counting the arp entries on the lan interface of the router.
##
## Graph: https://cosm.com/feeds/64676
## cron:
## */6 * * * * /home/kikadevices/kika-devices-cosm/lan_devices_to_cosm.sh >> /home/kikadevices/kika-devices-cosm/lan_devices_to_cosm.log 2>&1
## cron:
##
## Configure cosm.com
FEED_ID="64676"
DATAPOINT_ID="lan_devices"
COSM_URL="http://api.cosm.com/v2/feeds/$FEED_ID/datastreams/$DATAPOINT_ID/datapoints"
COSM_API="<MY_COSM_API_KEY"
## Collect the data
#list of mac addresses that are allways in the hacklab seperated by a pipe
# "dvoarak|glisha_rpi"
EXCLUDE_LIST="00:0c:76:5d:1c:9c|b8:27:eb:1b:dd:cf"
NUM_LAN_DEVICES=`/usr/sbin/arp -n -i eth1| grep -Ev "HWtype|incomplete" | grep -iEv "$EXCLUDE_LIST" | wc -l`
CURRENT_TIME=`/bin/date --iso-8601=ns`
echo "$CURRENT_TIME: $NUM_LAN_DEVICES"
## Send it to cosm.com
cat <<EOF | /usr/bin/curl --silent --request POST --data-binary @- --header "X-ApiKey: $COSM_API" $COSM_URL
{
"datapoints":[
{"at":"$CURRENT_TIME","value":"$NUM_LAN_DEVICES"}
]
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment