Sintaxa regulilor
Definește o regulă de depășire pentru un tag numeric.
Trimite path, operator: gt, threshold, unit și durationSeconds. Pragul este un șir zecimal în aceeași unitate cu tagul. Durata este un număr întreg pozitiv. Regula evaluează citirile bune și nu înlocuiește datele eronate sau vechi cu zero.
curl
curl -X POST "$RDC_BASE_URL/iot/v1/rules" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "a1000000-0000-4000-8000-000000000003",
"expectedRevision": 0,
"path": "cold-room-2/temperature",
"operator": "gt",
"threshold": "7.00",
"unit": "°C",
"durationSeconds": 60
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/iot/v1/rules`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "a1000000-0000-4000-8000-000000000003",
"expectedRevision": 0,
"path": "cold-room-2/temperature",
"operator": "gt",
"threshold": "7.00",
"unit": "°C",
"durationSeconds": 60
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/iot/v1/rules',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': 'a1000000-0000-4000-8000-000000000003',
'expectedRevision': 0,
'path': 'cold-room-2/temperature',
'operator': 'gt',
'threshold': '7.00',
'unit': '°C',
'durationSeconds': 60,
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "a1000000-0000-4000-8000-000000000003",
"expectedRevision": 0,
"path": "cold-room-2/temperature",
"operator": "gt",
"threshold": "7.00",
"unit": "°C",
"durationSeconds": 60
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/iot/v1/rules');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/iot/v1/rules");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "a1000000-0000-4000-8000-000000000003",
"expectedRevision": 0,
"path": "cold-room-2/temperature",
"operator": "gt",
"threshold": "7.00",
"unit": "°C",
"durationSeconds": 60
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "a1000000-0000-4000-8000-000000000003",
"status": "accepted",
"aggregateRevision": 1
} Condiția de deschidere trebuie să se mențină pe întreaga durată. După creare, citește operația și verifică regula înainte de a te baza pe ea. Regula este refuzată dacă tagul, operatorul, unitatea sau valorile numerice sunt nevalide.
curl
curl "$RDC_BASE_URL/iot/v1/rules?limit=20" \
-H "Authorization: Bearer $RDC_TOKEN" JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/iot/v1/rules?limit=20`, {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
},
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'GET',
f'{os.environ["RDC_BASE_URL"]}/iot/v1/rules?limit=20',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
)
result = response.json() PHP
<?php
$curl = curl_init(getenv('RDC_BASE_URL') . '/iot/v1/rules?limit=20');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
],
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/iot/v1/rules?limit=20");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"items": [
{
"id": "rule-1",
"path": "cold-room-2/temperature",
"operator": "gt",
"threshold": "7.00",
"unit": "°C",
"durationSeconds": 60,
"revision": 1
},
{
"id": "rule-2",
"path": "cold-room-1/temperature",
"operator": "gt",
"threshold": "7.00",
"unit": "°C",
"durationSeconds": 60,
"revision": 1
},
{
"id": "rule-3",
"path": "cold-room-3/temperature",
"operator": "gt",
"threshold": "7.00",
"unit": "°C",
"durationSeconds": 60,
"revision": 1
},
{
"id": "rule-4",
"path": "shop/temperature",
"operator": "gt",
"threshold": "8.00",
"unit": "°C",
"durationSeconds": 60,
"revision": 1
}
],
"nextCursor": null
} Pragurile sunt alese pentru echipamentul monitorizat. Confirmarea preluării și rezolvarea sunt acțiuni separate asupra alertei. Rezolvarea cere o alertă preluată și revizia curentă.
curl
curl -X POST "$RDC_BASE_URL/iot/v1/alerts/alert-1/resolve" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "a1000000-0000-4000-8000-000000000013",
"expectedRevision": 3
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/iot/v1/alerts/alert-1/resolve`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "a1000000-0000-4000-8000-000000000013",
"expectedRevision": 3
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/iot/v1/alerts/alert-1/resolve',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': 'a1000000-0000-4000-8000-000000000013',
'expectedRevision': 3,
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "a1000000-0000-4000-8000-000000000013",
"expectedRevision": 3
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/iot/v1/alerts/alert-1/resolve');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/iot/v1/alerts/alert-1/resolve");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "a1000000-0000-4000-8000-000000000013",
"expectedRevision": 3
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "a1000000-0000-4000-8000-000000000013",
"status": "accepted",
"aggregateRevision": 4
}