簡體   English   中英

如何在 Flux (influxdb) 中轉義字符串?

[英]How to escape strings in Flux (influxdb)?

我想通過一個任務傳遞一個 http.post json,但我找不到關於如何轉義字符串的文檔,而且我的字符串中有引號

import "json"
import "http"

from(bucket: "prod")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "canalplus_subs_per_mode_hourly")
  |> filter(fn: (r) => r["_field"] == "reach")
  |> filter(fn: (r) => r["label"] == "Live")
  |> aggregateWindow(every: 12h, fn: median, createEmpty: false)
  |> yield(name: "median")

//    -H "Content-Type: application/json"
//    -H "Authorization: GenieKey eb243sasdasdasdasdsadassadasdsad"


http.post(
  url: "https://api.opsgenie.com/v2/alerts",
  headers: { "Content-Type":"application/json", Authorization:"GenieKey eb243592-faa2-4ba2-a551q-1afdf565c889"},
  data: bytes(v: "{
  
    "message": "An example alert message",
    "alias": "Life is too short for no alias",
    "description":"Every alert needs a description",
    "responders":[
        {"id":"4513b7ea-3b91-438f-b7e4-e3e54af9147c", "type":"team"},
        {"name":"NOC", "type":"team"},
        {"id":"bb4d9938-c3c2-455d-aaab-727aa701c0d8", "type":"user"},
        {"username":"trinity@opsgenie.com", "type":"user"},
        {"id":"aee8a0de-c80f-4515-a232-501c0bc9d715", "type":"escalation"},
        {"name":"Nightwatch Escalation", "type":"escalation"},
        {"id":"80564037-1984-4f38-b98e-8a1f662df552", "type":"schedule"},
        {"name":"First Responders Schedule", "type":"schedule"}
    ],
    "visibleTo":[
        {"id":"4513b7ea-3b91-438f-b7e4-e3e54af9147c","type":"team"},
        {"name":"rocket_team","type":"team"},
        {"id":"bb4d9938-c3c2-455d-aaab-727aa701c0d8","type":"user"},
        {"username":"trinity@opsgenie.com","type":"user"}
    ],
    "actions": ["Restart", "AnExampleAction"],
    "tags": ["OverwriteQuietHours","Critical"],
    "details":{"key1":"value1","key2":"value2"},
    "entity":"An example entity",
    "priority":"P1"
  
  }")
)

我在這種情況下解決了我的實際問題是我應該傳遞一個實際的 json 而不是一個字符串化的版本

import "json"
import "http"

from(bucket: "prod")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "canalplus_subs_per_mode_hourly")
  |> filter(fn: (r) => r["_field"] == "reach")
  |> filter(fn: (r) => r["label"] == "Live")
  |> aggregateWindow(every: 12h, fn: median, createEmpty: false)
  |> yield(name: "median")

http.post(
  url: "https://api.opsgenie.com/v2/alerts",
  headers: { "Content-Type":"application/json", Authorization:"GenieKey 7"},
  data: json.encode(v: {
    "message": "An example alert message 123"
  
  })
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM