Create Metric Token

POST /node/api/metric-token

Creates a new metric token that can be used further to access the metric without authentication.

Request parameters

Body parameters

...

Response description

...

Examples

Request example

Bash
JavaScript
NodeJS
Python
1
login=<...>
2
password=<...>
3
saymon_hostname=<...>
4
url=https://$saymon_hostname/node/api/metric-token
5
6
curl -X POST $url -u $login:$password \
7
-H "Content-Type: application/json" \
8
--data '{"entityId": "5e21b85b308c3c66d64e07d2", "entityType": "1", "metric": "averageCpuLoad"}'
9
Copied!
1
let login = <...>
2
let password = <...>
3
let saymonHostname = <...>
4
let path = "/node/api/metric-token";
5
let auth = "Basic " + btoa(login + ":" + password);
6
7
let headers = new Headers();
8
headers.append("Content-Type", "application/json");
9
headers.append("Authorization", auth);
10
11
let data = JSON.stringify({
12
"entityId": "5e7dbc31f988c426bb372053",
13
"entityType": "1",
14
"metric": "averageCpuLoad"
15
});
16
17
let requestOptions = {
18
method: "POST",
19
headers: headers,
20
body: data
21
};
22
23
fetch(saymonHostname + path, requestOptions)
24
.then(response => response.text())
25
.then(result => console.log(result))
26
.catch(error => console.log("error", error));
Copied!
1
const http = require("http");
2
3
let login = <...>
4
let password = <...>
5
let saymonHostname = <...>
6
let path = "/node/api/metric-token/";
7
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
8
9
let options = {
10
"method": "POST",
11
"hostname": saymonHostname,
12
"headers": {
13
"Authorization": auth,
14
"Content-Type": "application/json"
15
},
16
"path": path
17
};
18
19
let req = http.request(options, function (res) {
20
let chunks = [];
21
22
res.on("data", function (chunk) {
23
chunks.push(chunk);
24
});
25
26
res.on("end", function (chunk) {
27
let body = Buffer.concat(chunks);
28
console.log(body.toString());
29
});
30
31
res.on("error", function (error) {
32
console.error(error);
33
});
34
});
35
36
let data = JSON.stringify({
37
"entityId": "5e7dbc31f988c426bb372053",
38
"entityType": "1",
39
"metric": "averageCpuLoad"
40
});
41
42
req.write(data);
43
req.end();
Copied!
1
import requests
2
3
login = <...>
4
password = <...>
5
saymon_hostname = <...>
6
url = "https://" + saymon_hostname + "/node/api/metric-token"
7
8
body = {
9
"entityId": "5e21b85b308c3c66d64e07d2",
10
"entityType": "1",
11
"metric": "averageCpuLoad"
12
}
13
14
response = requests.request("POST", url, json=body, auth=(login, password))
15
print(response.text)
Copied!

Response example

1
{
2
"entityId": "5e21b85b308c3c66d64e07d2",
3
"entityType": 1,
4
"metric": "averageCpuLoad",
5
"id": "83d62e15-628e-4ec7-8746-e6ff20ebdc11"
6
}
Copied!
Last modified 1yr ago