Skip to content
Snippets Groups Projects
Commit 56868c82 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-759: Avoid having init functions depend on the data in init, instead of...

L2SS-759: Avoid having init functions depend on the data in init, instead of the refreshed data later on
parent 6dfc5203
No related branches found
No related tags found
1 merge request!307L2SS-759: Add SVG panel plugin
...@@ -66,9 +66,9 @@ ...@@ -66,9 +66,9 @@
"addAllIDs": false, "addAllIDs": false,
"captureMappings": false, "captureMappings": false,
"eventAutoComplete": false, "eventAutoComplete": false,
"eventSource": "// find the right data series\nlet series = data.series.find(\n x => x.refId == \"B\"\n && x.fields[1].labels.device == \"total\"\n)\n\n// use the last value\nlet buffer = series.fields[1].values.buffer\nlet lastValue = buffer[buffer.length-1]\n\n// colour Drenthe accordingly\nsvgmap.Drenthe.css('fill', lastValue > 1 ? '#f00' : '#0f0')\nsvgmap.Drenthe.linkTo(function(link) {\n link.to('http://www.drenthe.nl').target('_blank')\n})\n\n// lookup an alert\nalert = get_alert(\"test\")\n\n// colour Groningen accordingly\nsvgmap.Groningen.css('fill', alert.colour)\nif (alert.href) {\n svgmap.Groningen.linkTo(function(link) {\n link.to(alert.href).target('_blank')\n })\n}\n\nconsole.log(\"refreshed\")", "eventSource": "// find the right data series\nlet series = data.series.find(\n x => x.refId == \"B\"\n && x.fields[1].labels.device == \"total\"\n)\n\n// use the last value\nlet buffer = series.fields[1].values.buffer\nlet lastValue = buffer[buffer.length-1]\n\n// colour Drenthe accordingly\nsvgmap.Drenthe.css('fill', lastValue > 1 ? '#f00' : '#0f0')\nsvgmap.Drenthe.linkTo(function(link) {\n link.to('http://www.drenthe.nl').target('_blank')\n})\n\n// lookup an alert\nalert = get_alert(data, \"test\")\n\n// colour Groningen accordingly\nsvgmap.Groningen.css('fill', alert.colour)\nif (alert.href) {\n svgmap.Groningen.linkTo(function(link) {\n link.to(alert.href).target('_blank')\n })\n}\n\nconsole.log(\"refreshed\")",
"initAutoComplete": false, "initAutoComplete": false,
"initSource": "// Lookup an alert in Grafana\r\nget_grafana_alert = (name) => {\r\n series = data.series.find(\r\n x => x.refId == \"GrafanaAlerts\"\r\n )\r\n\r\n return series.meta.custom.data.find(\r\n x => x.labels.alertname == name\r\n )\r\n}\r\n\r\n// Lookup an alert in Alerta\r\nget_alerta_alert = (name) => {\r\n series = data.series.find(\r\n x => x.refId == \"AlertaAlerts\"\r\n )\r\n\r\n return series.meta.custom.data.alerts.find(\r\n x => x.event == name\r\n )\r\n}\r\n\r\n// Return everything about an alert\r\nget_alert = (name) => {\r\n let grafana_alert = get_grafana_alert(name)\r\n let alerta_alert = get_alerta_alert(name)\r\n\r\n if (alerta_alert) {\r\n href = alerta_alert.href\r\n\r\n if (grafana_alert)\r\n colour = 'red'\r\n else\r\n colour = 'orange'\r\n } else if (grafana_alert) {\r\n // firing\r\n colour = 'red'\r\n\r\n href = '/alerting/grafana/'+ grafana_alert.labels.__alert_rule_uid__ +'/view'\r\n } else {\r\n colour = 'green'\r\n href = undefined\r\n }\r\n\r\n return {\r\n name: name,\r\n alerta_alert: alerta_alert,\r\n grafana_alert: grafana_alert,\r\n colour: colour,\r\n href: href\r\n }\r\n}", "initSource": "// Lookup an alert in Grafana\r\nget_grafana_alert = (data, name) => {\r\n series = data.series.find(\r\n x => x.refId == \"GrafanaAlerts\"\r\n )\r\n\r\n return series.meta.custom.data.find(\r\n x => x.labels.alertname == name\r\n )\r\n}\r\n\r\n// Lookup an alert in Alerta\r\nget_alerta_alert = (data, name) => {\r\n series = data.series.find(\r\n x => x.refId == \"AlertaAlerts\"\r\n )\r\n\r\n return series.meta.custom.data.alerts.find(\r\n x => x.event == name\r\n )\r\n}\r\n\r\n// Return everything about an alert\r\nget_alert = (data, name) => {\r\n let grafana_alert = get_grafana_alert(data, name)\r\n let alerta_alert = get_alerta_alert(data, name)\r\n\r\n if (alerta_alert) {\r\n href = alerta_alert.href\r\n\r\n if (grafana_alert)\r\n colour = 'red'\r\n else\r\n colour = 'orange'\r\n } else if (grafana_alert) {\r\n // firing\r\n colour = 'red'\r\n\r\n href = '/alerting/grafana/'+ grafana_alert.labels.__alert_rule_uid__ +'/view'\r\n } else {\r\n colour = 'green'\r\n href = undefined\r\n }\r\n\r\n return {\r\n name: name,\r\n alerta_alert: alerta_alert,\r\n grafana_alert: grafana_alert,\r\n colour: colour,\r\n href: href\r\n }\r\n}",
"svgMappings": [ "svgMappings": [
{ {
"mappedName": "Drenthe", "mappedName": "Drenthe",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment