@@ -22,7 +22,11 @@ export default register => {
2222 [ 'array' , 'http' , 'influxdata/influxdb/secrets' ]
2323 . map ( i => `import "${ i } "` )
2424 . join ( '\n' ) ,
25- generateQuery : data => `task_data
25+ generateQuery : data => {
26+ const subject = encodeURIComponent ( 'InfluxDB Alert' )
27+ const fromEmail = `mailgun@${ data . domain } `
28+
29+ return `task_data
2630 |> schema["fieldsAsCols"]()
2731 |> set(key: "_notebook_link", value: "${ window . location . href } ")
2832 |> monitor["check"](
@@ -33,37 +37,57 @@ export default register => {
3337 |> monitor["notify"](
3438 data: notification,
3539 endpoint: ((r) => {
36- apiKey = secrets.get(key: "${ data . apiKey } ")
37- http.post(
38- url: "https://api.mailgun.net/v3/${ data . domain } /messages",
39- headers: {
40- "Content-type": "application/json",
41- "Authorization": "Basic api:\${apiKey}"
42- },
43- data: bytes(v: "{
44- \\"from\\": \\"Username mailgun@${ data . domain } \\",
45- \\"to\\": \\"${ data . email } \\",
46- \\"subject\\": \\"InfluxDB Alert\\",
47- \\"text\\": \\"\${ r._message }\\"
48- }"))
49- })
50- )` ,
51- generateTestQuery : data => `
52- apiKey = secrets.get(key: "{data.apiKey}")
53- http.post(
54- url: "https://api.mailgun.net/v3/${ data . domain } /messages",
40+ apiKey = secrets.get(key: "${ data . apiKey } ")
41+ auth = http.basicAuth(u: "api", p: "\${apiKey}")
42+ url = "https://api.mailgun.net/v3/${ data . domain } /messages"
43+ data = strings.joinStr(arr: [
44+ "from=${ fromEmail } ",
45+ "to=${ data . email } ",
46+ "subject=${ subject } ",
47+ "text=\${r._message}"
48+ ], v: "&"
49+ )
50+ http.post(
51+ url: url,
5552 headers: {
56- "Content-type ": "application/json ",
57- "Authorization": "Basic api: \${apiKey }"
53+ "Content-Type ": "application/x-www-form-urlencoded ",
54+ "Authorization": "\${auth }"
5855 },
59- data: bytes(v: "{
60- \"from\": \"Username mailgun@${ data . domain } \",
61- \"to\": \"${ data . email } \",
62- \"subject\": \"InfluxDB Alert\",
63- \"text\": \"${ TEST_NOTIFICATION } \"
64- }"))
56+ data: bytes(v: data)
57+ )
58+ array.from(rows: [{value: 0}])
59+ |> yield(name: "ignore")
60+ })
61+ )`
62+ } ,
63+ generateTestQuery : data => {
64+ const subject = encodeURIComponent ( 'InfluxDB Alert' )
65+ const message = encodeURIComponent ( TEST_NOTIFICATION )
66+ const fromEmail = `mailgun@${ data . domain } `
67+
68+ return `apiKey = secrets.get(key: "${ data . apiKey } ")
69+ auth = http.basicAuth(u: "api", p: "\${apiKey}")
70+ url = "https://api.mailgun.net/v3/${ data . domain } /messages"
71+ data = strings.joinStr(arr: [
72+ "from=${ fromEmail } ",
73+ "to=${ data . email } ",
74+ "subject=${ subject } ",
75+ "text=${ message } "
76+ ], v: "&"
77+ )
6578
66- array.from(rows: [{value: 0}])
67- |> yield(name: "ignore")` ,
79+ http.post(
80+ url: url,
81+ headers: {
82+ "Content-Type": "application/x-www-form-urlencoded",
83+ "Authorization": "\${auth}"
84+ },
85+ data: bytes(v: data)
86+ )
87+
88+ array.from(rows: [{value: 0}])
89+ |> yield(name: "ignore")
90+ `
91+ } ,
6892 } )
6993}
0 commit comments