grafana.coffee 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Description:
  2. # A way to interact with the Google Images API.
  3. #
  4. # Commands:
  5. # hubot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
  6. # hubot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
  7. # hubot mustache me <url> - Adds a mustache to the specified URL.
  8. # hubot mustache me <query> - Searches Google Images for the specified query and mustaches it.
  9. module.exports = (robot) ->
  10. robot.hear /grafana (.*)/i, (msg) ->
  11. sendUrl msg.match[1]
  12. robot.router.get '/hubot/test', (req, res) ->
  13. sendUrl()
  14. res.send 'OK '
  15. imageMe = (msg, cb) ->
  16. cb 'http://localhost:3000/render/dashboard/solo/grafana-play-home?from=now-1h&to=now&panelId=4&fullscreen'
  17. sendUrl = (params) ->
  18. https = require 'https'
  19. querystring = require 'querystring'
  20. opts = params.split(' ')
  21. dashboard = opts[0]
  22. panelId = opts[1]
  23. from = opts[2]
  24. imageUrl = "http://localhost:3000/render/dashboard/solo/#{dashboard}/?panelId=#{panelId}"
  25. link = "http://localhost:3000/dashboard/db/#{dashboard}/?panelId=#{panelId}&fullscreen"
  26. if from
  27. imageUrl += "&from=#{from}"
  28. link += "&from=#{from}"
  29. console.log 'imageUrl: ' + imageUrl
  30. hipchat = {}
  31. hipchat.format = 'json'
  32. hipchat.auth_token = process.env.HUBOT_HIPCHAT_TOKEN
  33. console.log 'token: ' + hipchat.auth_token
  34. hipchat.room_id = '877465'
  35. hipchat.message = "<a href='#{link}'><img src='#{imageUrl}'></img></a>"
  36. hipchat.from = "hubot"
  37. hipchat.message_format = "html"
  38. params = querystring.stringify(hipchat)
  39. path = "/v1/rooms/message/?#{params}"
  40. data = ''
  41. https.get {host: 'api.hipchat.com', path: path}, (res) ->
  42. res.on 'data', (chunk) ->
  43. data += chunk.toString()
  44. res.on 'end', () ->
  45. json = JSON.parse(data)
  46. console.log "Hipchat response ", data