diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..1713208 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,8 @@ +FROM mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye + +# Install the npm packages globally +RUN npm install -g npm \ + && npm install -g npm-check-updates + +COPY ./startup.sh / +RUN chmod +x /startup.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..feab8ba --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node +{ + "name": "Node.js & TypeScript", + "dockerFile": "Dockerfile", + "postStartCommand": "/startup.sh", + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "yarn install", + // Configure tool-specific properties. + // "customizations": {}, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" + "remoteUser": "node", + "mounts": [ + "source=${localWorkspaceFolderBasename}-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume" + ], + "postCreateCommand": "sudo chown node node_modules" +} diff --git a/.devcontainer/startup.sh b/.devcontainer/startup.sh new file mode 100644 index 0000000..27a4b33 --- /dev/null +++ b/.devcontainer/startup.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# trust the repo +# fixes: +# - fatal: detected dubious ownership in repository at '/workspaces/bot-zero'. +git config --global --add safe.directory "$PWD" + +# install NPM packages +echo "" +echo "Installing packages..." +npm install --no-audit --no-fund diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f33a02c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index a0f3eab..09bd77f 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [18.x, 20.x] steps: - uses: actions/checkout@v3 @@ -24,13 +24,14 @@ jobs: - name: npm install, build run: | - npm ci + npm run bootstrap npm run build --if-present env: CI: true - name: npm test run: | - npm test + npm run bootstrap + npm test -- --forbid-only --forbid-pending env: CI: true diff --git a/package-lock.json b/package-lock.json index 2268d04..61ca21d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "hubot-grafana", - "version": "5.1.1", + "version": "5.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "hubot-grafana", - "version": "5.1.1", + "version": "5.1.2", "license": "MIT", "dependencies": { "@aws-sdk/client-s3": "^3.378.0", @@ -4160,9 +4160,10 @@ } }, "node_modules/get-func-name": { - "version": "2.0.0", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", + "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", "dev": true, - "license": "MIT", "engines": { "node": "*" } diff --git a/package.json b/package.json index ad47ae7..f79c6d1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hubot-grafana", "description": "Query Grafana dashboards", - "version": "5.1.1", + "version": "5.1.2", "author": "Stephen Yeargin ", "license": "MIT", "keywords": [ @@ -39,8 +39,9 @@ }, "main": "index.js", "scripts": { - "test": "script/test", - "test-with-coverage": "nyc --reporter=text ./script/test", + "test": "mocha \"test/**/*.js\" --reporter spec", + "test-with-coverage": "nyc --reporter=text mocha \"test/**/*.js\" --reporter spec", + "bootstrap": "script/bootstrap", "prepare": "husky install", "lint": "eslint src/ test/" }, diff --git a/script/bootstrap b/script/bootstrap index 666faf1..12fc43b 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -12,4 +12,4 @@ if [ -f .env.${NODE_ENV} ]; then source .env.${NODE_ENV} fi -npm install +npm ci diff --git a/script/test b/script/test deleted file mode 100755 index c281706..0000000 --- a/script/test +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# bootstrap environment -source script/bootstrap - -mocha \"test/**/*.js\" --reporter spec diff --git a/src/grafana.js b/src/grafana.js index 00d00eb..f60ec3d 100644 --- a/src/grafana.js +++ b/src/grafana.js @@ -91,8 +91,8 @@ module.exports = (robot) => { let apiPanelId = false; let pname = false; const query = { - width: process.env.HUBOT_GRAFANA_DEFAULT_WIDTH || 1000, - height: process.env.HUBOT_GRAFANA_DEFAULT_HEIGHT || 500, + width: parseInt(process.env.HUBOT_GRAFANA_DEFAULT_WIDTH, 10) || 1000, + height: parseInt(process.env.HUBOT_GRAFANA_DEFAULT_HEIGHT, 10) || 500, tz: process.env.HUBOT_GRAFANA_DEFAULT_TIME_ZONE || '', orgId: process.env.HUBOT_GRAFANA_ORG_ID || '', apiEndpoint: process.env.HUBOT_GRAFANA_API_ENDPOINT || 'd-solo', diff --git a/test/fixtures/v8/dashboard-monitoring-default.json b/test/fixtures/v8/dashboard-monitoring-default.json index 6d18e0a..1691a20 100644 --- a/test/fixtures/v8/dashboard-monitoring-default.json +++ b/test/fixtures/v8/dashboard-monitoring-default.json @@ -1 +1,938 @@ -{"meta":{"type":"db","canSave":false,"canEdit":true,"canAdmin":false,"canStar":false,"slug":"influxdb-server-monitoring","url":"/d/AAy9r_bmk/influxdb-server-monitoring","expires":"0001-01-01T00:00:00Z","created":"2018-10-26T12:12:26Z","updated":"2018-12-07T10:20:43Z","updatedBy":"peter.hlmbrg@gmail.com","createdBy":"torkel.odegaard@gmail.com","version":5,"hasAcl":false,"isFolder":false,"folderId":461,"folderUid":"KbH7u4Pmz","folderTitle":"Data source: Influx DB","folderUrl":"/dashboards/f/KbH7u4Pmz/data-source-influx-db","provisioned":false,"provisionedExternalId":""},"dashboard":{"annotations":{"enable":false,"list":[{"builtIn":1,"datasource":"-- Grafana --","enable":true,"hide":true,"iconColor":"rgba(0, 211, 255, 1)","name":"Annotations \u0026 Alerts","type":"dashboard"}]},"editable":true,"gnetId":null,"graphTooltip":0,"id":443,"links":[],"panels":[{"cacheTimeout":null,"colorBackground":false,"colorValue":true,"colors":["#299c46","rgba(237, 129, 40, 0.89)","#d44a3a"],"datasource":"InfluxDB","format":"percent","gauge":{"maxValue":100,"minValue":0,"show":false,"thresholdLabels":false,"thresholdMarkers":true},"gridPos":{"h":4,"w":8,"x":0,"y":0},"id":3,"interval":null,"links":[],"mappingType":1,"mappingTypes":[{"name":"value to text","value":1},{"name":"range to text","value":2}],"maxDataPoints":100,"nullPointMode":"connected","nullText":null,"postfix":"","postfixFontSize":"50%","prefix":"$host ","prefixFontSize":"80%","rangeMaps":[{"from":"null","text":"N/A","to":"null"}],"repeat":"host","repeatDirection":"h","scopedVars":{"host":{"selected":true,"text":"server1","value":"server1"}},"sparkline":{"fillColor":"rgba(31, 118, 189, 0.18)","full":false,"lineColor":"rgb(31, 120, 193)","show":true},"tableColumn":"","targets":[{"groupBy":[{"params":["$__interval"],"type":"time"},{"params":["null"],"type":"fill"}],"measurement":"logins.count","orderByTime":"ASC","policy":"default","refId":"A","resultFormat":"time_series","select":[[{"params":["value"],"type":"field"},{"params":[],"type":"mean"},{"params":[" / 100"],"type":"math"}]],"tags":[{"key":"datacenter","operator":"=~","value":"/^$datacenter$/"},{"condition":"AND","key":"hostname","operator":"=~","value":"/^$host$/"}],"target":""}],"thresholds":"50,90","title":"CPU","type":"singlestat","valueFontSize":"80%","valueMaps":[{"op":"=","text":"N/A","value":"null"}],"valueName":"avg"},{"cacheTimeout":null,"colorBackground":false,"colorValue":true,"colors":["#299c46","rgba(237, 129, 40, 0.89)","#d44a3a"],"datasource":"InfluxDB","format":"percent","gauge":{"maxValue":100,"minValue":0,"show":false,"thresholdLabels":false,"thresholdMarkers":true},"gridPos":{"h":4,"w":8,"x":8,"y":0},"id":7,"interval":null,"links":[],"mappingType":1,"mappingTypes":[{"name":"value to text","value":1},{"name":"range to text","value":2}],"maxDataPoints":100,"nullPointMode":"connected","nullText":null,"postfix":"","postfixFontSize":"50%","prefix":"$host ","prefixFontSize":"80%","rangeMaps":[{"from":"null","text":"N/A","to":"null"}],"repeat":null,"repeatDirection":"h","repeatIteration":1541083165909,"repeatPanelId":3,"scopedVars":{"host":{"selected":true,"text":"server2","value":"server2"}},"sparkline":{"fillColor":"rgba(31, 118, 189, 0.18)","full":false,"lineColor":"rgb(31, 120, 193)","show":true},"tableColumn":"","targets":[{"groupBy":[{"params":["$__interval"],"type":"time"},{"params":["null"],"type":"fill"}],"measurement":"logins.count","orderByTime":"ASC","policy":"default","refId":"A","resultFormat":"time_series","select":[[{"params":["value"],"type":"field"},{"params":[],"type":"mean"},{"params":[" / 100"],"type":"math"}]],"tags":[{"key":"datacenter","operator":"=~","value":"/^$datacenter$/"},{"condition":"AND","key":"hostname","operator":"=~","value":"/^$host$/"}],"target":""}],"thresholds":"50,90","title":"CPU","type":"singlestat","valueFontSize":"80%","valueMaps":[{"op":"=","text":"N/A","value":"null"}],"valueName":"avg"},{"cacheTimeout":null,"colorBackground":false,"colorValue":true,"colors":["#299c46","rgba(237, 129, 40, 0.89)","#d44a3a"],"datasource":"InfluxDB","format":"percent","gauge":{"maxValue":100,"minValue":0,"show":false,"thresholdLabels":false,"thresholdMarkers":true},"gridPos":{"h":4,"w":8,"x":16,"y":0},"id":8,"interval":null,"links":[],"mappingType":1,"mappingTypes":[{"name":"value to text","value":1},{"name":"range to text","value":2}],"maxDataPoints":100,"nullPointMode":"connected","nullText":null,"postfix":"","postfixFontSize":"50%","prefix":"$host ","prefixFontSize":"80%","rangeMaps":[{"from":"null","text":"N/A","to":"null"}],"repeat":null,"repeatDirection":"h","repeatIteration":1541083165909,"repeatPanelId":3,"scopedVars":{"host":{"selected":true,"text":"10.1.100.1","value":"10.1.100.1"}},"sparkline":{"fillColor":"rgba(31, 118, 189, 0.18)","full":false,"lineColor":"rgb(31, 120, 193)","show":true},"tableColumn":"","targets":[{"groupBy":[{"params":["$__interval"],"type":"time"},{"params":["null"],"type":"fill"}],"measurement":"logins.count","orderByTime":"ASC","policy":"default","refId":"A","resultFormat":"time_series","select":[[{"params":["value"],"type":"field"},{"params":[],"type":"mean"},{"params":[" / 100"],"type":"math"}]],"tags":[{"key":"datacenter","operator":"=~","value":"/^$datacenter$/"},{"condition":"AND","key":"hostname","operator":"=~","value":"/^$host$/"}],"target":""}],"thresholds":"50,90","title":"CPU","type":"singlestat","valueFontSize":"80%","valueMaps":[{"op":"=","text":"N/A","value":"null"}],"valueName":"avg"},{"aliasColors":{},"annotate":{"enable":false},"bars":false,"dashLength":10,"dashes":false,"datasource":"InfluxDB","editable":true,"error":false,"fill":2,"grid":{},"gridPos":{"h":8,"w":12,"x":0,"y":4},"id":1,"interval":"$summarize","legend":{"alignAsTable":true,"avg":false,"current":false,"max":false,"min":false,"rightSide":true,"show":true,"total":false,"values":false},"lines":true,"linewidth":1,"links":[],"nullPointMode":"connected","percentage":false,"pointradius":5,"points":false,"renderer":"flot","resolution":100,"scale":1,"seriesOverrides":[],"spaceLength":10,"stack":true,"steppedLine":false,"targets":[{"alias":"$tag_hostname","dsType":"influxdb","groupBy":[{"params":["auto"],"type":"time"},{"params":["hostname"],"type":"tag"}],"measurement":"logins.count","orderByTime":"ASC","policy":"default","query":"SELECT mean(\"value\") FROM \"logins.count\" WHERE \"hostname\" =~ /$Hostname$/ AND $timeFilter GROUP BY time($interval), \"hostname\"","refId":"A","resultFormat":"time_series","select":[[{"params":["value"],"type":"field"},{"params":[],"type":"mean"}]],"tags":[{"key":"datacenter","operator":"=~","value":"/^$datacenter$/"},{"condition":"AND","key":"hostname","operator":"=~","value":"/^$host$/"}],"target":""}],"thresholds":[],"timeFrom":null,"timeShift":null,"title":"Nginx Req/s","tooltip":{"msResolution":false,"query_as_alias":true,"shared":false,"sort":0,"value_type":"cumulative"},"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"format":"short","logBase":1,"max":null,"min":null,"show":true},{"format":"short","logBase":1,"max":null,"min":null,"show":true}],"yaxis":{"align":false,"alignLevel":null},"zerofill":true},{"aliasColors":{},"bars":false,"dashLength":10,"dashes":false,"datasource":"InfluxDB","fill":1,"gridPos":{"h":8,"w":12,"x":12,"y":4},"id":6,"legend":{"alignAsTable":true,"avg":false,"current":true,"max":false,"min":false,"rightSide":false,"show":true,"total":false,"values":true},"lines":true,"linewidth":1,"links":[],"nullPointMode":"null","percentage":false,"pointradius":5,"points":false,"renderer":"flot","seriesOverrides":[],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"alias":"$tag_hostname","groupBy":[{"params":["$__interval"],"type":"time"},{"params":["hostname"],"type":"tag"},{"params":["null"],"type":"fill"}],"measurement":"logins.count","orderByTime":"ASC","policy":"default","refId":"A","resultFormat":"time_series","select":[[{"params":["value"],"type":"field"},{"params":[],"type":"mean"},{"params":["10s"],"type":"non_negative_derivative"},{"params":["*1000000000"],"type":"math"}]],"tags":[],"target":""}],"thresholds":[],"timeFrom":null,"timeShift":null,"title":"Free memory","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"format":"bytes","label":null,"logBase":1,"max":null,"min":null,"show":true},{"format":"short","label":null,"logBase":1,"max":null,"min":null,"show":true}],"yaxis":{"align":false,"alignLevel":null}}],"refresh":false,"schemaVersion":16,"style":"dark","tags":["influxdb","templated","presentation"],"templating":{"list":[{"allValue":null,"current":{"tags":[],"text":"America","value":"America"},"datasource":"InfluxDB","hide":0,"includeAll":false,"label":null,"multi":false,"name":"datacenter","options":[],"query":"SHOW TAG VALUES WITH KEY = \"datacenter\" ","refresh":1,"regex":"","skipUrlSync":false,"sort":0,"tagValuesQuery":null,"tags":[],"tagsQuery":null,"type":"query","useTags":false},{"allFormat":"regex values","allValue":null,"current":{"selected":false,"tags":[],"text":"server1 + server2 + 10.1.100.1","value":["server1","server2","10.1.100.1"]},"datasource":"InfluxDB","hide":0,"includeAll":true,"label":null,"multi":true,"multiFormat":"regex values","name":"host","options":[],"query":"SHOW TAG VALUES WITH KEY = \"hostname\" WHERE \"datacenter\" =~ /^$datacenter$/","refresh":1,"refresh_on_load":false,"regex":"","skipUrlSync":false,"sort":0,"tagValuesQuery":null,"tags":[],"tagsQuery":null,"type":"query","useTags":false},{"allFormat":"glob","auto":true,"auto_count":5,"auto_min":"10s","current":{"tags":[],"text":"auto","value":"$__auto_interval_summarize"},"datasource":null,"hide":0,"includeAll":false,"label":"","name":"summarize","options":[{"selected":true,"text":"auto","value":"$__auto_interval_summarize"},{"selected":false,"text":"1m","value":"1m"},{"selected":false,"text":"10m","value":"10m"},{"selected":false,"text":"30m","value":"30m"},{"selected":false,"text":"1h","value":"1h"},{"selected":false,"text":"6h","value":"6h"},{"selected":false,"text":"12h","value":"12h"},{"selected":false,"text":"1d","value":"1d"},{"selected":false,"text":"7d","value":"7d"},{"selected":false,"text":"14d","value":"14d"},{"selected":false,"text":"30d","value":"30d"}],"query":"1m,10m,30m,1h,6h,12h,1d,7d,14d,30d","refresh":2,"refresh_on_load":false,"skipUrlSync":false,"type":"interval"},{"datasource":"InfluxDB","filters":[],"hide":0,"label":null,"name":"adhoc","skipUrlSync":false,"type":"adhoc"}]},"time":{"from":"now-1h","to":"now"},"timepicker":{"collapse":false,"enable":true,"notice":false,"now":true,"refresh_intervals":["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],"status":"Stable","time_options":["5m","15m","1h","6h","12h","24h","2d","7d","30d"],"type":"timepicker"},"timezone":"browser","title":"InfluxDB Server Monitoring","uid":"AAy9r_bmk","version":5}} \ No newline at end of file +{ + "meta": { + "type": "db", + "canSave": false, + "canEdit": true, + "canAdmin": false, + "canStar": false, + "slug": "influxdb-server-monitoring", + "url": "/d/AAy9r_bmk/influxdb-server-monitoring", + "expires": "0001-01-01T00:00:00Z", + "created": "2018-10-26T12:12:26Z", + "updated": "2018-12-07T10:20:43Z", + "updatedBy": "peter.hlmbrg@gmail.com", + "createdBy": "torkel.odegaard@gmail.com", + "version": 5, + "hasAcl": false, + "isFolder": false, + "folderId": 461, + "folderUid": "KbH7u4Pmz", + "folderTitle": "Data source: Influx DB", + "folderUrl": "/dashboards/f/KbH7u4Pmz/data-source-influx-db", + "provisioned": false, + "provisionedExternalId": "" + }, + "dashboard": { + "annotations": { + "enable": false, + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations \u0026 Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 443, + "links": [], + "panels": [ + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": true, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "InfluxDB", + "format": "percent", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 8, + "x": 0, + "y": 0 + }, + "id": 3, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "$host ", + "prefixFontSize": "80%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "repeat": "host", + "repeatDirection": "h", + "scopedVars": { + "host": { + "selected": true, + "text": "server1", + "value": "server1" + } + }, + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": true + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "logins.count", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + " / 100" + ], + "type": "math" + } + ] + ], + "tags": [ + { + "key": "datacenter", + "operator": "=~", + "value": "/^$datacenter$/" + }, + { + "condition": "AND", + "key": "hostname", + "operator": "=~", + "value": "/^$host$/" + } + ], + "target": "" + } + ], + "thresholds": "50,90", + "title": "CPU", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "avg" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": true, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "InfluxDB", + "format": "percent", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 8, + "x": 8, + "y": 0 + }, + "id": 7, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "$host ", + "prefixFontSize": "80%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "repeat": null, + "repeatDirection": "h", + "repeatIteration": 1541083165909, + "repeatPanelId": 3, + "scopedVars": { + "host": { + "selected": true, + "text": "server2", + "value": "server2" + } + }, + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": true + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "logins.count", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + " / 100" + ], + "type": "math" + } + ] + ], + "tags": [ + { + "key": "datacenter", + "operator": "=~", + "value": "/^$datacenter$/" + }, + { + "condition": "AND", + "key": "hostname", + "operator": "=~", + "value": "/^$host$/" + } + ], + "target": "" + } + ], + "thresholds": "50,90", + "title": "CPU", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "avg" + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": true, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": "InfluxDB", + "format": "percent", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 4, + "w": 8, + "x": 16, + "y": 0 + }, + "id": 8, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "$host ", + "prefixFontSize": "80%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "repeat": null, + "repeatDirection": "h", + "repeatIteration": 1541083165909, + "repeatPanelId": 3, + "scopedVars": { + "host": { + "selected": true, + "text": "10.1.100.1", + "value": "10.1.100.1" + } + }, + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": true + }, + "tableColumn": "", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "logins.count", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + " / 100" + ], + "type": "math" + } + ] + ], + "tags": [ + { + "key": "datacenter", + "operator": "=~", + "value": "/^$datacenter$/" + }, + { + "condition": "AND", + "key": "hostname", + "operator": "=~", + "value": "/^$host$/" + } + ], + "target": "" + } + ], + "thresholds": "50,90", + "title": "CPU", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "avg" + }, + { + "aliasColors": {}, + "annotate": { + "enable": false + }, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "InfluxDB", + "editable": true, + "error": false, + "fill": 2, + "grid": {}, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 4 + }, + "id": 1, + "interval": "$summarize", + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "connected", + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "resolution": 100, + "scale": 1, + "seriesOverrides": [], + "spaceLength": 10, + "stack": true, + "steppedLine": false, + "targets": [ + { + "alias": "$tag_hostname", + "dsType": "influxdb", + "groupBy": [ + { + "params": [ + "auto" + ], + "type": "time" + }, + { + "params": [ + "hostname" + ], + "type": "tag" + } + ], + "measurement": "logins.count", + "orderByTime": "ASC", + "policy": "default", + "query": "SELECT mean(\"value\") FROM \"logins.count\" WHERE \"hostname\" =~ /$Hostname$/ AND $timeFilter GROUP BY time($interval), \"hostname\"", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "datacenter", + "operator": "=~", + "value": "/^$datacenter$/" + }, + { + "condition": "AND", + "key": "hostname", + "operator": "=~", + "value": "/^$host$/" + } + ], + "target": "" + } + ], + "thresholds": [], + "timeFrom": null, + "timeShift": null, + "title": "Nginx Req/s", + "tooltip": { + "msResolution": false, + "query_as_alias": true, + "shared": false, + "sort": 0, + "value_type": "cumulative" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + }, + "zerofill": true + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "InfluxDB", + "fill": 1, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 4 + }, + "id": 6, + "legend": { + "alignAsTable": true, + "avg": false, + "current": true, + "max": false, + "min": false, + "rightSide": false, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "percentage": false, + "pointradius": 5, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "alias": "$tag_hostname", + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "hostname" + ], + "type": "tag" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "logins.count", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "value" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + }, + { + "params": [ + "10s" + ], + "type": "non_negative_derivative" + }, + { + "params": [ + "*1000000000" + ], + "type": "math" + } + ] + ], + "tags": [], + "target": "" + } + ], + "thresholds": [], + "timeFrom": null, + "timeShift": null, + "title": "Free memory", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "bytes", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + } + ], + "refresh": false, + "schemaVersion": 16, + "style": "dark", + "tags": [ + "influxdb", + "templated", + "presentation" + ], + "templating": { + "list": [ + { + "allValue": null, + "current": { + "tags": [], + "text": "America", + "value": "America" + }, + "datasource": "InfluxDB", + "hide": 0, + "includeAll": false, + "label": null, + "multi": false, + "name": "datacenter", + "options": [], + "query": "SHOW TAG VALUES WITH KEY = \"datacenter\" ", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": null, + "tags": [], + "tagsQuery": null, + "type": "query", + "useTags": false + }, + { + "allFormat": "regex values", + "allValue": null, + "current": { + "selected": false, + "tags": [], + "text": "server1 + server2 + 10.1.100.1", + "value": [ + "server1", + "server2", + "10.1.100.1" + ] + }, + "datasource": "InfluxDB", + "hide": 0, + "includeAll": true, + "label": null, + "multi": true, + "multiFormat": "regex values", + "name": "host", + "options": [], + "query": "SHOW TAG VALUES WITH KEY = \"hostname\" WHERE \"datacenter\" =~ /^$datacenter$/", + "refresh": 1, + "refresh_on_load": false, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": null, + "tags": [], + "tagsQuery": null, + "type": "query", + "useTags": false + }, + { + "allFormat": "glob", + "auto": true, + "auto_count": 5, + "auto_min": "10s", + "current": { + "tags": [], + "text": "auto", + "value": "$__auto_interval_summarize" + }, + "datasource": null, + "hide": 0, + "includeAll": false, + "label": "", + "name": "summarize", + "options": [ + { + "selected": true, + "text": "auto", + "value": "$__auto_interval_summarize" + }, + { + "selected": false, + "text": "1m", + "value": "1m" + }, + { + "selected": false, + "text": "10m", + "value": "10m" + }, + { + "selected": false, + "text": "30m", + "value": "30m" + }, + { + "selected": false, + "text": "1h", + "value": "1h" + }, + { + "selected": false, + "text": "6h", + "value": "6h" + }, + { + "selected": false, + "text": "12h", + "value": "12h" + }, + { + "selected": false, + "text": "1d", + "value": "1d" + }, + { + "selected": false, + "text": "7d", + "value": "7d" + }, + { + "selected": false, + "text": "14d", + "value": "14d" + }, + { + "selected": false, + "text": "30d", + "value": "30d" + } + ], + "query": "1m,10m,30m,1h,6h,12h,1d,7d,14d,30d", + "refresh": 2, + "refresh_on_load": false, + "skipUrlSync": false, + "type": "interval" + }, + { + "datasource": "InfluxDB", + "filters": [], + "hide": 0, + "label": null, + "name": "adhoc", + "skipUrlSync": false, + "type": "adhoc" + } + ] + }, + "time": { + "from": "now-1h", + "to": "now" + }, + "timepicker": { + "collapse": false, + "enable": true, + "notice": false, + "now": true, + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ], + "status": "Stable", + "time_options": [ + "5m", + "15m", + "1h", + "6h", + "12h", + "24h", + "2d", + "7d", + "30d" + ], + "type": "timepicker" + }, + "timezone": "browser", + "title": "InfluxDB Server Monitoring", + "uid": "AAy9r_bmk", + "version": 5 + } +} \ No newline at end of file diff --git a/test/grafana-s3-test.js b/test/grafana-s3-test.js index 65203a7..cd7c7b7 100644 --- a/test/grafana-s3-test.js +++ b/test/grafana-s3-test.js @@ -52,8 +52,12 @@ describe('s3', () => { let response = await ctx.sendAndWaitForResponse('@hubot graf db AAy9r_bmk:cpu server=ww3.example.com now-6h'); response = response.replace(/\/[a-f0-9]{40}\.png/i, '/abdcdef0123456789.png'); + let panelRegex = /panelId=(\d+)/ + expect(response).to.match(panelRegex); + + let panelId = response.match(panelRegex)[1] expect(response).to.eql( - 'CPU: https://graf.s3.us-standard.amazonaws.com/grafana/abdcdef0123456789.png - https://play.grafana.org/d/AAy9r_bmk/?panelId=3&fullscreen&from=now-6h&to=now&var-server=ww3.example.com' + 'CPU: https://graf.s3.us-standard.amazonaws.com/grafana/abdcdef0123456789.png - https://play.grafana.org/d/AAy9r_bmk/?panelId=' + panelId + '&fullscreen&from=now-6h&to=now&var-server=ww3.example.com' ); }); });