Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- COOKIES="/tmp/jar.txt"
- STATIC="/tmp/edge-static.json"
- DYNAMIC="/tmp/edge-dynamic.json"
- OUTPUT="/tmp/dhcp"
- USERNAME="<USERNAME>"
- PASSWORD="<PASSWORD>"
- if [[ -f "$STATIC" ]]; then
- rm $STATIC
- fi
- if [[ -f "$DYNAMIC" ]]; then
- rm $DYNAMIC
- fi
- if [[ -f "$OUTPUT" ]]; then
- MD5OLD=`md5sum $OUTPUT | awk '{print $1}'`
- rm $OUTPUT
- fi
- /usr/bin/curl -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "username=$USERNAME&password=$PASSWORD" https://10.2.0.1 --insecure -c $COOKIES
- /usr/bin/curl -s "https://10.2.0.1/api/edge/data.json?data=dhcp_leases" --insecure -b $COOKIES > $DYNAMIC
- /usr/bin/curl -s "https://10.2.0.1/api/edge/get.json" --insecure -b $COOKIES > $STATIC
- # for host in `jq -r '.GET.service."dhcp-server"."shared-network-name"'.\"$server\"'.subnet'.\"$subnet\"'."static-mapping" | to_entries[] | [.key,.value."ip-address"] | @csv' $STATIC 2> /dev/null` ; do
- for server in `/usr/bin/jq --raw-output '.GET.service."dhcp-server"."shared-network-name" | to_entries[] | .key ' $STATIC`; do
- if [[ ! -z "$server" ]]; then
- for subnet in `/usr/bin/jq -r '.GET.service."dhcp-server"."shared-network-name"'.\"$server\"'.subnet | to_entries[] | .key' $STATIC 2> /dev/null`; do
- HOSTNAME=`/usr/bin/jq -r '.GET.service."dhcp-server"."shared-network-name"'.\"$server\"'.subnet'.\"$subnet\"'."static-mapping"| to_entries[] | .key' $STATIC 2> /dev/null`
- for hostname in $HOSTNAME; do
- IP=`/usr/bin/jq -r '.GET.service."dhcp-server"."shared-network-name"'.\"$server\"'.subnet.'\"$subnet\"'."static-mapping"'.\"$hostname\"'."ip-address"' $STATIC`
- echo "\"$IP\",\"static\",\"$server\",\"$hostname\"" >> $OUTPUT
- done
- done
- for ip in `/usr/bin/jq -r '.output."dhcp-server-leases"'.\"$server\"' | to_entries[] | .key' $DYNAMIC 2> /dev/null` ; do
- HOSTNAME=`/usr/bin/jq -r '.output."dhcp-server-leases"'.\"$server\".\"$ip\"'."client-hostname"' $DYNAMIC 2> /dev/null`
- EXPIRATION=`/usr/bin/jq -r '.output."dhcp-server-leases"'.\"$server\".\"$ip\"'."expiration"' $DYNAMIC 2> /dev/null | date '+%Y-%m-%d %H:%M:%S'`
- echo "\"$ip\",\"dynamic\",\"$server\",\"$HOSTNAME\"" >> $OUTPUT
- done
- fi
- done
- MD5NEW="`md5sum $OUTPUT | awk '{print $1}'`"
- if [ ! "$MD5OLD" == "$MD5NEW" ]; then
- /usr/bin/mysql --host=10.2.0.10 --port=3307 -u dhcp-update grafana -e "truncate table dhcp"
- /usr/bin/mysqlimport -s --local --fields-optionally-enclosed-by="\"" --fields-terminated-by=, --host 10.2.0.10 --port 3307 -u dhcp-update grafana /tmp/dhcp
- echo "UPDATED `date`" >> /tmp/dhcp-update
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement