@@ -21,23 +21,42 @@ module.exports = (robot) ->
2121 grafana_host = process .env .HUBOT_GRAFANA_HOST
2222 grafana_api_key = process .env .HUBOT_GRAFANA_API_KEY
2323
24- robot .respond / (?:grafana| graph| graf) (?:dash| dashboard| db) ([A-Za-z0-9\-\: _] + )(| [ A-Za-z0-9\- \+ ] + ) ? ( | [ A-Za-z0-9\- \+ ] + )? / i , (msg ) ->
24+ robot .respond / (?:grafana| graph| graf) (?:dash| dashboard| db) ([A-Za-z0-9\-\: _] + )(. * )? / i , (msg ) ->
2525
2626 slug = msg .match [1 ].trim ()
27- from = msg .match [2 ] || ' now-6h'
28- to = msg .match [3 ] || ' now'
29- pid = false
27+ remainder = msg .match [2 ]
28+ timespan = {
29+ from : ' now-6h'
30+ to : ' now'
31+ }
32+ variables = " "
33+ pid = false
3034
3135 # Parse out a specific panel
3236 if / \: / .test slug
3337 parts = slug .split (' :' )
3438 slug = parts[0 ]
3539 pid = parseInt parts[1 ], 10
3640
41+ # Check if we have any extra fields
42+ if remainder
43+ # The order we apply non-variables in
44+ timeFields = [" from" , " to" ]
45+
46+ for part in remainder .trim ().split " "
47+
48+ # Check if it's a variable or part of the timespan
49+ if part .indexOf (" =" ) >= 0
50+ variables = " #{ variables} &var-#{ part} "
51+
52+ # Only add to the timespan if we haven't already filled out from and to
53+ else if timeFields .length > 0
54+ timespan[timeFields .shift ()] = part .trim ()
55+
3756 robot .logger .debug msg .match
3857 robot .logger .debug slug
39- robot .logger .debug from
40- robot .logger .debug to
58+ robot .logger .debug timespan
59+ robot .logger .debug variables
4160 robot .logger .debug pid
4261
4362 # Call the API to get information about this dashboard
@@ -77,12 +96,8 @@ module.exports = (robot) ->
7796 if pid && pid != panel .id
7897 continue
7998
80- # Clean up attributes
81- from = from .trim ()
82- to = to .trim ()
83-
84- imageUrl = " #{ grafana_host} /render/#{ apiEndpoint} /db/#{ slug} /?panelId=#{ panel .id } &width=1000&height=500&from=#{ from } &to=#{ to} "
85- link = " #{ grafana_host} /dashboard/db/#{ slug} /?panelId=#{ panel .id } &fullscreen&from=#{ from } &to=#{ to} "
99+ imageUrl = " #{ grafana_host} /render/#{ apiEndpoint} /db/#{ slug} /?panelId=#{ panel .id } &width=1000&height=500&from=#{ timespan .from } &to=#{ timespan .to }#{ variables} "
100+ link = " #{ grafana_host} /dashboard/db/#{ slug} /?panelId=#{ panel .id } &fullscreen&from=#{ timespan .from } &to=#{ timespan .to }#{ variables} "
86101 msg .send " #{ formatTitleWithTemplate (panel .title , template_map)} : #{ imageUrl} - #{ link} "
87102
88103 robot .respond / (?:grafana| graph| graf) list/ i , (msg ) ->
0 commit comments