generated from sensu/check-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sql.go
36 lines (30 loc) · 1.07 KB
/
sql.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import "text/template"
// In order to make the metrics queryable, they are imported into an in-memory
// sqlite3 database. Since we don't know the schema of the metrics ahead of time,
// and since the schema varies for different HAProxy versions, some dynamic
// code is needed to produce the sqlite3 schema. These templates are used with
// the scraped CSV to create the schema and insert the metrics as SQL rows.
//
// Some SQL injection protection has been implemented. For instance the columns
// are sanitized so that they cannot contain anything other than alphanumeric
// characters. For the inserts, placeholders are used so that there is no
// opportunity for SQLi.
const metricsDDL = `
CREATE TABLE metrics (
{{ range $i, $e := . }}
{{ if $i }},{{ end }}
{{ $e }}
{{ end }}
);
`
var metricsDDLTmpl = template.Must(template.New("metricsddl").Parse(metricsDDL))
const insertMetric = `
INSERT INTO metrics VALUES (
{{ range $i, $e := . }}
{{ if $i }},{{ end }}
?
{{ end }}
);
`
var insertMetricTmpl = template.Must(template.New("metricsinsert").Parse(insertMetric))