Skip to content

Commit

Permalink
Merge pull request #172 from KeesCBakker/feature/from-now-parameter-s…
Browse files Browse the repository at this point in the history
…upport

Add support for from= and to= parameters
  • Loading branch information
KeesCBakker authored Jan 19, 2024
2 parents 87e8221 + f9e30a9 commit c1488d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hubot-grafana",
"description": "Query Grafana dashboards",
"version": "5.0.3",
"version": "5.1.0",
"author": "Stephen Yeargin <[email protected]>",
"license": "MIT",
"keywords": [
Expand Down
22 changes: 16 additions & 6 deletions src/grafana.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,28 @@ module.exports = (robot) => {

for (const part of Array.from(remainder.trim().split(' '))) {
// Check if it's a variable or part of the timespan

if (part.indexOf('=') >= 0) {
// put query stuff into its own dict
if (part.split('=')[0] in query) {
query[part.split('=')[0]] = part.split('=')[1];
const [partName, partValue] = part.split('=')

if (partName in query) {
query[partName] = partValue;
continue;
}
else if (partName == "from") {
timespan.from = partValue;
continue;
}
else if (partName == "to") {
timespan.to = partValue;
continue;
}

variables = `${variables}&var-${part}`;
template_params.push({
name: part.split('=')[0],
value: part.split('=')[1],
name: partName,
value: partValue,
});
} else if (part == 'kiosk') {
query.kiosk = true;
Expand Down Expand Up @@ -420,8 +431,7 @@ module.exports = (robot) => {
}

msg.send(
`Successfully tried to ${msg.match[1]} *${alerts.length}* alerts.\n*Success: ${
alerts.length - errored
`Successfully tried to ${msg.match[1]} *${alerts.length}* alerts.\n*Success: ${alerts.length - errored
}*\n*Errored: ${errored}*`
);
});
Expand Down
16 changes: 16 additions & 0 deletions test/grafana-v8-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ describe('grafana v8', () => {
});
});

describe('ask hubot to return a specific panel with a custom time range', () => {
beforeEach(async () => {
ctx
.nock('https://play.grafana.org')
.get('/api/dashboards/uid/97PlYC7Mk')
.replyWithFile(200, `${__dirname}/fixtures/v8/dashboard-grafana-play.json`);
});

it('hubot should respond with a resized image specified in request', async () => {
let response = await ctx.sendAndWaitForResponse('hubot graf db 97PlYC7Mk:3 from=1705569109372 to=1705572545230');
expect(response).to.eql(
'client side full page load: https://play.grafana.org/render/d-solo/97PlYC7Mk/?panelId=5&width=1000&height=500&from=1705569109372&to=1705572545230 - https://play.grafana.org/d/97PlYC7Mk/?panelId=5&fullscreen&from=1705569109372&to=1705572545230'
);
});
});

describe('ask hubot for templated dashboard', () => {
beforeEach(async () => {
ctx
Expand Down

0 comments on commit c1488d7

Please sign in to comment.