hubot-grafana 3.0.1 → 3.1.2
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/package.json +7 -8
- package/src/grafana.coffee +10 -2
- package/test/grafana-s3-test.coffee +10 -14
- package/test/grafana-v8-test.coffee +5 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hubot-grafana",
|
|
3
3
|
"description": "Query Grafana dashboards",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.1.2",
|
|
5
5
|
"author": "Stephen Yeargin <stephen@yearg.in>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -25,16 +25,15 @@
|
|
|
25
25
|
"hubot": "^3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"chai": "^4.3.
|
|
28
|
+
"chai": "^4.3.6",
|
|
29
29
|
"coffee-script": "^1.12.7",
|
|
30
30
|
"hubot-test-helper": "^1.9.0",
|
|
31
|
-
"husky": "^
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"release-it": "^14.10.0",
|
|
31
|
+
"husky": "^7.0.4",
|
|
32
|
+
"mocha": "^9.2.2",
|
|
33
|
+
"nock": "^13.2.4",
|
|
34
|
+
"release-it": "^14.13.1",
|
|
36
35
|
"require-dir": "^1.2.0",
|
|
37
|
-
"sinon": "^
|
|
36
|
+
"sinon": "^13.0.1",
|
|
38
37
|
"sinon-chai": "^3.7.0",
|
|
39
38
|
"travis-cov": "^0.2.5"
|
|
40
39
|
},
|
package/src/grafana.coffee
CHANGED
|
@@ -228,6 +228,7 @@ module.exports = (robot) ->
|
|
|
228
228
|
|
|
229
229
|
# Return dashboard rows
|
|
230
230
|
panelNumber = 0
|
|
231
|
+
returnedCount = 0
|
|
231
232
|
for row in data.rows
|
|
232
233
|
for panel in row.panels
|
|
233
234
|
robot.logger.debug panel
|
|
@@ -245,6 +246,10 @@ module.exports = (robot) ->
|
|
|
245
246
|
if pname && panel.title.toLowerCase().indexOf(pname) is -1
|
|
246
247
|
continue
|
|
247
248
|
|
|
249
|
+
# Skip if we have already returned max count of dashboards
|
|
250
|
+
if returnedCount > max_return_dashboards
|
|
251
|
+
continue
|
|
252
|
+
|
|
248
253
|
# Build links for message sending
|
|
249
254
|
title = formatTitleWithTemplate(panel.title, template_map)
|
|
250
255
|
uid = dashboard.dashboard.uid
|
|
@@ -255,8 +260,11 @@ module.exports = (robot) ->
|
|
|
255
260
|
imageUrl += "&orgId=#{encodeURIComponent query.orgId}"
|
|
256
261
|
link = "#{endpoint.host}/d/#{uid}/?panelId=#{panel.id}&fullscreen&from=#{timespan.from}&to=#{timespan.to}#{variables}"
|
|
257
262
|
|
|
258
|
-
|
|
259
|
-
|
|
263
|
+
sendDashboardChart msg, title, imageUrl, link
|
|
264
|
+
returnedCount += 1
|
|
265
|
+
|
|
266
|
+
if returnedCount == 0
|
|
267
|
+
return sendError "Could not locate desired panel.", msg
|
|
260
268
|
|
|
261
269
|
# Process the bot response
|
|
262
270
|
sendDashboardChart = (msg, title, imageUrl, link) ->
|
|
@@ -21,20 +21,13 @@ describe 's3', ->
|
|
|
21
21
|
nock('https://play.grafana.org')
|
|
22
22
|
.get('/api/dashboards/uid/AAy9r_bmk')
|
|
23
23
|
.replyWithFile(200, __dirname + '/fixtures/v8/dashboard-monitoring-default.json')
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
width: 1000,
|
|
32
|
-
height: 500,
|
|
33
|
-
from: 'now-6h',
|
|
34
|
-
to: 'now',
|
|
35
|
-
"var-server": 'ww3.example.com'
|
|
36
|
-
)
|
|
37
|
-
.replyWithFile(200, __dirname + '/fixtures/v8/dashboard-monitoring-default.png')
|
|
24
|
+
|
|
25
|
+
for i in [3,7,8]
|
|
26
|
+
nock('https://play.grafana.org')
|
|
27
|
+
.defaultReplyHeaders({ 'Content-Type': 'image/png' })
|
|
28
|
+
.get('/render/d-solo/AAy9r_bmk/')
|
|
29
|
+
.query({ panelId: i, width: 1000, height: 500, from: 'now-6h', to: 'now', "var-server": 'ww3.example.com' })
|
|
30
|
+
.replyWithFile(200, __dirname + '/fixtures/v8/dashboard-monitoring-default.png')
|
|
38
31
|
|
|
39
32
|
afterEach ->
|
|
40
33
|
@room.destroy()
|
|
@@ -50,6 +43,7 @@ describe 's3', ->
|
|
|
50
43
|
nock('https://graf.s3.amazonaws.com')
|
|
51
44
|
.filteringPath(/[a-z0-9]+\.png/g, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.png')
|
|
52
45
|
.put('/grafana/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.png')
|
|
46
|
+
.times(3)
|
|
53
47
|
.reply(200)
|
|
54
48
|
|
|
55
49
|
it 'should respond with a png graph in the default s3 region', (done) ->
|
|
@@ -77,6 +71,7 @@ describe 's3', ->
|
|
|
77
71
|
nock('https://graf.custom.s3.endpoint.com')
|
|
78
72
|
.filteringPath(/[a-z0-9]+\.png/g, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.png')
|
|
79
73
|
.put('/grafana/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.png')
|
|
74
|
+
.times(3)
|
|
80
75
|
.reply(200)
|
|
81
76
|
|
|
82
77
|
after ->
|
|
@@ -107,6 +102,7 @@ describe 's3', ->
|
|
|
107
102
|
nock('https://s3.amazonaws.com')
|
|
108
103
|
.filteringPath(/[a-z0-9]+\.png/g, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.png')
|
|
109
104
|
.put('/graf/grafana/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.png')
|
|
105
|
+
.times(3)
|
|
110
106
|
.reply(200)
|
|
111
107
|
|
|
112
108
|
after ->
|
|
@@ -91,6 +91,11 @@ describe 'grafana v8', ->
|
|
|
91
91
|
expect(room.messages).to.eql [
|
|
92
92
|
[ 'alice', 'hubot graf db 97PlYC7Mk' ]
|
|
93
93
|
[ 'hubot', "Grafana diagram architecture: https://play.grafana.org/render/d-solo/97PlYC7Mk/?panelId=13&width=1000&height=500&from=now-6h&to=now - https://play.grafana.org/d/97PlYC7Mk/?panelId=13&fullscreen&from=now-6h&to=now"]
|
|
94
|
+
[ 'hubot', 'server requests: https://play.grafana.org/render/d-solo/97PlYC7Mk/?panelId=2&width=1000&height=500&from=now-6h&to=now - https://play.grafana.org/d/97PlYC7Mk/?panelId=2&fullscreen&from=now-6h&to=now' ]
|
|
95
|
+
[ 'hubot', 'client side full page load: https://play.grafana.org/render/d-solo/97PlYC7Mk/?panelId=5&width=1000&height=500&from=now-6h&to=now - https://play.grafana.org/d/97PlYC7Mk/?panelId=5&fullscreen&from=now-6h&to=now' ]
|
|
96
|
+
[ 'hubot', 'Memory / CPU: https://play.grafana.org/render/d-solo/97PlYC7Mk/?panelId=4&width=1000&height=500&from=now-6h&to=now - https://play.grafana.org/d/97PlYC7Mk/?panelId=4&fullscreen&from=now-6h&to=now' ]
|
|
97
|
+
[ 'hubot', 'Traffic In/Out: https://play.grafana.org/render/d-solo/97PlYC7Mk/?panelId=11&width=1000&height=500&from=now-6h&to=now - https://play.grafana.org/d/97PlYC7Mk/?panelId=11&fullscreen&from=now-6h&to=now' ]
|
|
98
|
+
[ 'hubot', 'logins: https://play.grafana.org/render/d-solo/97PlYC7Mk/?panelId=3&width=1000&height=500&from=now-6h&to=now - https://play.grafana.org/d/97PlYC7Mk/?panelId=3&fullscreen&from=now-6h&to=now' ]
|
|
94
99
|
]
|
|
95
100
|
|
|
96
101
|
context 'ask hubot to return a panel by slug', ->
|