Создать графики данных

Возвращает виджеты График заданных сущностей в таблице Excel.

Запрос

HTTP Запрос

POST /node/api/reports/excel

Права

objectPermissions

Параметры пути

Параметры не требуются.

Тело запроса

В теле запроса указывается набор графиков, которые нужно включить в отчёт.

[
    {
        "type": "line-chart",
        "entityId": "62e92397b8ff53567ebda32d",
        "entityType": 1,
        "metric": "{{packetsReceived}}",
        "formula": "{{packetsReceived}}",
        "from": 1661425032783,
        "to": 1661511432783,
        "downsample": "1m-avg"
    },
    {
        "type": "line-chart",
        "entityId": "630796035253ca424d67343a",
        "entityType": 1,
        "metric": "{{responseTimeMs}}",
        "formula": "{{responseTimeMs}}",
        "from": 1661425032784,
        "to": 1661511432784,
        "downsample": "1m-avg"
    }
]

Ответ

Возвращает бинарную таблицу Excel, которая включает запрошенные графики на первой таблице и данные для построения этих графиков на второй.

Пример

Запрос

Так как этот запрос возвращает файл XLSX, ответ нужно выводить сразу в файл, чтобы файл не был повреждён.
  • Bash

  • JavaScript

  • NodeJS

  • Python

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/reports/prop-inventory/excel

curl -X POST $url +
    -H "Content-Type: application/json" +
-o report.xlsx +
    -d @- <<EOF
[
    {
        "type": "line-chart",
        "entityId": "62e92397b8ff53567ebda32d",
        "entityType": 1,
        "metric": "{\{packetsReceived}}",
        "formula": "{\{packetsReceived}}",
        "from": 1661425032783,
        "to": 1661511432783,
        "downsample": "1m-avg"
    }
]
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/reports/prop-inventory/excel";

let headers = new Headers();
headers.append("Content-Type", "application/json");

let data = JSON.stringify([
    {
        "type": "line-chart",
        "entityId": "62e92397b8ff53567ebda32d",
        "entityType": 1,
        "metric": "{{packetsReceived}}",
        "formula": "{{packetsReceived}}",
        "from": 1661425032783,
        "to": 1661511432783,
        "downsample": "1m-avg"
    }
]);

let requestOptions = {
    method: "POST",
    headers: headers,
    body: data
};

fetch(saymonHostname + path, requestOptions)
    .then(response => response.blob())
    .then(blob => {
    var file = window.URL.createObjectURL(blob);
    window.location.assign(file);
  })
    .catch(error => console.log("error", error));
const http = require("http");
const fs = require("fs")

let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/reports/prop-inventory/excel";

let options = {
    "method": "POST",
    "hostname": saymonHostname,
    "headers": {
      "Content-Type": "application/json"
    },
    "path": path
};

let req = http.request(options, function (res) {
    let chunks = [];

    res.on("data", function (chunk) {
        chunks.push(chunk);
    });

    res.on("end", function (chunk) {
        let body = Buffer.concat(chunks);

        fs.writeFile('report.xlsx', body.toString(), function (err) {
          if (err) return console.log(err);
          console.log('Saved report.xlsx');
        });
    });

    res.on("error", function (error) {
        console.error(error);
    });
});

let data = JSON.stringify([
    {
        "type": "line-chart",
        "entityId": "62e92397b8ff53567ebda32d",
        "entityType": 1,
        "metric": "{{packetsReceived}}",
        "formula": "{{packetsReceived}}",
        "from": 1661425032783,
        "to": 1661511432783,
        "downsample": "1m-avg"
    }
]);

req.write(data);
req.end();
import requests

login = <...>
password = <...>
saymon_hostname = <...>
url = "http://" + saymon_hostname + "/node/api/reports/prop-inventory/excel"

json = [
    {
        "type": "line-chart",
        "entityId": "62e92397b8ff53567ebda32d",
        "entityType": 1,
        "metric": "{{packetsReceived}}",
        "formula": "{{packetsReceived}}",
        "from": 1661425032783,
        "to": 1661511432783,
        "downsample": "1m-avg"
    }
]

response = requests.request("POST", url, json=json, auth=(login, password))
f = open("report.xlsx", "w")
f.write(response.text)
f.close()

Ответ

График

Смотрите также