Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B-9 - Sumologic get widget from dashboard #10

Open
wants to merge 1 commit into
base: payou-playground-graph-img-generation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions scripts/hubot-sumologic-image-widget/widgetFinder.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ sumoToken = process.env.SUMOLOGIC_TOKEN || "ZnJvbnRlbmRAdGVhZHMudHY6RzhMZGNK
class WidgetFinder
constructor: (@name, @robot) ->
@config = _.get(mapping, @name)
if _.isUndefined(@config)
robot.logger.error "The widget '#{@name}' isn't mapped yet !"

exists: () ->
not _.isUndefined(@config)
Expand Down
49 changes: 44 additions & 5 deletions scripts/sumo-main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,50 @@ WidgetFinder = require './hubot-sumologic-image-widget/widgetFinder'
module.exports = (robot) ->

robot.respond /sumo (.*)/i, (result) ->
widget = new WidgetFinder(result.match[1], robot)
if widget.exists()
result.reply "Sure ! I process it and send you this one here !"
widget.getData(result.message)
argz = result.match[1].split(' ')
n = argz.length
# WARNING: Slack replaces "--" with "-" !
# FIXME: do this with a regex

verbose = false
if argz.indexOf('-v') > -1
verboseOptIndex = argz.indexOf('-v')
else
verboseOptIndex = argz.indexOf('-verbose')

if verboseOptIndex > -1
verbose = true
argz.splice(verboseOptIndex, 1) # remove it from argz
n = argz.length

if argz.indexOf('-a') > -1
addOptIndex = argz.indexOf('-a')
else
result.reply "I don't know this widget sorry... :disappointed:"
addOptIndex = argz.indexOf('—add')

if addOptIndex > -1
# add a widget to config
argz.splice(addOptIndex, 1) # remove it from argz
n = argz.length

# DIRTY!!!
# we should have --name "name" etc
if n >= 4
name = argz[0]
dashboardId = argz[1]
widgetId = argz[2]
type = argz[3]

result.reply "Ok, I'll remember the widget " + name + " (id " + widgetId + " - dashboardId " + dashboardId + " - type " + type + ")."
else
result.reply "To add a widget, I need 4 pieces of information!"

else
if n > -1
widgetName = argz[n-1]
widget = new WidgetFinder(widgetName, robot)
if widget.exists()
result.reply "I know this widget, let me grab it for you ;)"
widget.getData(result.message)
else
result.reply "I don't know this widget sorry... :disappointed:"
4 changes: 2 additions & 2 deletions scripts/welcome.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ getRandomItem = (items) => items[Math.floor(Math.random()*items.length)]

module.exports = (robot) ->

robot.messageRoom "general", "Hubot is back !!!!!! :banana:"
# robot.messageRoom "general", "Hubot is back !!!!!! :banana:"

responses = [
"uk:Hello!"
Expand Down Expand Up @@ -54,4 +54,4 @@ module.exports = (robot) ->
res.reply ":flag-" + randomResponse[0] + ": " + randomResponse[1]

robot.hear /(bichour)/i, (res) ->
res.reply "Bichour toi"
res.reply "Bichour toi"