Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env ruby
# Speedtest cli to ifttt.com wrapper
# based on https://github.com/HenrikBengtsson/speedtest-cli-extras
# More: https://www.iamyourfather.de/dsl-speedtest-mit-dem-raspberry-pi (german)
# Original: http://makezine.com/projects/send-ticket-isp-when-your-internet-drops/
require 'json'
secret_key = "XXXXXXXXXXX"
speedtest = `/usr/local/bin/speedtest-cli --share`
upload = speedtest.scan(/Upload: ([0-9\.]{3,5})/)[0][0]
download = speedtest.scan(/Download: ([0-9\.]{3,5})/)[0][0]
ping = speedtest.scan(/]: ([0-9\.]{3,6})/)[0][0]
share = speedtest.scan(/Share results: (.*)/)[0][0]
json = {value1: ping, value2: download, value3: upload}
`curl -X POST -H \"Content-Type: application/json\" \
-d \"#{JSON[json].to_s.gsub("\"","\\\"")}\" \
https://maker.ifttt.com/trigger/speedtest/with/key/#{secret_key} > /dev/null`
File.open("/tmp/speedtest.log", "a") { |file| file.puts("#{Time.now}\
- Ping: #{ping}\
- Download: #{download}\
- Upload: #{upload}\
- Share: #{share}") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment