hubot-grafana 3.1.4 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,13 +35,13 @@ Then add **hubot-grafana** to your `external-scripts.json`:
35
35
  | `HUBOT_GRAFANA_DEFAULT_TIME_ZONE` | No | Default time zone for rendered images (defaults to `""`) |
36
36
  | `HUBOT_GRAFANA_ORG_ID` | No | Default organization id, need for image rendering in new versions of Grafana (defaults to `""`) |
37
37
  | `HUBOT_GRAFANA_API_ENDPOINT` | No | Default rendering api endpoint, need for image rendering in new versions of Grafana (defaults to `d-solo`) |
38
+ | `HUBOT_GRAFANA_USE_THREADS` | No | When set to any value, graphs are sent in thread instead of as new message (only Slack supports this for now). |
38
39
  | `HUBOT_GRAFANA_MAX_RETURNED_DASHBOARDS` | No | Count of dashboards to return to prevent chat flood (defaults to `25`) |
39
40
 
40
41
  ^ _Not required when `HUBOT_GRAFANA_PER_ROOM` is set to 1._
41
42
 
42
43
  ^^ _Not required for `auth.anonymous` Grafana configurations. All other authentication models will require a user-specific API key._
43
44
 
44
-
45
45
  ### Image Hosting Configuration
46
46
 
47
47
  By default, *hubot-grafana* will assume you intend to render the image, unauthenticated, directly from your Grafana instance. The limitation is that you will only receive a link to those images, but they won't appear as images in most circumstances in your chat client.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hubot-grafana",
3
3
  "description": "Query Grafana dashboards",
4
- "version": "3.1.4",
4
+ "version": "3.2.0",
5
5
  "author": "Stephen Yeargin <stephen@yearg.in>",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -27,6 +27,7 @@
27
27
  # HUBOT_GRAFANA_S3_SECRET_ACCESS_KEY - Optional; Secret access key for S3
28
28
  # HUBOT_GRAFANA_S3_PREFIX - Optional; Bucket prefix (useful for shared buckets)
29
29
  # HUBOT_GRAFANA_S3_REGION - Optional; Bucket region (defaults to us-standard)
30
+ # HUBOT_GRAFANA_USE_THREADS - Optional; When set to any value, graphs are sent in thread instead of as new message.
30
31
  # HUBOT_SLACK_TOKEN - Optional; Token to connect to Slack (already configured with the adapter)
31
32
  # ROCKETCHAT_URL - Optional; URL to your Rocket.Chat instance (already configured with the adapter)
32
33
  # ROCKETCHAT_USER - Optional; Bot username (already configured with the adapter)
@@ -76,6 +77,7 @@ module.exports = (robot) ->
76
77
  rocketchat_user = process.env.ROCKETCHAT_USER
77
78
  rocketchat_password = process.env.ROCKETCHAT_PASSWORD
78
79
  max_return_dashboards = process.env.HUBOT_GRAFANA_MAX_RETURNED_DASHBOARDS or 25
80
+ use_threads = process.env.HUBOT_GRAFANA_USE_THREADS or false
79
81
 
80
82
  if rocketchat_url && ! rocketchat_url.startsWith 'http'
81
83
  rocketchat_url = 'http://' + rocketchat_url
@@ -395,6 +397,7 @@ module.exports = (robot) ->
395
397
 
396
398
  # Format the title with template vars
397
399
  formatTitleWithTemplate = (title, template_map) ->
400
+ title = '' unless title
398
401
  title.replace /\$\w+/g, (match) ->
399
402
  if template_map[match]
400
403
  return template_map[match]
@@ -406,6 +409,7 @@ module.exports = (robot) ->
406
409
  switch robot.adapterName
407
410
  # Slack
408
411
  when 'slack'
412
+ msg.message.thread_ts = msg.message.rawMessage.ts if use_threads
409
413
  msg.send {
410
414
  attachments: [
411
415
  {
@@ -521,7 +525,7 @@ module.exports = (robot) ->
521
525
  request.post testAuthData, (err, httpResponse, slackResBody) ->
522
526
  if err
523
527
  robot.logger.error err
524
- msg.send "#{title} - [Slak auth.test Error - invalid token/can't fetch team url] - #{link}"
528
+ msg.send "#{title} - [Slack auth.test Error - invalid token/can't fetch team url] - #{link}"
525
529
  else
526
530
  slack_url = JSON.parse(slackResBody)["url"]
527
531
 
@@ -536,6 +540,9 @@ module.exports = (robot) ->
536
540
  file: grafanaDashboardRequest()
537
541
  filetype: 'png'
538
542
 
543
+ # Post images in thread if configured
544
+ uploadData['formData']['thread_ts'] = msg.message.rawMessage.ts if use_threads
545
+
539
546
  # Try to upload the image to slack else pass the link over
540
547
  request.post uploadData, (err, httpResponse, body) ->
541
548
  res = JSON.parse(body)