Monitoring service

This commit is contained in:
ViacheslavKlimov 2022-11-19 15:52:47 +02:00
parent 6223307cd8
commit 9858c4e137
50 changed files with 3815 additions and 0 deletions

132
monitoring/pom.xml Normal file
View File

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2016-2022 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.thingsboard</groupId>
<version>3.4.2-SNAPSHOT</version>
<artifactId>thingsboard</artifactId>
</parent>
<artifactId>monitoring</artifactId>
<version>3.4.2-SNAPSHOT</version>
<name>Monitoring service</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<main.dir>${basedir}/..</main.dir>
<pkg.name>monitoring-service</pkg.name>
</properties>
<dependencies>
<dependency>
<groupId>org.thingsboard.common</groupId>
<artifactId>data</artifactId>
</dependency>
<dependency>
<groupId>org.thingsboard.common</groupId>
<artifactId>util</artifactId>
</dependency>
<dependency>
<groupId>org.thingsboard</groupId>
<artifactId>rest-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>californium-core</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>scandium</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-client-cf</artifactId>
<version>2.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-core</artifactId>
<version>2.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${pkg.name}-${project.version}</finalName>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,51 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.aba;
import lombok.Data;
@Data
public class LatencyMsg {
private long restClientLoginLatency;
private long deviceCredLatency;
private long getDeviceLatency;
private long wsSubInitLatency;
private long mqttConnectLatency;
private long mqttSendLatency;
private long mqttTotalLatency;
private long httpSendLatency;
private long httpTotalLatency;
private long mqttErrors;
private long mqttReconnects;
public boolean hasLongLatency(long threshold) {
return restClientLoginLatency > threshold
|| deviceCredLatency > threshold
|| getDeviceLatency > threshold
|| wsSubInitLatency > threshold
|| mqttConnectLatency > threshold
|| mqttSendLatency > threshold
|| mqttTotalLatency > threshold
|| httpSendLatency > threshold
|| httpTotalLatency > threshold;
}
}

View File

@ -0,0 +1,234 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.aba;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.ssl.TrustStrategy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.support.HttpRequestWrapper;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
import org.thingsboard.rest.client.RestClient;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.security.DeviceCredentials;
import java.net.URI;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
@Component
@Slf4j
public class SaasApi {
private static final long wsResponseWaitSec = 300;
@Value("${saas.host}")
private String host;
private AtomicLong counter = new AtomicLong();
private SampleMqttClient mqttClient;
private AtomicLong mqttErrors = new AtomicLong();
private AtomicLong mqttReconnects = new AtomicLong();
public void checkMqtt(Device device, DeviceCredentials deviceCredentials, RestClient restClient, LatencyMsg latency) {
try {
WsClient wsClient = subscribeToWebSocket(device.getId(), "tsSubCmds", restClient, latency);
long msgTs = System.currentTimeMillis();
long submittedValue = counter.incrementAndGet();
sendMqtt(deviceCredentials, submittedValue, msgTs, latency);
WsTelemetryResponse actualLatestTelemetry = wsClient.getLastMessage(wsResponseWaitSec);
if(actualLatestTelemetry == null) {
latency.setMqttTotalLatency(-1*wsResponseWaitSec);
} else {
validateWsResponse(actualLatestTelemetry, msgTs, submittedValue);
long responseReadyTs = System.currentTimeMillis();
latency.setMqttTotalLatency(responseReadyTs - msgTs);
}
wsClient.closeBlocking();
latency.setMqttErrors(mqttErrors.getAndSet(0L));
latency.setMqttReconnects(mqttReconnects.getAndSet(0L));
} catch (Exception ex) {
throw new IllegalStateException("Could not check mqtt: " + ex.getMessage(), ex);
}
}
public void checkHttp(Device device, DeviceCredentials deviceCredentials, RestClient restClient, LatencyMsg latency) {
try {
WsClient wsClient = subscribeToWebSocket(device.getId(), "tsSubCmds", restClient, latency);
long msgTs = System.currentTimeMillis();
long submittedValue = counter.incrementAndGet();
sendHttp(restClient, deviceCredentials, submittedValue, msgTs, latency);
WsTelemetryResponse actualLatestTelemetry = wsClient.getLastMessage(wsResponseWaitSec);
if(actualLatestTelemetry == null) {
latency.setHttpTotalLatency(-1*wsResponseWaitSec);
} else {
validateWsResponse(actualLatestTelemetry, msgTs, submittedValue);
long responseReadyTs = System.currentTimeMillis();
latency.setHttpTotalLatency(responseReadyTs - msgTs);
}
wsClient.closeBlocking();
} catch (Exception ex) {
throw new IllegalStateException("Could not check http: " + ex.getMessage(), ex);
}
}
private void validateWsResponse(WsTelemetryResponse response, long expectedTs, long expectedVal) {
try {
List<Object> values = response.getDataValuesByKey("checkKey");
if (CollectionUtils.isEmpty(values)) {
throw new IllegalStateException("Ws response - no data");
}
long actualTs = Long.parseLong(values.get(0).toString());
long actualVal = Long.parseLong(values.get(1).toString());
if (actualTs != expectedTs) {
throw new IllegalStateException("Ws response - Ts not matched. Actual: " + actualTs + " Expected: " + expectedTs + " Delta: " + (expectedTs - actualTs));
}
if (actualVal != expectedVal) {
throw new IllegalStateException("Ws response - Value not matched. Actual: " + actualVal + " Expected: " + expectedVal + " Delta: " + (expectedVal - actualVal));
}
} catch (Exception ex) {
throw new IllegalStateException("Could not validate WS response: " + response, ex);
}
}
private void sendHttp(RestClient restClient, DeviceCredentials deviceCredentials, long value, long msgTs, LatencyMsg latency) {
try {
long start = System.currentTimeMillis();
RestTemplate restTemplate = new RestTemplate();
restTemplate.setInterceptors(Collections.singletonList((httpRequest, bytes, clientHttpRequestExecution) -> {
HttpRequest wrapper = new HttpRequestWrapper(httpRequest);
wrapper.getHeaders().set("X-Authorization", "Bearer " + restClient.getToken());
return clientHttpRequestExecution.execute(wrapper, bytes);
}));
String payload = createPayload(msgTs, value).toString();
restTemplate.postForEntity("https://" + host + "/api/v1/" + deviceCredentials.getCredentialsId() + "/telemetry", payload, String.class);
latency.setHttpSendLatency(System.currentTimeMillis() - start);
log.info("HTTP msg submitted");
} catch (Exception ex) {
throw new IllegalStateException("Could not send http: " + ex.getMessage(), ex);
}
}
private void sendMqtt(DeviceCredentials deviceCredentials, long value, long msgTs, LatencyMsg latency) {
try {
long start = System.currentTimeMillis();
SampleMqttClient mqttClient = getMqttClient(deviceCredentials, latency);
JsonObject payload = createPayload(msgTs, value);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.readTree(payload.toString());
mqttClient.publishTelemetry(objectMapper.readTree(payload.toString()));
latency.setMqttSendLatency(System.currentTimeMillis() - start);
log.info("Mqtt msg submitted");
} catch (Exception ex) {
throw new IllegalStateException("Could not send mqtt: " + ex.getMessage(), ex);
}
}
private WsClient subscribeToWebSocket(DeviceId deviceId, String property, RestClient restClient, LatencyMsg latency) {
try {
long start = System.currentTimeMillis();
WsClient wsClient = new WsClient(new URI("wss://" + host + "/api/ws/plugins/telemetry?token=" + restClient.getToken()));
SSLContextBuilder builder = SSLContexts.custom();
builder.loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true);
wsClient.setSocketFactory(builder.build().getSocketFactory());
wsClient.connectBlocking();
JsonObject cmdsObject = new JsonObject();
cmdsObject.addProperty("entityType", EntityType.DEVICE.name());
cmdsObject.addProperty("entityId", deviceId.toString());
cmdsObject.addProperty("scope", "LATEST_TELEMETRY");
cmdsObject.addProperty("cmdId", new Random().nextInt(100));
JsonArray cmd = new JsonArray();
cmd.add(cmdsObject);
JsonObject wsRequest = new JsonObject();
wsRequest.add(property, cmd);
wsClient.send(wsRequest.toString());
wsClient.waitForFirstReply();
latency.setWsSubInitLatency(System.currentTimeMillis() - start);
log.info("Ws subscription created");
return wsClient;
} catch (Exception ex) {
throw new IllegalStateException("Could not subscribe to WS: " + ex.getMessage(), ex);
}
}
private SampleMqttClient getMqttClient(DeviceCredentials deviceCredentials, LatencyMsg latency) {
try {
long start = System.currentTimeMillis();
if (mqttClient == null || !mqttClient.nativeClient.isConnected()) {
if (mqttClient != null) {
mqttReconnects.incrementAndGet();
try {
mqttClient.disconnect();
} catch (Exception ex) {
log.error("fail disconnect mqtt", ex);
}
}
String uri = "tcp://" + host + ":1883";
String deviceTmpName = "health check device";
String token = deviceCredentials.getCredentialsId();
mqttClient = new SampleMqttClient(uri, deviceTmpName, token, mqttErrors);
boolean connected = mqttClient.connect();
if (!connected) {
throw new IllegalStateException("Could not connect mqtt nativeClient");
}
}
latency.setMqttConnectLatency(System.currentTimeMillis() - start);
return mqttClient;
} catch (Exception ex) {
throw new IllegalStateException("Could not create mqtt nativeClient: " + ex.getMessage(), ex);
}
}
private static JsonObject createPayload(long ts, long val) {
JsonObject values = createPayload(val);
JsonObject payload = new JsonObject();
payload.addProperty("ts", ts);
payload.add("values", values);
return payload;
}
private static JsonObject createPayload(long val) {
JsonObject values = new JsonObject();
values.addProperty("checkKey", val);
return values;
}
}

View File

@ -0,0 +1,233 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.aba;
import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import org.crawler.license.service.NotifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.support.HttpRequestWrapper;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.thingsboard.rest.client.RestClient;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.security.DeviceCredentials;
import javax.annotation.PostConstruct;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
@Component
@Slf4j
public class SaasHealthChecker {
// private String url = "";
private String username = "paromskiy@gmail.com";
private String pass = "123test123";
private String deviceName = "healthcheckDevice";
private String dashboardId = "";
@Value("${saas.host}")
private String host;
@Value("${saas.check.interval.sec}")
private long refreshIntervalSec;
@Value("${saas.notifyThreshold.ms}")
private long notifyThreshold;
@Autowired
private NotifyService notifyService;
@Autowired
private SaasApi saasApi;
private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
private AtomicLong counter = new AtomicLong();
private long logStatsIntervalMs = TimeUnit.HOURS.toMillis(12);
private long lastLogStatsTime = System.currentTimeMillis();
private long lastLatencyNotification = 0;
private boolean inFailedState = false;
private List<LatencyMsg> latestLatencies = Lists.newArrayList();
private long failsCount = 0;
@PostConstruct
public void init() throws URISyntaxException {
check();
executor.scheduleWithFixedDelay(() -> {
try {
log.info("Start saas healthcheck");
check();
counter.incrementAndGet();
log.info("Finish saas healthcheck");
// if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) == 1) {
// notifyService.sendInSlackSaasHealth("I AM ALIVE. Checks performed: " + counter.get());
// }
if(System.currentTimeMillis() - lastLogStatsTime > logStatsIntervalMs) {
lastLogStatsTime = System.currentTimeMillis();
logIntervalStats();
notifyService.sendInSlackSaasHealth("I AM ALIVE. Checks performed: " + counter.get());
}
} catch (Exception ex) {
log.error("Scheduled error", ex);
}
}, refreshIntervalSec, refreshIntervalSec, TimeUnit.SECONDS);
}
private void check() throws URISyntaxException {
try {
// load dashboard
LatencyMsg latency = new LatencyMsg();
RestClient restClient = buildClient(latency);
Device device = getDevice(restClient, latency);
DeviceCredentials deviceCred = getDeviceCred(restClient, device, latency);
saasApi.checkMqtt(device, deviceCred, restClient, latency);
saasApi.checkHttp(device, deviceCred, restClient, latency);
processLatencyObj(latency, restClient, deviceCred);
latestLatencies.add(latency);
if (inFailedState) {
inFailedState = false;
notifyService.sendInSlackSaasHealth("service restored");
}
} catch (Exception ex) {
failsCount++;
log.error("Error while check Saas health", ex);
if (!inFailedState || System.currentTimeMillis() - lastLatencyNotification > TimeUnit.MINUTES.toHours(15)) {
String msg = "########################## \n ERROR \n " + ex.getMessage();
lastLatencyNotification = System.currentTimeMillis();
inFailedState = true;
notifyService.sendInSlackSaasHealth(msg);
}
}
}
private void processLatencyObj(LatencyMsg latency, RestClient restClient, DeviceCredentials credentials) throws URISyntaxException {
System.out.println();
System.out.println(latency);
System.out.println();
JsonObject values = new JsonObject();
values.addProperty("restClientLoginLatency", latency.getRestClientLoginLatency());
values.addProperty("deviceCredLatency", latency.getDeviceCredLatency());
values.addProperty("getDeviceLatency", latency.getGetDeviceLatency());
values.addProperty("wsSubInitLatency", latency.getWsSubInitLatency());
values.addProperty("mqttConnectLatency", latency.getMqttConnectLatency());
values.addProperty("mqttSendLatency", latency.getMqttSendLatency());
values.addProperty("mqttTotalLatency", latency.getMqttTotalLatency());
values.addProperty("httpSendLatency", latency.getHttpSendLatency());
values.addProperty("httpTotalLatency", latency.getHttpTotalLatency());
values.addProperty("mqttErrors", latency.getMqttErrors());
values.addProperty("mqttReconnects", latency.getMqttReconnects());
JsonObject payload = new JsonObject();
payload.addProperty("ts", System.currentTimeMillis());
payload.add("values", values);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setInterceptors(Collections.singletonList((httpRequest, bytes, clientHttpRequestExecution) -> {
HttpRequest wrapper = new HttpRequestWrapper(httpRequest);
wrapper.getHeaders().set("X-Authorization", "Bearer " + restClient.getToken());
return clientHttpRequestExecution.execute(wrapper, bytes);
}));
restTemplate.postForEntity("https://" + host + "/api/v1/" + credentials.getCredentialsId() + "/telemetry", payload.toString(), String.class);
if (latency.hasLongLatency(notifyThreshold) && System.currentTimeMillis() - lastLatencyNotification > TimeUnit.MINUTES.toHours(60)) {
lastLatencyNotification = System.currentTimeMillis();
notifyService.sendInSlackSaasHealth("Some SaaS latencies are upper threshold [" + notifyThreshold + "ms] \n " + latency);
}
}
private Device getDevice(RestClient restClient, LatencyMsg latencyMsg) {
long start = System.currentTimeMillis();
Optional<Device> tenantDevice = restClient.getTenantDevice(deviceName);
Device device = tenantDevice.orElseThrow(() -> new IllegalStateException("Device [" + deviceName + "] was not found"));
latencyMsg.setGetDeviceLatency(System.currentTimeMillis() - start);
log.info("Device loaded");
return device;
}
private DeviceCredentials getDeviceCred(RestClient client, Device device, LatencyMsg latencyMsg) {
long start = System.currentTimeMillis();
Optional<DeviceCredentials> credentialsOptional = client.getDeviceCredentialsByDeviceId(device.getId());
DeviceCredentials credentials = credentialsOptional.orElseThrow(() -> new IllegalStateException("Could not load device credentials"));
latencyMsg.setDeviceCredLatency(System.currentTimeMillis() - start);
log.info("Device cred loaded");
return credentials;
}
private RestClient buildClient(LatencyMsg latencyMsg) {
try {
long start = System.currentTimeMillis();
RestClient client = new RestClient("https://" + host);
client.login(username, pass);
latencyMsg.setRestClientLoginLatency(System.currentTimeMillis() - start);
log.info("Rest client ready");
return client;
} catch (Exception ex) {
throw new IllegalStateException("Could not login: " + ex.getMessage(), ex);
}
}
private void logIntervalStats() throws URISyntaxException {
List<Long> httpTotal = latestLatencies.stream().map(LatencyMsg::getHttpTotalLatency).collect(Collectors.toList());
List<Long> login = latestLatencies.stream().map(LatencyMsg::getRestClientLoginLatency).collect(Collectors.toList());
List<Long> getDevice = latestLatencies.stream().map(LatencyMsg::getDeviceCredLatency).collect(Collectors.toList());
long mqttErrorsCnt = latestLatencies.stream().mapToLong(LatencyMsg::getMqttErrors).sum();
long mqttReconectCnt = latestLatencies.stream().mapToLong(LatencyMsg::getMqttReconnects).sum();
String msg = "[Interval stats] Fails count: " + failsCount + " ok count: " + latestLatencies.size() + "\n";
if (latestLatencies.size() > 0) {
msg += "\t http send -receive dalay: " + toPercentile(httpTotal) + "\n";
msg += "\t http login: " + toPercentile(login) + "\n";
msg += "\t get device: " + toPercentile(getDevice) + "\n";
msg += "\t mqtt errors: " + mqttErrorsCnt + "\n";
msg += "\t mqtt reconnects: " + mqttReconectCnt + "\n";
}
failsCount = 0;
latestLatencies.clear();
log.info("Interval stats: {}" , msg);
notifyService.sendInSlackSaasHealth(msg);
}
private String toPercentile(List<Long> values) {
return "75%: " + percentile(values, 75) + "ms; \t90%:" + percentile(values, 90) + "ms; \t95%:" + percentile(values, 95) + "ms; \tmin: " + percentile(values, 1) + "ms; \tmax: " + percentile(values, 99.99);
}
private static Long percentile(List<Long> values, double percentile) {
Collections.sort(values);
int index = (int) Math.ceil(percentile / 100.0 * values.size());
return (long) ((Math.round(values.get(index - 1) * 100)) / 100d);
}
}

View File

@ -0,0 +1,112 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.aba;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicLong;
@Slf4j
public class SampleMqttClient {
public static final ObjectMapper MAPPER = new ObjectMapper();
@Getter
private final String deviceToken;
@Getter
private final String deviceName;
@Getter
private final String clientId;
private final MqttClientPersistence persistence;
public final MqttAsyncClient nativeClient;
public final AtomicLong failCount;
public SampleMqttClient(String uri, String deviceName, String deviceToken, AtomicLong failCount) throws Exception {
this.clientId = MqttAsyncClient.generateClientId();
this.deviceToken = deviceToken;
this.deviceName = deviceName;
this.failCount = failCount;
this.persistence = new MemoryPersistence();
this.nativeClient = new MqttAsyncClient(uri, clientId, persistence);
}
public boolean connect() throws Exception {
MqttConnectOptions options = new MqttConnectOptions();
options.setUserName(deviceToken);
try {
nativeClient.connect(options, null, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken iMqttToken) {
log.info("[{}] connected to Thingsboard!", deviceName);
}
@Override
public void onFailure(IMqttToken iMqttToken, Throwable e) {
failCount.incrementAndGet();
log.error("[{}] failed to connect to Thingsboard!", deviceName, e);
}
}).waitForCompletion();
} catch (MqttException e) {
log.error("Failed to connect to the server", e);
}
return nativeClient.isConnected();
}
public void disconnect() throws Exception {
nativeClient.disconnect().waitForCompletion();
}
public void publishAttributes(JsonNode data) throws Exception {
publish("v1/devices/me/attributes", data, true);
}
public void publishTelemetry(JsonNode data) throws Exception {
publish("v1/devices/me/telemetry", data, false);
}
private void publish(String topic, JsonNode data, boolean sync) throws Exception {
MqttMessage msg = new MqttMessage(MAPPER.writeValueAsString(data).getBytes(StandardCharsets.UTF_8));
IMqttDeliveryToken deliveryToken = nativeClient.publish(topic, msg, null, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
log.trace("Data updated!");
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
log.error("[{}] Data update failed!", deviceName, exception);
}
});
if (sync) {
deliveryToken.waitForCompletion();
}
}
}

View File

@ -0,0 +1,102 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.aba;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import javax.net.ssl.SSLParameters;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@Slf4j
public class WsClient extends WebSocketClient {
private static final ObjectMapper mapper = new ObjectMapper();
private WsTelemetryResponse message;
private volatile boolean firstReplyReceived;
private CountDownLatch firstReply = new CountDownLatch(1);
private CountDownLatch latch = new CountDownLatch(1);
WsClient(URI serverUri) {
super(serverUri);
}
@Override
public void onOpen(ServerHandshake serverHandshake) {
}
@Override
public void onMessage(String message) {
log.info("Ws on message {}", message);
if (!firstReplyReceived) {
firstReplyReceived = true;
firstReply.countDown();
} else {
try {
WsTelemetryResponse response = mapper.readValue(message, WsTelemetryResponse.class);
response.setArriveTs(System.currentTimeMillis());
if (!response.getData().isEmpty()) {
this.message = response;
latch.countDown();
}
} catch (IOException e) {
log.error("ws message can't be read");
}
}
}
@Override
public void onClose(int code, String reason, boolean remote) {
log.info("ws is closed, due to [{}]", reason);
}
@Override
public void onError(Exception ex) {
ex.printStackTrace();
}
public WsTelemetryResponse getLastMessage(long timeoutSec) {
try {
latch.await(timeoutSec, TimeUnit.SECONDS);
log.info("Ws response received");
return this.message;
} catch (InterruptedException e) {
log.error("Timeout, ws message wasn't received");
}
return null;
}
void waitForFirstReply() {
try {
firstReply.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.error("Timeout, ws message wasn't received");
throw new RuntimeException(e);
}
}
@Override
protected void onSetSSLParameters(SSLParameters sslParameters) {
sslParameters.setEndpointIdentificationAlgorithm(null);
}
}

View File

@ -0,0 +1,41 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.aba;
import lombok.Data;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Data
public class WsTelemetryResponse {
private int subscriptionId;
private int errorCode;
private String errorMsg;
private Map<String, List<List<Object>>> data;
private Map<String, Object> latestValues;
private long arriveTs;
public List<Object> getDataValuesByKey(String key) {
return data.entrySet().stream()
.filter(e -> e.getKey().equals(key))
.flatMap(e -> e.getValue().stream().flatMap(Collection::stream))
.collect(Collectors.toList());
}
}

View File

@ -0,0 +1,28 @@
#
# Copyright © 2016-2022 The Thingsboard Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
server.address: "${HTTP_BIND_ADDRESS:0.0.0.0}"
server.port: "${HTTP_BIND_PORT:9712}"
server.compression.enabled: true
server.compression.mime-types: "text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json"
server.compression.min-response-size: 1024
saas.host: "${SAAS_CHECK_HOST:thingsboard.cloud}"
saas.check.interval.sec: "${SAAS_CHECK_INTERVAL_SEC:60}"
saas.slack.token: "${SAAS_SLACK_TOKEN:T2QD8CLUS/B02TP4E0Y02/RenftHjCFYdVlOU8OiPGOhJV}"
saas.notifyThreshold.ms: "${SAAS_NOTIFY_THRESHOLD_MS:28000}"

View File

@ -0,0 +1,68 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.thingsboard.common.util.ThingsBoardThreadFactory;
import org.thingsboard.monitoring.config.service.TransportMonitoringServiceConfig;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@SpringBootApplication
@EnableScheduling
public class ThingsboardMonitoringApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ThingsboardMonitoringApplication.class)
.properties(Map.of("spring.config.name", "tb-monitoring"))
.run(args);
}
@Bean
public ApplicationRunner initMonitoringServices(List<TransportMonitoringServiceConfig> configs, ApplicationContext context) {
return args -> {
configs.forEach(config -> {
config.getTargets().stream()
.filter(target -> StringUtils.isNotBlank(target.getBaseUrl()))
.forEach(target -> {
context.getBean(config.getTransportType().getMonitoringServiceClass(), config, target);
});
});
};
}
@Bean
public ScheduledExecutorService monitoringExecutor(List<TransportMonitoringServiceConfig> configs) {
int targetsCount = configs.stream().mapToInt(config -> config.getTargets().size()).sum();
return Executors.newScheduledThreadPool(targetsCount, ThingsBoardThreadFactory.forName("monitoring-executor"));
}
@Bean
public ExecutorService requestExecutor() {
return Executors.newCachedThreadPool(ThingsBoardThreadFactory.forName("request-executor"));
}
}

View File

@ -0,0 +1,182 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.client;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.californium.core.network.CoapEndpoint;
import org.eclipse.californium.core.network.config.NetworkConfig;
import org.eclipse.californium.core.observe.ObservationStore;
import org.eclipse.californium.scandium.DTLSConnector;
import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
import org.eclipse.leshan.client.californium.LeshanClient;
import org.eclipse.leshan.client.californium.LeshanClientBuilder;
import org.eclipse.leshan.client.engine.DefaultRegistrationEngineFactory;
import org.eclipse.leshan.client.object.Security;
import org.eclipse.leshan.client.object.Server;
import org.eclipse.leshan.client.resource.BaseInstanceEnabler;
import org.eclipse.leshan.client.resource.DummyInstanceEnabler;
import org.eclipse.leshan.client.resource.ObjectsInitializer;
import org.eclipse.leshan.client.servers.ServerIdentity;
import org.eclipse.leshan.core.californium.EndpointFactory;
import org.eclipse.leshan.core.model.InvalidDDFFileException;
import org.eclipse.leshan.core.model.LwM2mModel;
import org.eclipse.leshan.core.model.ObjectLoader;
import org.eclipse.leshan.core.model.ObjectModel;
import org.eclipse.leshan.core.model.StaticModel;
import org.eclipse.leshan.core.node.codec.DefaultLwM2mDecoder;
import org.eclipse.leshan.core.node.codec.DefaultLwM2mEncoder;
import org.eclipse.leshan.core.response.ReadResponse;
import javax.security.auth.Destroyable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import static org.eclipse.leshan.client.object.Security.noSec;
import static org.eclipse.leshan.core.LwM2mId.ACCESS_CONTROL;
import static org.eclipse.leshan.core.LwM2mId.DEVICE;
import static org.eclipse.leshan.core.LwM2mId.SECURITY;
import static org.eclipse.leshan.core.LwM2mId.SERVER;
@Slf4j
public class Lwm2mClient extends BaseInstanceEnabler implements Destroyable {
@Getter
@Setter
private String name;
@Getter
@Setter
private LeshanClient leshanClient;
private List<ObjectModel> models;
private Security security;
private NetworkConfig coapConfig;
private static final List<Integer> supportedResources = Collections.singletonList(2);
private String data = UUID.randomUUID().toString();
private String serverUri;
private String endpoint;
public Lwm2mClient(String serverUri, String endpoint) {
this.serverUri = serverUri;
this.endpoint = endpoint;
}
public Lwm2mClient() {
}
public void initClient() throws InvalidDDFFileException, IOException {
String[] resources = new String[]{"0.xml", "1.xml", "2.xml", "3.xml"};
models = new ArrayList<>();
for (String resourceName : resources) {
models.addAll(ObjectLoader.loadDdfFile(getClass().getClassLoader().getResourceAsStream("lwm2m/" + resourceName), resourceName));
}
security = noSec(serverUri, 123);
coapConfig = new NetworkConfig().setString("COAP_PORT", StringUtils.substringAfterLast(serverUri, ":"));
setName(endpoint);
LeshanClient leshanClient;
LwM2mModel model = new StaticModel(models);
ObjectsInitializer initializer = new ObjectsInitializer(model);
initializer.setInstancesForObject(SECURITY, security);
initializer.setInstancesForObject(SERVER, new Server(123, 300));
initializer.setInstancesForObject(DEVICE, this);
initializer.setClassForObject(ACCESS_CONTROL, DummyInstanceEnabler.class);
DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder();
dtlsConfig.setRecommendedCipherSuitesOnly(true);
dtlsConfig.setClientOnly();
DefaultRegistrationEngineFactory engineFactory = new DefaultRegistrationEngineFactory();
engineFactory.setReconnectOnUpdate(false);
engineFactory.setResumeOnConnect(true);
EndpointFactory endpointFactory = new EndpointFactory() {
@Override
public CoapEndpoint createUnsecuredEndpoint(InetSocketAddress address, NetworkConfig coapConfig,
ObservationStore store) {
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
builder.setInetSocketAddress(address);
builder.setNetworkConfig(coapConfig);
return builder.build();
}
@Override
public CoapEndpoint createSecuredEndpoint(DtlsConnectorConfig dtlsConfig, NetworkConfig coapConfig,
ObservationStore store) {
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
DtlsConnectorConfig.Builder dtlsConfigBuilder = new DtlsConnectorConfig.Builder(dtlsConfig);
builder.setConnector(new DTLSConnector(dtlsConfigBuilder.build()));
builder.setNetworkConfig(coapConfig);
return builder.build();
}
};
LeshanClientBuilder builder = new LeshanClientBuilder(endpoint);
builder.setObjects(initializer.createAll());
builder.setCoapConfig(coapConfig);
builder.setDtlsConfig(dtlsConfig);
builder.setRegistrationEngineFactory(engineFactory);
builder.setEndpointFactory(endpointFactory);
builder.setDecoder(new DefaultLwM2mDecoder(false));
builder.setEncoder(new DefaultLwM2mEncoder(false));
leshanClient = builder.build();
setLeshanClient(leshanClient);
leshanClient.start();
}
@Override
public ReadResponse read(ServerIdentity identity, int resourceId) {
if (resourceId == 2) {
return ReadResponse.success(resourceId, data);
}
return ReadResponse.notFound();
}
@Override
public List<Integer> getAvailableResourceIds(ObjectModel model) {
return supportedResources;
}
@SneakyThrows
public void send(String data) {
this.data = data;
fireResourcesChange(2);
}
@Override
public void destroy() {
if (leshanClient != null) {
leshanClient.destroy(true);
}
}
}

View File

@ -0,0 +1,14 @@
package org.thingsboard.monitoring.client;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.stereotype.Component;
@Component
public class TbClientFactory {
@Lookup
public TbRestClient createClient() {
return null;
}
}

View File

@ -0,0 +1,43 @@
package org.thingsboard.monitoring.client;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.thingsboard.monitoring.config.TransportType;
import org.thingsboard.monitoring.data.TransportInfo;
import org.thingsboard.rest.client.RestClient;
import org.thingsboard.server.common.data.Device;
import java.time.Duration;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TbRestClient extends RestClient {
@Value("${monitoring.auth.username}")
private String username;
@Value("${monitoring.auth.password}")
private String password;
public TbRestClient(@Value("${monitoring.auth.base_url}") String baseUrl) {
super(new RestTemplateBuilder()
.setConnectTimeout(Duration.ofSeconds(5))
.setReadTimeout(Duration.ofSeconds(2))
.build(), baseUrl);
}
public String logIn() {
login(username, password);
return getToken();
}
public Device createDeviceForMonitoringIfNotExists(TransportInfo transportInfo, String deviceName) {
// getTenantDevice(name)
// .orElseGet(() -> {
// Device device =
// })
}
}

View File

@ -0,0 +1,123 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.client;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.monitoring.data.cmd.CmdsWrapper;
import org.thingsboard.monitoring.data.cmd.TimeseriesSubscriptionCmd;
import org.thingsboard.monitoring.data.cmd.TimeseriesUpdate;
import java.net.URI;
import java.nio.channels.NotYetConnectedException;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@Slf4j
public class WsClient extends WebSocketClient {
private volatile String lastMsg;
private CountDownLatch reply;
private CountDownLatch update;
public WsClient(URI serverUri) {
super(serverUri);
}
@Override
public void onOpen(ServerHandshake serverHandshake) {
}
@Override
public void onMessage(String s) {
lastMsg = s;
if (reply != null) {
reply.countDown();
}
if (update != null) {
update.countDown();
}
}
@Override
public void onClose(int i, String s, boolean b) {
log.debug("WebSocket client is closed");
}
@Override
public void onError(Exception e) {
log.error("WebSocket client error:", e);
}
public void registerWaitForUpdate() {
lastMsg = null;
update = new CountDownLatch(1);
}
@Override
public void send(String text) throws NotYetConnectedException {
reply = new CountDownLatch(1);
super.send(text);
}
public void subscribeForTelemetry(UUID deviceId, String telemetryKey) {
TimeseriesSubscriptionCmd subCmd = new TimeseriesSubscriptionCmd();
subCmd.setEntityType("DEVICE");
subCmd.setEntityId(deviceId.toString());
subCmd.setScope("LATEST_TELEMETRY");
subCmd.setKeys(telemetryKey);
subCmd.setCmdId(RandomUtils.nextInt(0, 100));
CmdsWrapper wrapper = new CmdsWrapper();
wrapper.setTsSubCmds(List.of(subCmd));
send(JacksonUtil.toString(wrapper));
}
public String waitForUpdate(long ms) {
try {
if (update.await(ms, TimeUnit.MILLISECONDS)) {
return lastMsg;
}
} catch (InterruptedException e) {
log.debug("Failed to await reply", e);
}
return null;
}
public String waitForReply(int ms) {
try {
if (reply.await(ms, TimeUnit.MILLISECONDS)) {
return lastMsg;
}
} catch (InterruptedException e) {
log.debug("Failed to await reply", e);
}
return null;
}
public Object getTelemetryKeyUpdate(String key) {
if (lastMsg == null) return null;
TimeseriesUpdate update = JacksonUtil.fromString(lastMsg, TimeseriesUpdate.class);
return update.getLatest(key);
}
}

View File

@ -0,0 +1,32 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.config;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.util.UUID;
@Data
public class DeviceConfig {
private UUID id;
private String accessToken;
public void setId(String id) {
this.id = StringUtils.isNotEmpty(id) ? UUID.fromString(id) : null;
}
}

View File

@ -0,0 +1,30 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.config;
import lombok.Data;
@Data
public class MonitoringTargetConfig {
private String baseUrl;
private DeviceConfig device;
@Override
public String toString() {
return "Monitoring target [base url: '" + baseUrl + "', device: " + device.getId() + "]";
}
}

View File

@ -0,0 +1,36 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.config;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.thingsboard.monitoring.service.TransportMonitoringService;
import org.thingsboard.monitoring.service.impl.CoapTransportMonitoringService;
import org.thingsboard.monitoring.service.impl.HttpTransportMonitoringService;
import org.thingsboard.monitoring.service.impl.Lwm2mTransportMonitoringService;
import org.thingsboard.monitoring.service.impl.MqttTransportMonitoringService;
@AllArgsConstructor
@Getter
public enum TransportType {
MQTT(MqttTransportMonitoringService.class),
COAP(CoapTransportMonitoringService.class),
LWM2M(Lwm2mTransportMonitoringService.class),
HTTP(HttpTransportMonitoringService.class);
private final Class<? extends TransportMonitoringService<?>> monitoringServiceClass;
}

View File

@ -0,0 +1,18 @@
package org.thingsboard.monitoring.config;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
@Getter
public class WsConfig {
@Value("${monitoring.ws.base_url}")
private String baseUrl;
@Value("${monitoring.ws.request_timeout_ms}")
private int requestTimeoutMs;
@Value("${monitoring.ws.check_timeout_ms}")
private int resultCheckTimeoutMs;
}

View File

@ -0,0 +1,36 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.config.service;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.thingsboard.monitoring.config.TransportType;
import org.thingsboard.rest.client.RestClient;
import javax.annotation.PostConstruct;
@Component
@ConditionalOnProperty(name = "monitoring.transports.coap.enabled", havingValue = "true")
@ConfigurationProperties(prefix = "monitoring.transports.coap")
public class CoapTransportMonitoringServiceConfig extends TransportMonitoringServiceConfig {
@Override
public TransportType getTransportType() {
return TransportType.COAP;
}
}

View File

@ -0,0 +1,31 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.config.service;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.thingsboard.monitoring.config.TransportType;
@Component
@ConditionalOnProperty(name = "monitoring.transports.http.enabled", havingValue = "true")
@ConfigurationProperties(prefix = "monitoring.transports.http")
public class HttpTransportMonitoringServiceConfig extends TransportMonitoringServiceConfig {
@Override
public TransportType getTransportType() {
return TransportType.HTTP;
}
}

View File

@ -0,0 +1,31 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.config.service;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.thingsboard.monitoring.config.TransportType;
@Component
@ConditionalOnProperty(name = "monitoring.transports.lwm2m.enabled", havingValue = "true")
@ConfigurationProperties(prefix = "monitoring.transports.lwm2m")
public class Lwm2mTransportMonitoringServiceConfig extends TransportMonitoringServiceConfig {
@Override
public TransportType getTransportType() {
return TransportType.LWM2M;
}
}

View File

@ -0,0 +1,36 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.config.service;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.thingsboard.monitoring.config.TransportType;
@Component
@ConditionalOnProperty(name = "monitoring.transports.mqtt.enabled", havingValue = "true")
@ConfigurationProperties(prefix = "monitoring.transports.mqtt")
@Data
public class MqttTransportMonitoringServiceConfig extends TransportMonitoringServiceConfig {
private Integer qos;
@Override
public TransportType getTransportType() {
return TransportType.MQTT;
}
}

View File

@ -0,0 +1,37 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.config.service;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.thingsboard.monitoring.config.MonitoringTargetConfig;
import org.thingsboard.monitoring.config.TransportType;
import java.util.List;
@Data
public abstract class TransportMonitoringServiceConfig {
private int monitoringRateMs;
private int requestTimeoutMs;
private int initialDelayMs;
@Value("${monitoring.failure_threshold}")
private int failureThreshold;
private List<MonitoringTargetConfig> targets;
public abstract TransportType getTransportType();
}

View File

@ -0,0 +1,4 @@
package org.thingsboard.monitoring.data;
public class MonitoringStats {
}

View File

@ -0,0 +1,25 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.data;
import lombok.Data;
import org.thingsboard.monitoring.config.TransportType;
@Data
public class TransportInfo {
private final TransportType transportType;
private final String url;
}

View File

@ -0,0 +1,27 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.data.cmd;
import lombok.Data;
import java.util.List;
@Data
public class CmdsWrapper {
private List<TimeseriesSubscriptionCmd> tsSubCmds;
}

View File

@ -0,0 +1,40 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.data.cmd;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TimeseriesSubscriptionCmd {
private int cmdId;
private String entityType;
private String entityId;
private String keys;
private String scope;
public String getType() {
return "TIMESERIES";
}
}

View File

@ -0,0 +1,37 @@
package org.thingsboard.monitoring.data.cmd;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.data.util.Pair;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class TimeseriesUpdate {
private final int cmdId;
private final int errorCode;
private final String errorMsg;
private Map<String, List<List<Object>>> data;
public Object getLatest(String key) {
if (!data.containsKey(key)) return null;
return data.get(key).stream()
.map(tsAndValue -> {
if (tsAndValue == null || tsAndValue.size() != 2) {
return null;
}
long ts = Long.parseLong(tsAndValue.get(0).toString());
Object value = tsAndValue.get(1);
return Pair.of(ts, value);
})
.filter(Objects::nonNull)
.max(Comparator.comparing(Pair::getFirst))
.map(Pair::getSecond).orElse(null);
}
}

View File

@ -0,0 +1,34 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.data.notification;
import lombok.Getter;
import org.thingsboard.monitoring.data.TransportInfo;
@Getter
public class MonitoringFailureNotificationInfo extends NotificationInfo {
private final Exception error;
public MonitoringFailureNotificationInfo(TransportInfo transportInfo, Exception error) {
super(transportInfo);
this.error = error;
}
@Override
public NotificationType getType() {
return NotificationType.MONITORING_FAILURE;
}
}

View File

@ -0,0 +1,29 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.data.notification;
import org.thingsboard.monitoring.data.TransportInfo;
public class MonitoringRecoveryNotificationInfo extends NotificationInfo {
public MonitoringRecoveryNotificationInfo(TransportInfo transportInfo) {
super(transportInfo);
}
@Override
public NotificationType getType() {
return NotificationType.MONITORING_RECOVERY;
}
}

View File

@ -0,0 +1,27 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.data.notification;
import lombok.Data;
import org.thingsboard.monitoring.data.TransportInfo;
@Data
public abstract class NotificationInfo {
private final TransportInfo transportInfo;
public abstract NotificationType getType();
}

View File

@ -0,0 +1,23 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.data.notification;
public enum NotificationType {
TRANSPORT_FAILURE,
MONITORING_FAILURE,
TRANSPORT_RECOVERY,
MONITORING_RECOVERY;
}

View File

@ -0,0 +1,35 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.data.notification;
import lombok.Getter;
import org.thingsboard.monitoring.data.TransportInfo;
@Getter
public class TransportFailureNotificationInfo extends NotificationInfo {
private final Exception error;
public TransportFailureNotificationInfo(TransportInfo transportInfo, Exception error) {
super(transportInfo);
this.error = error;
}
@Override
public NotificationType getType() {
return NotificationType.TRANSPORT_FAILURE;
}
}

View File

@ -0,0 +1,29 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.data.notification;
import org.thingsboard.monitoring.data.TransportInfo;
public class TransportRecoveryNotificationInfo extends NotificationInfo {
public TransportRecoveryNotificationInfo(TransportInfo transportInfo) {
super(transportInfo);
}
@Override
public NotificationType getType() {
return NotificationType.TRANSPORT_RECOVERY;
}
}

View File

@ -0,0 +1,42 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.notification;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.thingsboard.monitoring.notification.channels.NotificationChannel;
import org.thingsboard.monitoring.data.notification.NotificationInfo;
import java.util.List;
@Service
@RequiredArgsConstructor
@Slf4j
public class NotificationService {
private final List<NotificationChannel> notificationChannels;
public void notify(NotificationInfo notificationInfo) {
notificationChannels.forEach(notificationChannel -> {
try {
notificationChannel.sendNotification(notificationInfo);
} catch (Exception e) {
log.error("Failed to send notification to {} ({})", notificationChannel.getClass().getSimpleName(), notificationInfo, e);
}
});
}
}

View File

@ -0,0 +1,59 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.notification.channels;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.thingsboard.monitoring.data.notification.MonitoringFailureNotificationInfo;
import org.thingsboard.monitoring.data.notification.NotificationInfo;
import org.thingsboard.monitoring.data.notification.TransportFailureNotificationInfo;
@Slf4j
public abstract class NotificationChannel {
public abstract void sendNotification(NotificationInfo notificationInfo);
protected String createNotificationMessage(NotificationInfo notificationInfo) {
String message = String.format("[%s transport (%s)]", notificationInfo.getTransportInfo().getTransportType(), notificationInfo.getTransportInfo().getUrl());
switch (notificationInfo.getType()) {
case TRANSPORT_FAILURE:
TransportFailureNotificationInfo transportFailureNotificationInfo = (TransportFailureNotificationInfo) notificationInfo;
message += " Transport failure: " + getErrorMessage(transportFailureNotificationInfo.getError());
break;
case MONITORING_FAILURE:
MonitoringFailureNotificationInfo monitoringFailureNotificationInfo = (MonitoringFailureNotificationInfo) notificationInfo;
message += " Monitoring failure: " + getErrorMessage(monitoringFailureNotificationInfo.getError());
break;
case TRANSPORT_RECOVERY:
message += " Transport is now working";
break;
case MONITORING_RECOVERY:
message += " Monitoring is now working";
break;
default:
throw new UnsupportedOperationException("Notification type " + notificationInfo.getType() + " not supported");
}
return message;
}
protected String getErrorMessage(Exception error) {
return ExceptionUtils.getMessage(error);
}
}

View File

@ -0,0 +1,54 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.notification.channels.impl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.thingsboard.monitoring.notification.channels.NotificationChannel;
import org.thingsboard.monitoring.data.notification.NotificationInfo;
import javax.annotation.PostConstruct;
import java.time.Duration;
import java.util.Map;
@Component
@ConditionalOnProperty(value = "monitoring.notification_channels.slack.enabled", havingValue = "true")
@Slf4j
public class SlackNotificationChannel extends NotificationChannel {
@Value("${monitoring.notification_channels.slack.webhook_url}")
private String webhookUrl;
private RestTemplate restTemplate;
@PostConstruct
private void init() {
restTemplate = new RestTemplateBuilder()
.setConnectTimeout(Duration.ofSeconds(5))
.setReadTimeout(Duration.ofSeconds(2))
.build();
}
@Override
public void sendNotification(NotificationInfo notificationInfo) {
String message = createNotificationMessage(notificationInfo);
restTemplate.postForObject(webhookUrl, Map.of("text", message), String.class);
}
}

View File

@ -0,0 +1,32 @@
package org.thingsboard.monitoring.service;
import org.springframework.stereotype.Service;
import org.thingsboard.monitoring.data.TransportInfo;
@Service
public class MonitoringReporter {
public void reportTransportRequestLatency(TransportInfo transportInfo, long latencyInNanos) {
double latencyInMs = (double) latencyInNanos / 1000_000;
}
public void reportTransportConnectLatency(TransportInfo transportInfo, long latencyInNanos) {
}
public void reportWsUpdateLatency(long latencyInNanos) {
}
public void reportWsConnectLatency(long latencyInNanos) {
}
public void reportLogInLatency(long latencyInNanos) {
}
public void reportFailure(TransportInfo transportInfo, Exception error) {
}
}

View File

@ -0,0 +1,199 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.service;
import com.fasterxml.jackson.databind.node.TextNode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.monitoring.client.TbClientFactory;
import org.thingsboard.monitoring.client.WsClient;
import org.thingsboard.monitoring.config.MonitoringTargetConfig;
import org.thingsboard.monitoring.config.TransportType;
import org.thingsboard.monitoring.config.WsConfig;
import org.thingsboard.monitoring.config.service.TransportMonitoringServiceConfig;
import org.thingsboard.monitoring.data.TransportInfo;
import org.thingsboard.monitoring.data.notification.MonitoringFailureNotificationInfo;
import org.thingsboard.monitoring.data.notification.MonitoringRecoveryNotificationInfo;
import org.thingsboard.monitoring.data.notification.TransportFailureNotificationInfo;
import org.thingsboard.monitoring.data.notification.TransportRecoveryNotificationInfo;
import org.thingsboard.monitoring.notification.NotificationService;
import javax.annotation.PostConstruct;
import java.net.URI;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@Slf4j
public abstract class TransportMonitoringService<C extends TransportMonitoringServiceConfig> {
protected final C config;
protected final MonitoringTargetConfig target;
private TransportInfo transportInfo;
@Autowired
private WsConfig wsConfig;
@Autowired
private NotificationService notificationService;
@Autowired
private MonitoringReporter monitoringReporter;
@Autowired
@Qualifier("monitoringExecutor")
private ScheduledExecutorService monitoringExecutor;
@Autowired
@Qualifier("requestExecutor")
private ExecutorService requestExecutor;
@Autowired
private TbClientFactory tbClientFactory;
private final AtomicInteger transportFailuresCounter = new AtomicInteger();
private final AtomicInteger monitoringFailuresCounter = new AtomicInteger();
private final StopWatch stopWatch = new StopWatch();
protected static final String TEST_TELEMETRY_KEY = "testData";
protected TransportMonitoringService(C config, MonitoringTargetConfig target) {
this.config = config;
this.target = target;
}
@PostConstruct
public void startMonitoring() {
transportInfo = new TransportInfo(getTransportType(), target.getBaseUrl());
// todo: create devices
monitoringExecutor.scheduleWithFixedDelay(() -> {
try {
startStopWatch();
initClient();
monitoringReporter.reportTransportConnectLatency(transportInfo, getElapsedTime());
WsClient wsClient = establishWsClient();
wsClient.registerWaitForUpdate();
String testPayload = createTestPayload(UUID.randomUUID().toString());
startStopWatch();
Future<?> resultFuture = requestExecutor.submit(() -> {
try {
sendTestPayload(testPayload);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
resultFuture.get(config.getRequestTimeoutMs(), TimeUnit.MILLISECONDS);
monitoringReporter.reportTransportRequestLatency(transportInfo, getElapsedTime());
startStopWatch();
wsClient.waitForUpdate(wsConfig.getResultCheckTimeoutMs());
Object update = wsClient.getTelemetryKeyUpdate(TEST_TELEMETRY_KEY);
boolean success = update != null && update.toString().equals(testPayload);
if (!success) {
throw new RuntimeException("No WS update arrived");
}
monitoringReporter.reportWsUpdateLatency(getElapsedTime());
wsClient.closeBlocking();
destroyClient();
} catch (Exception e) {
monitoringReporter.reportFailure(transportInfo, e);
}
}, config.getInitialDelayMs(), config.getMonitoringRateMs(), TimeUnit.MILLISECONDS);
log.info("Started monitoring for transport type {} for target {}", getTransportType(), target);
}
private WsClient establishWsClient() throws Exception {
startStopWatch();
String accessToken = tbClientFactory.createClient().logIn();
monitoringReporter.reportLogInLatency(getElapsedTime());
URI uri = new URI(wsConfig.getBaseUrl() + "/api/ws/plugins/telemetry?token=" + accessToken);
startStopWatch();
WsClient wsClient = new WsClient(uri);
boolean connected = wsClient.connectBlocking(wsConfig.getRequestTimeoutMs(), TimeUnit.MILLISECONDS);
if (!connected) {
throw new IllegalStateException("Failed to establish WS session");
}
wsClient.subscribeForTelemetry(target.getDevice().getId(), TEST_TELEMETRY_KEY);
Optional.ofNullable(wsClient.waitForReply(wsConfig.getRequestTimeoutMs()))
.orElseThrow(() -> new IllegalStateException("Failed to subscribe for telemetry"));
monitoringReporter.reportWsConnectLatency(getElapsedTime());
return wsClient;
}
protected abstract void initClient() throws Exception;
protected String createTestPayload(String testValue) {
return JacksonUtil.newObjectNode().set(TEST_TELEMETRY_KEY, new TextNode(testValue)).toString();
}
protected abstract void sendTestPayload(String payload) throws Exception;
protected abstract void destroyClient() throws Exception;
private void startStopWatch() {
stopWatch.start();
}
private long getElapsedTime() {
stopWatch.stop();
long nanoTime = stopWatch.getNanoTime();
stopWatch.reset();
return nanoTime;
}
private void onTransportFailure(Exception e) {
log.debug("[{}] Transport failure", transportInfo, e);
int failuresCount = transportFailuresCounter.incrementAndGet();
if (failuresCount == config.getFailureThreshold()) {
notificationService.notify(new TransportFailureNotificationInfo(transportInfo, e));
}
}
private void onMonitoringFailure(Exception e) {
log.debug("[{}] Monitoring failure", transportInfo, e);
int failuresCount = monitoringFailuresCounter.incrementAndGet();
if (failuresCount == config.getFailureThreshold()) {
notificationService.notify(new MonitoringFailureNotificationInfo(transportInfo, e));
}
}
private void onTransportIsOk() {
log.debug("[{}] Transport is OK", transportInfo);
if (transportFailuresCounter.get() >= config.getFailureThreshold()) {
notificationService.notify(new TransportRecoveryNotificationInfo(transportInfo));
}
if (monitoringFailuresCounter.get() >= config.getFailureThreshold()) {
notificationService.notify(new MonitoringRecoveryNotificationInfo(transportInfo));
}
transportFailuresCounter.set(0);
monitoringFailuresCounter.set(0);
}
protected abstract TransportType getTransportType();
}

View File

@ -0,0 +1,69 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.service.impl;
import org.eclipse.californium.core.CoapClient;
import org.eclipse.californium.core.CoapResponse;
import org.eclipse.californium.core.coap.CoAP;
import org.eclipse.californium.core.coap.MediaTypeRegistry;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.thingsboard.monitoring.config.TransportType;
import org.thingsboard.monitoring.config.MonitoringTargetConfig;
import org.thingsboard.monitoring.config.service.CoapTransportMonitoringServiceConfig;
import org.thingsboard.monitoring.service.TransportMonitoringService;
import java.io.IOException;
@Service
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class CoapTransportMonitoringService extends TransportMonitoringService<CoapTransportMonitoringServiceConfig> {
private CoapClient coapClient;
protected CoapTransportMonitoringService(CoapTransportMonitoringServiceConfig config, MonitoringTargetConfig target) {
super(config, target);
}
@Override
protected void initClient() throws Exception {
String uri = target.getBaseUrl() + "/api/v1/" + target.getDevice().getAccessToken() + "/telemetry";
coapClient = new CoapClient(uri);
coapClient.setTimeout((long) config.getRequestTimeoutMs());
}
@Override
protected void sendTestPayload(String payload) throws Exception {
CoapResponse response = coapClient.post(payload, MediaTypeRegistry.APPLICATION_JSON);
CoAP.ResponseCode code = response.getCode();
if (code.codeClass != CoAP.CodeClass.SUCCESS_RESPONSE.value) {
throw new IOException("COAP client didn't receive success response from transport");
}
}
@Override
protected void destroyClient() throws Exception {
coapClient.shutdown();
coapClient = null;
}
@Override
protected TransportType getTransportType() {
return TransportType.COAP;
}
}

View File

@ -0,0 +1,64 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.service.impl;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.thingsboard.monitoring.config.MonitoringTargetConfig;
import org.thingsboard.monitoring.config.TransportType;
import org.thingsboard.monitoring.config.service.HttpTransportMonitoringServiceConfig;
import org.thingsboard.monitoring.service.TransportMonitoringService;
import javax.annotation.PostConstruct;
import java.time.Duration;
@Service
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class HttpTransportMonitoringService extends TransportMonitoringService<HttpTransportMonitoringServiceConfig> {
private RestTemplate restTemplate;
protected HttpTransportMonitoringService(HttpTransportMonitoringServiceConfig config, MonitoringTargetConfig target) {
super(config, target);
}
@Override
protected void initClient() throws Exception {
if (restTemplate == null) {
restTemplate = new RestTemplateBuilder()
.setConnectTimeout(Duration.ofMillis(config.getRequestTimeoutMs()))
.setReadTimeout(Duration.ofMillis(config.getRequestTimeoutMs()))
.build();
}
}
@Override
protected void sendTestPayload(String payload) throws Exception {
restTemplate.postForObject(target.getBaseUrl() + "/api/v1/" + target.getDevice().getAccessToken() + "/telemetry", payload, String.class);
}
@Override
protected void destroyClient() throws Exception {}
@Override
protected TransportType getTransportType() {
return TransportType.HTTP;
}
}

View File

@ -0,0 +1,64 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.service.impl;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.thingsboard.monitoring.config.MonitoringTargetConfig;
import org.thingsboard.monitoring.config.TransportType;
import org.thingsboard.monitoring.config.service.Lwm2mTransportMonitoringServiceConfig;
import org.thingsboard.monitoring.service.TransportMonitoringService;
import org.thingsboard.monitoring.client.Lwm2mClient;
@Service
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class Lwm2mTransportMonitoringService extends TransportMonitoringService<Lwm2mTransportMonitoringServiceConfig> {
private Lwm2mClient lwm2mClient;
protected Lwm2mTransportMonitoringService(Lwm2mTransportMonitoringServiceConfig config, MonitoringTargetConfig target) {
super(config, target);
}
@Override
protected void initClient() throws Exception {
lwm2mClient = new Lwm2mClient(target.getBaseUrl(), target.getDevice().getAccessToken());
lwm2mClient.initClient();
}
@Override
protected void sendTestPayload(String payload) throws Exception {
lwm2mClient.send(payload);
}
@Override
protected String createTestPayload(String testValue) {
return testValue;
}
@Override
protected void destroyClient() throws Exception {
lwm2mClient.destroy();
lwm2mClient = null;
}
@Override
protected TransportType getTransportType() {
return TransportType.LWM2M;
}
}

View File

@ -0,0 +1,72 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring.service.impl;
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.thingsboard.monitoring.config.TransportType;
import org.thingsboard.monitoring.config.MonitoringTargetConfig;
import org.thingsboard.monitoring.config.service.MqttTransportMonitoringServiceConfig;
import org.thingsboard.monitoring.service.TransportMonitoringService;
@Service
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class MqttTransportMonitoringService extends TransportMonitoringService<MqttTransportMonitoringServiceConfig> {
private MqttAsyncClient mqttClient;
private static final String DEVICE_TELEMETRY_TOPIC = "v1/devices/me/telemetry";
protected MqttTransportMonitoringService(MqttTransportMonitoringServiceConfig config, MonitoringTargetConfig target) {
super(config, target);
}
@Override
protected void initClient() throws Exception {
String clientId = MqttAsyncClient.generateClientId();
mqttClient = new MqttAsyncClient(target.getBaseUrl(), clientId, new MemoryPersistence());
MqttConnectOptions options = new MqttConnectOptions();
options.setUserName(target.getDevice().getAccessToken());
mqttClient.connect(options).waitForCompletion(config.getRequestTimeoutMs());
}
@Override
protected void sendTestPayload(String payload) throws Exception {
MqttMessage message = new MqttMessage();
message.setPayload(payload.getBytes());
message.setQos(config.getQos());
mqttClient.publish(DEVICE_TELEMETRY_TOPIC, message).waitForCompletion(config.getRequestTimeoutMs());
}
@Override
protected void destroyClient() throws Exception {
mqttClient.disconnect();
mqttClient.close();
mqttClient = null;
}
@Override
protected TransportType getTransportType() {
return TransportType.MQTT;
}
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright © 2016-2022 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE configuration>
<configuration scan="true" scanPeriod="10 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org" level="WARN" />
<logger name="org.thingsboard.server" level="INFO" />
<logger name="org.thingsboard.server.monitoring" level="DEBUG" />
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>

View File

@ -0,0 +1,364 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2016-2022 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LWM2M xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.openmobilealliance.org/tech/profiles/LWM2M-v1_1.xsd">
<Object ObjectType="MODefinition">
<Name>LWM2M Security</Name>
<Description1><![CDATA[This LwM2M Object provides the keying material of a LwM2M Client appropriate to access a specified LwM2M Server. One Object Instance SHOULD address a LwM2M Bootstrap-Server.
These LwM2M Object Resources MUST only be changed by a LwM2M Bootstrap-Server or Bootstrap from Smartcard and MUST NOT be accessible by any other LwM2M Server.]]></Description1>
<ObjectID>0</ObjectID>
<ObjectURN>urn:oma:lwm2m:oma:0:1.2</ObjectURN>
<LWM2MVersion>1.1</LWM2MVersion>
<ObjectVersion>1.2</ObjectVersion>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Resources>
<Item ID="0">
<Name>LWM2M Server URI</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>String</Type>
<RangeEnumeration>0..255</RangeEnumeration>
<Units></Units>
<Description><![CDATA[Uniquely identifies the LwM2M Server or LwM2M Bootstrap-Server. The format of the CoAP URI is defined in Section 6 of RFC 7252.]]></Description>
</Item>
<Item ID="1">
<Name>Bootstrap-Server</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Boolean</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Determines if the current instance concerns a LwM2M Bootstrap-Server (true) or a standard LwM2M Server (false)]]></Description>
</Item>
<Item ID="2">
<Name>Security Mode</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..4</RangeEnumeration>
<Units></Units>
<Description><![CDATA[Determines which security mode is used
0: Pre-Shared Key mode
1: Raw Public Key mode
2: Certificate mode
3: NoSec mode
4: Certificate mode with EST]]></Description>
</Item>
<Item ID="3">
<Name>Public Key or Identity</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Opaque</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Stores the LwM2M Client's certificate, public key (RPK mode) or PSK Identity (PSK mode).]]></Description>
</Item>
<Item ID="4">
<Name>Server Public Key</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Opaque</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Stores the LwM2M Server's, respectively LwM2M Bootstrap-Server's, certificate, public key (RPK mode) or trust anchor. The Certificate Mode Resource determines the content of this resource.]]></Description>
</Item>
<Item ID="5">
<Name>Secret Key</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Opaque</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Stores the secret key (PSK mode) or private key (RPK or certificate mode).]]></Description>
</Item>
<Item ID="6">
<Name>SMS Security Mode</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..255</RangeEnumeration>
<Units></Units>
<Description><![CDATA[Determines which SMS security mode is used:
0: Reserved for future use
1: DTLS mode (Device terminated) PSK mode assumed
2: Secure Packet Structure mode (Smartcard terminated)
3: NoSec mode
4: Reserved mode (DTLS mode with multiplexing Security Association support)
5-203 : Reserved for future use
204-255: Proprietary modes]]></Description>
</Item>
<Item ID="7">
<Name>SMS Binding Key Parameters</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Opaque</Type>
<RangeEnumeration>6</RangeEnumeration>
<Units></Units>
<Description><![CDATA[Stores the KIc, KID, SPI and TAR.]]></Description>
</Item>
<Item ID="8">
<Name>SMS Binding Secret Key(s)</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Opaque</Type>
<RangeEnumeration>16,32,48</RangeEnumeration>
<Units></Units>
<Description><![CDATA[Stores the values of the key(s) for the SMS binding.]]></Description>
</Item>
<Item ID="9">
<Name>LwM2M Server SMS Number</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[MSISDN used by the LwM2M Client to send messages to the LwM2M Server via the SMS binding.]]></Description>
</Item>
<Item ID="10">
<Name>Short Server ID</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>1..65534</RangeEnumeration>
<Units></Units>
<Description><![CDATA[This identifier uniquely identifies each LwM2M Server configured for the LwM2M Client.
This Resource MUST be set when the Bootstrap-Server Resource has a value of 'false'.
The values ID:0 and ID:65535 values MUST NOT be used for identifying the LwM2M Server.]]></Description>
</Item>
<Item ID="11">
<Name>Client Hold Off Time</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units>s</Units>
<Description><![CDATA[The number of seconds to wait before initiating a Client Initiated Bootstrap once the LwM2M Client has determined it should initiate this bootstrap mode.
In case client initiated bootstrap is supported by the LwM2M Client, this resource MUST be supported. This information is relevant for use with a Bootstrap-Server only.]]></Description>
</Item>
<Item ID="12">
<Name>Bootstrap-Server Account Timeout</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units>s</Units>
<Description><![CDATA[The LwM2M Client MUST purge the LwM2M Bootstrap-Server Account after the timeout value given by this resource. The lowest timeout value is 1.
If the value is set to 0, or if this resource is not instantiated, the Bootstrap-Server Account lifetime is infinite.]]></Description>
</Item>
<Item ID="13">
<Name>Matching Type</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..3</RangeEnumeration>
<Units></Units>
<Description><![CDATA[The Matching Type Resource specifies how the certificate or raw public key in in the Server Public Key is presented. Four values are currently defined:
0: Exact match. This is the default value and also corresponds to the functionality of LwM2M v1.0. Hence, if this resource is not present then the content of the Server Public Key Resource corresponds to this value.
1: SHA-256 hash [RFC6234]
2: SHA-384 hash [RFC6234]
3: SHA-512 hash [RFC6234]]]></Description>
</Item>
<Item ID="14">
<Name>SNI</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[This resource holds the value of the Server Name Indication (SNI) value to be used during the TLS handshake. When this resource is present then the LwM2M Server URI acts as the address of the service while the SNI value is used for matching a presented certificate, or PSK identity.]]></Description>
</Item>
<Item ID="15">
<Name>Certificate Usage</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..3</RangeEnumeration>
<Units></Units>
<Description><![CDATA[The Certificate Usage Resource specifies the semantic of the certificate or
raw public key stored in the Server Public Key Resource, which is used to match
the certificate presented in the TLS/DTLS handshake. The currently defined values are
0 for "CA constraint", 1 for "service certificate constraint", 2 for "trust anchor
assertion", and 3 for "domain-issued certificate". When this resource is absent,
value (3) for domain issued certificate mode is assumed. More details about the
semantic of each value can be found in the security consideration section of the
LwM2M specification.]]></Description>
</Item>
<Item ID="16">
<Name>DTLS/TLS Ciphersuite</Name>
<Operations></Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[When this resource is present it instructs the TLS/DTLS client to propose the indicated ciphersuite(s) in the ClientHello of the handshake. A ciphersuite is indicated as a 32-bit integer value. The IANA TLS ciphersuite registry is maintained at https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml. As an example, the TLS_PSK_WITH_AES_128_CCM_8 ciphersuite is represented with the following string "0xC0,0xA8". To form an integer value the two values are concatenated. In this example, the value is 0xc0a8 or 49320.]]></Description>
</Item>
<Item ID="17"><Name>OSCORE Security Mode</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Objlnk</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it provides a link to the OSCORE Object Instance and OSCORE MUST be used by the LwM2M Client with the linked OSCORE Object Instance.]]></Description>
</Item>
<Item ID="18">
<Name>Groups To Use by Client</Name>
<Operations></Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..65535</RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it indicates what groups the LwM2M Client should use with a LwM2M Server/LwM2M Bootstrap-Server (ordered from most preferred to least preferred). Resource instance 0 indicates the most preferred group. The values are taken from Section 4.2.7 of RFC 8446. An example is secp256r1 (0x0017).]]></Description>
</Item>
<Item ID="19">
<Name>Signature Algorithms Supported by Server</Name>
<Operations></Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..65535</RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it indicates what signature algorithms the LwM2M Server/LwM2M Bootstrap-Server supports. The values are taken from Section 4.2.3 of RFC 8446. An example is ecdsa_secp256r1_sha256(0x0403).]]></Description>
</Item>
<Item ID="20"><Name>Signature Algorithms To Use by Client</Name>
<Operations></Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..65535</RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it indicates what signature algorithms the LwM2M Client should use with a LwM2M Server/LwM2M Bootstrap-Server (ordered from most preferred to least preferred). Resource instance 0 indicates the most preferred group. The values are taken from Section 4.2.3 of RFC 8446. An example is ecdsa_secp256r1_sha256(0x0403).]]></Description>
</Item>
<Item ID="21">
<Name>Signature Algorithm Certs Supported by Server</Name>
<Operations></Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..65535</RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it indicates what certificate-specific signature algorithms the the LwM2M Server/LwM2M Bootstrap-Server supports. The values are taken from Section 4.2.3 of RFC 8446. An example is ecdsa_secp256r1_sha256(0x0403).]]></Description>
</Item>
<Item ID="22">
<Name>TLS 1.3 Features To Use by Client</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..65535</RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it indicates which features the LwM2M Client should use with the respective LwM2M Server/LwM2M Bootstrap-Server. The bitmask values listed below are defined. A bit value of '0' means the feature should not be used. bit(0) - PSK Plain, bit(1) - 0-RTT, bit(2) - PSK with PFS, bit(3) - Certificate-based Authentication. Bit(4) to bit(31) are reserved.]]></Description>
</Item>
<Item ID="23">
<Name>TLS Extensions Supported by Server</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..65535</RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it indicates what extensions the LwM2M Server/LwM2M Bootstrap-Server supports in form of a bitmap. The following values are defined: bit(0) - Server Name Indication (RFC 6066), bit (1) - Max Fragment Length (RFC 6066), bit (2) - Status Request (RFC 6066), bit (3) - Heartbeat (RFC 6520), bit (4) - Application Layer Protocol Negotiation (RFC 7301), bit (5) - Signed Certificate Timestamp (RFC 6962), bit (6) - Certificate Compression (draft-ietf-tls-certificate-compression), bit (7) - Record Size Limit (RFC 8449), bit (8) - Ticket Pinning (draft-ietf-tls-pinning-ticket), bit (9) - Certificate Authorities (RFC 8446), bit (10) - OID Filters (RFC 8446), bit (11) - Post Handshake Auth (RFC 8446), bit (12) - Connection ID (draft-ietf-tls-dtls-connection-id/draft-ietf-tls-dtls13). Bit(13) to bit(31) are reserved. ]]></Description>
</Item>
<Item ID="24">
<Name>TLS Extensions To Use by Client</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..65535</RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it indicates what extensions the LwM2M Client should use with the LwM2M Server/LwM2M Bootstrap-Server in form of a bitmap. The following values are defined: bit(0) - Server Name Indication (RFC 6066), bit (1) - Max Fragment Length (RFC 6066), bit (2) - Status Request (RFC 6066), bit (3) - Heartbeat (RFC 6520), bit (4) - Application Layer Protocol Negotiation (RFC 7301), bit (5) - Signed Certificate Timestamp (RFC 6962), bit (6) - Certificate Compression (draft-ietf-tls-certificate-compression), bit (7) - Record Size Limit (RFC 8449), bit (8) - Ticket Pinning (draft-ietf-tls-pinning-ticket), bit (9) - Certificate Authorities (RFC 8446), bit (10) - OID Filters (RFC 8446), bit (11) - Post Handshake Auth (RFC 8446), bit (12) - Connection ID (draft-ietf-tls-dtls-connection-id/draft-ietf-tls-dtls13). Bit(13) to bit(31) are reserved. ]]></Description>
</Item>
<Item ID="25">
<Name>Secondary LwM2M Server URI</Name>
<Operations></Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration>0..255</RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is present then the LwM2M Server URI in the Security Object, Resource ID 0, is augmented with information about further LwM2M Server URIs that can be used with the same security information found in the LwM2M Security Object. This is useful when a LwM2M Server is reachable via two different transport bindings (i.e. URIs). For example when the same server is reachable with two different URIs, such as a "coaps" and a "coaps+tcp" URI scheme.]]></Description>
</Item>
<Item ID="26"><Name>MQTT Server</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Objlnk</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it provides a link to a MQTT Server Object Instance, which offers additional configuration information for use with this MQTT server. This Resource is used only when the URI scheme in the LwM2M Server URI Resource indicates the use of MQTT.]]></Description>
</Item>
<Item ID="27"><Name>LwM2M COSE Security</Name>
<Operations></Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Objlnk</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it provides a links to LwM2M COSE Object Instances, which contain security-relevant configuration information for use with COSE.]]></Description>
</Item>
<Item ID="28"><Name>RDS Destination Port</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..15</RangeEnumeration>
<Units></Units>
<Description><![CDATA[This resource provides the default RDS Destination Port Number (as defined in 3GPP TS 24.250) to use for contacting the LwM2M or Bootstrap Server when communicating through the SCEF across the Non-IP binding.]]></Description>
</Item>
<Item ID="29"><Name>RDS Source Port</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..15</RangeEnumeration>
<Units></Units>
<Description><![CDATA[This resource provides the default RDS Source Port Number (as defined in 3GPP TS 24.250) to use for contacting the LwM2M or Bootstrap Server when communicating through the SCEF across the Non-IP binding.]]></Description>
</Item>
<Item ID="30"><Name>RDS Application ID</Name>
<Operations></Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[This resource provides the Application ID (as defined in 3GPP TS 24.250) to use for querying the SCEF for the source and destination port numbers for contacting the LwM2M or Bootstrap Server when communicating through the SCEF across the Non-IP binding.]]></Description>
</Item>
</Resources>
<Description2><![CDATA[]]></Description2>
</Object>
</LWM2M>

View File

@ -0,0 +1,319 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2016-2022 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LWM2M xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.openmobilealliance.org/tech/profiles/LWM2M-v1_1.xsd">
<Object ObjectType="MODefinition">
<Name>LwM2M Server</Name>
<Description1><![CDATA[This LwM2M Objects provides the data related to a LwM2M Server. A Bootstrap-Server has no such an Object Instance associated to it.]]></Description1>
<ObjectID>1</ObjectID>
<ObjectURN>urn:oma:lwm2m:oma:1:1.2</ObjectURN>
<LWM2MVersion>1.2</LWM2MVersion>
<ObjectVersion>1.2</ObjectVersion>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Resources>
<Item ID="0">
<Name>Short Server ID</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>1..65534</RangeEnumeration>
<Units></Units>
<Description><![CDATA[Used as link to associate server Object Instance.]]></Description>
</Item>
<Item ID="1">
<Name>Lifetime</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units>s</Units>
<Description><![CDATA[Specify the lifetime of the registration in seconds (see Client Registration Interface). If the value is set to 0, the lifetime is infinite.]]></Description>
</Item>
<Item ID="2">
<Name>Default Minimum Period</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units>s</Units>
<Description><![CDATA[The default value the LwM2M Client should use for the Minimum Period of an Observation in the absence of this parameter being included in an Observation.
If this Resource doesnt exist, the default value is 0.]]></Description>
</Item>
<Item ID="3">
<Name>Default Maximum Period</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units>s</Units>
<Description><![CDATA[The default value the LwM2M Client should use for the Maximum Period of an Observation in the absence of this parameter being included in an Observation.]]></Description>
</Item>
<Item ID="4">
<Name>Disable</Name>
<Operations>E</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type></Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this Resource is executed, this LwM2M Server Object is disabled for a certain period defined in the Disabled Timeout Resource. After receiving "Execute" operation, LwM2M Client MUST send response of the operation and perform de-registration process, and underlying network connection between the Client and Server MUST be disconnected to disable the LwM2M Server account.
After the above process, the LwM2M Client MUST NOT send any message to the Server and ignore all the messages from the LwM2M Server for the period.]]></Description>
</Item>
<Item ID="5">
<Name>Disable Timeout</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units>s</Units>
<Description><![CDATA[A period to disable the Server. After this period, the LwM2M Client MUST perform registration process to the Server. If this Resource is not set, a default timeout value is 86400 (1 day).]]></Description>
</Item>
<Item ID="6">
<Name>Notification Storing When Disabled or Offline</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Boolean</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If true, the LwM2M Client stores "Notify" operations to the LwM2M Server while the LwM2M Server account is disabled or the LwM2M Client is offline. After the LwM2M Server account is enabled or the LwM2M Client is online, the LwM2M Client reports the stored "Notify" operations to the Server.
If false, the LwM2M Client discards all the "Notify" operations or temporarily disables the Observe function while the LwM2M Server is disabled or the LwM2M Client is offline.
The default value is true.
The maximum number of storing Notifications per Server is up to the implementation.]]></Description>
</Item>
<Item ID="7">
<Name>Binding</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[The possible values are those listed in the LwM2M Core Specification. This Resource defines the transport binding configured for the LwM2M Client.
If the LwM2M Client supports the binding specified in this Resource, the LwM2M Client MUST use that transport for the Current Binding Mode.]]></Description>
</Item>
<Item ID="8">
<Name>Registration Update Trigger</Name>
<Operations>E</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type></Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this Resource is executed the LwM2M Client MUST perform an "Update" operation with this LwM2M Server. The LwM2M Client can use a transport binding supported in the Current Binding Mode, Preferred Transport resource or the transport specified as an argument in the Registration Update Trigger.]]></Description>
</Item>
<Item ID="9">
<Name>Bootstrap-Request Trigger</Name>
<Operations>E</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type></Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[When this Resource is executed the LwM2M Client MUST initiate a "Client Initiated Bootstrap" procedure in using the LwM2M Bootstrap-Server Account.]]></Description>
</Item>
<Item ID="10">
<Name>APN Link</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Objlnk</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it provides a link to the APN connection profile Object Instance (OMNA registered Object ID:11) to be used to communicate with this server.]]></Description>
</Item>
<Item ID="11">
<Name>TLS-DTLS Alert Code</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..255</RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it contains the most recent TLS / DTLS alert message received from the LwM2M Server respective represented by the AlertDescription defined in Section 7.2 of RFC 5246. This resource set by the LwM2M Client may help the LwM2M Bootstrap-Server to determine the cause of TLS/DTLS connection failure with the respective LwM2M Server.]]></Description>
</Item>
<Item ID="12">
<Name>Last Bootstrapped</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Time</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it represents the last time that the bootstrap server updated this LwM2M Server Account. The LwM2M Client is responsible for updating this value. When the Bootstrap Server detects that this LwM2M Server Account is "out-of-date", the Bootstrap Server can update the LwM2M Server Account as represented by the LwM2M Server object instance.]]></Description>
</Item>
<Item ID="13">
<Name>Registration Priority Order</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[The LwM2M Client sequences the LwM2M Server registrations in increasing order of this value. If this value is not defined, registration attempts to this server are not impacted by other server registrations.]]></Description>
</Item>
<Item ID="14">
<Name>Initial Registration Delay Timer</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units>s</Units>
<Description><![CDATA[The delay, in seconds, before registration is attempted for this LwM2M Server based upon the completion of registration of the previous LwM2M Server in the registration order. This is only applied until the first successful registration after a successful bootstrapping sequence.]]></Description>
</Item>
<Item ID="15">
<Name>Registration Failure Block</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Boolean</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[When set to true and registration to this LwM2M server fails, the LwM2M Client blocks registration to other servers in the order. When set to false, the LwM2M Client proceeds with registration to the next server in the order.]]></Description>
</Item>
<Item ID="16">
<Name>Bootstrap on Registration Failure</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Boolean</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If set to true, this indicates that the LwM2M Client should re-bootstrap when either registration is explicitly rejected by the LwM2M Server or registration is considered as failing as dictated by the other resource settings. If set to false, the LwM2M Client will continue with the registration attempts as dictated by the other resource settings.]]></Description>
</Item>
<Item ID="17">
<Name>Communication Retry Count</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[The number of successive communication attempts before which a communication sequence is considered as failed.]]></Description>
</Item>
<Item ID="18">
<Name>Communication Retry Timer</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units>s</Units>
<Description><![CDATA[The delay, in seconds, between successive communication attempts in a communication sequence. This value is multiplied by two to the power of the communication retry attempt minus one (2**(retry attempt-1)) to create an exponential back-off.]]></Description>
</Item>
<Item ID="19">
<Name>Communication Sequence Delay Timer</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units>s</Units>
<Description><![CDATA[The delay, in seconds, between successive communication sequences. A communication sequence is defined as the exhaustion of the Communication Retry Count and Communication Retry Timer values. A communication sequence can be applied to server registrations or bootstrapping attempts. MAX_VALUE means do not perform another communication sequence.]]></Description>
</Item>
<Item ID="20">
<Name>Communication Sequence Retry Count</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[The number of successive communication sequences before which a registration attempt is considered as failed.]]></Description>
</Item>
<Item ID="21">
<Name>Trigger</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Boolean</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Using the Trigger Resource a LwM2M Client can indicate whether it is reachable over SMS (value set to 'true') or not (value set to 'false'). The default value (resource not present) is 'false'. When set to 'true' the LwM2M Server MAY, for example, request the LwM2M Client to perform operations, such as the "Update" operation by sending an "Execute" operation on "Registration Update Trigger" Resource via SMS. No SMS response is expected for such a message.]]></Description>
</Item>
<Item ID="22">
<Name>Preferred Transport</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration>The possible values are those listed in the LwM2M Core Specification</RangeEnumeration>
<Units></Units>
<Description><![CDATA[Only a single transport binding SHALL be present. When the LwM2M client supports multiple transports, it MAY use this transport to initiate a connection. This resource can also be used to switch between multiple transports e.g. a non-IP device can switch to UDP transport to perform firmware updates.]]></Description>
</Item>
<Item ID="23"><Name>Mute Send</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Boolean</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If true or the Resource is not present, the LwM2M Client Send command capability is de-activated.
If false, the LwM2M Client Send Command capability is activated.]]></Description>
</Item>
<Item ID="24">
<Name>Alternate APN Links</Name>
<Operations>RW</Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Objlnk</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[If this resource is defined, it provides links to alternate APN connection profile Object Instance (OMNA registered Object ID:11) to be used to communicate with this server if Resource 10 has configuration conflicts.]]></Description>
</Item>
<Item ID="25">
<Name>Supported Server Versions</Name>
<Operations>RW</Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[This resource provides the supported enabler versions of the server to the client as a set of strings. Format for each string is 1*DIGIT"."1*DIGIT"."1*DIGIT where the third DIGIT is optional.]]></Description>
</Item>
<Item ID="26">
<Name>Default Notification Mode</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..1</RangeEnumeration>
<Units></Units>
<Description><![CDATA[This resource indicates the default mode for observations to be sent: 0 = Non-Confirmable, 1 = Confirmable.]]></Description>
</Item>
<Item ID="27">
<Name>Profile ID Hash Algorithm</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..255</RangeEnumeration>
<Units/>
<Description><![CDATA[If this resource is defined, it contains the hash algorithm the LwM2M Server would prefer the LwM2M Client to use with the dynamically generated mode of creating Profile IDs. The numerical ID value of the 'Suite Identifiers' registered by RFC 6920 is used in this Resource.]]></Description>
</Item>
</Resources>
<Description2></Description2>
</Object>
</LWM2M>

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2016-2022 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LWM2M xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.openmobilealliance.org/tech/profiles/LWM2M.xsd">
<Object ObjectType="MODefinition">
<Name>LwM2M Access Control</Name>
<Description1><![CDATA[Access Control Object is used to check whether the LwM2M Server has access right for performing an operation.]]></Description1>
<ObjectID>2</ObjectID>
<ObjectURN>urn:oma:lwm2m:oma:2:1.1</ObjectURN>
<LWM2MVersion>1.0</LWM2MVersion>
<ObjectVersion>1.1</ObjectVersion>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Resources>
<Item ID="0">
<Name>Object ID</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>1..65534</RangeEnumeration>
<Units></Units>
<Description><![CDATA[Resources 0 and 1 point to the Object Instance for which the Instances of the ACL Resource of that Access Control Object Instance are applicable.]]></Description>
</Item>
<Item ID="1">
<Name>Object Instance ID</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..65535</RangeEnumeration>
<Units></Units>
<Description><![CDATA[See above]]></Description>
</Item>
<Item ID="2">
<Name>ACL</Name>
<Operations>RW</Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..31</RangeEnumeration>
<Units></Units>
<Description><![CDATA[The Resource Instance ID MUST be the Short Server ID of a certain LwM2M Server for which associated access rights are contained in the Resource Instance value.
The Resource Instance ID 0 is a specific ID, determining the ACL Instance which contains the default access rights.
Each bit set in the Resource Instance value, grants an access right to the LwM2M Server to the corresponding operation.
The bit order is specified as below.
1st LSB: R(Read, Observe, Write-Attributes)
2nd LSB: W(Write)
3rd LSB: E(Execute)
4th LSB: D(Delete)
5th LSB: C(Create)
Other bits are reserved for future use.]]></Description>
</Item>
<Item ID="3">
<Name>Access Control Owner</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..65535</RangeEnumeration>
<Units></Units>
<Description><![CDATA[Short Server ID of a certain LwM2M Server; only such an LwM2M Server can manage the Resources of this Object Instance.
The specific value MAX_ID=65535 means this Access Control Object Instance is created and modified during a Bootstrap phase only.]]></Description>
</Item>
</Resources>
<Description2><![CDATA[]]></Description2>
</Object>
</LWM2M>

View File

@ -0,0 +1,290 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2016-2022 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LWM2M xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.openmobilealliance.org/tech/profiles/LWM2M-v1_1.xsd">
<Object ObjectType="MODefinition">
<Name>Device</Name>
<Description1><![CDATA[This LwM2M Object provides a range of device related information which can be queried by the LwM2M Server, and a device reboot and factory reset function.]]></Description1>
<ObjectID>3</ObjectID>
<ObjectURN>urn:oma:lwm2m:oma:3:1.0</ObjectURN>
<LWM2MVersion>1.1</LWM2MVersion>
<ObjectVersion>1.0</ObjectVersion>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Resources>
<Item ID="0">
<Name>Manufacturer</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Human readable manufacturer name]]></Description>
</Item>
<Item ID="1">
<Name>Model Number</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[A model identifier (manufacturer specified string)]]></Description>
</Item>
<Item ID="2">
<Name>Serial Number</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Serial Number]]></Description>
</Item>
<Item ID="3">
<Name>Firmware Version</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Current firmware version of the Device.The Firmware Management function could rely on this resource.]]></Description>
</Item>
<Item ID="4">
<Name>Reboot</Name>
<Operations>E</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type></Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Reboot the LwM2M Device to restore the Device from unexpected firmware failure.]]></Description>
</Item>
<Item ID="5">
<Name>Factory Reset</Name>
<Operations>E</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type></Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Perform factory reset of the LwM2M Device to make the LwM2M Device to go through initial deployment sequence where provisioning and bootstrap sequence is performed. This requires client ensuring post factory reset to have minimal information to allow it to carry out one of the bootstrap methods specified in section 5.2.3.
When this Resource is executed, "De-register" operation MAY be sent to the LwM2M Server(s) before factory reset of the LwM2M Device.]]></Description>
</Item>
<Item ID="6">
<Name>Available Power Sources</Name>
<Operations>R</Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..7</RangeEnumeration>
<Units></Units>
<Description><![CDATA[0: DC power
1: Internal Battery
2: External Battery
3: Fuel Cell
4: Power over Ethernet
5: USB
6: AC (Mains) power
7: Solar
The same Resource Instance ID MUST be used to associate a given Power Source (Resource ID:6) with its Present Voltage (Resource ID:7) and its Present Current (Resource ID:8)]]></Description>
</Item>
<Item ID="7">
<Name>Power Source Voltage</Name>
<Operations>R</Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Present voltage for each Available Power Sources Resource Instance. The unit used for this resource is in mV.]]></Description>
</Item>
<Item ID="8">
<Name>Power Source Current</Name>
<Operations>R</Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Present current for each Available Power Source. The unit used for this resource is in mA.]]></Description>
</Item>
<Item ID="9">
<Name>Battery Level</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..100</RangeEnumeration>
<Units>/100</Units>
<Description><![CDATA[Contains the current battery level as a percentage (with a range from 0 to 100). This value is only valid for the Device internal Battery if present (one Available Power Sources Resource Instance is 1).]]></Description>
</Item>
<Item ID="10">
<Name>Memory Free</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Estimated current available amount of storage space which can store data and software in the LwM2M Device (expressed in kilobytes). Note: 1 kilobyte corresponds to 1000 bytes.]]></Description>
</Item>
<Item ID="11">
<Name>Error Code</Name>
<Operations>R</Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..32</RangeEnumeration>
<Units></Units>
<Description><![CDATA[0=No error
1=Low battery power
2=External power supply off
3=GPS module failure
4=Low received signal strength
5=Out of memory
6=SMS failure
7=IP connectivity failure
8=Peripheral malfunction
9..15=Reserved for future use
16..32=Device specific error codes
When the single Device Object Instance is initiated, there is only one error code Resource Instance whose value is equal to 0 that means no error. When the first error happens, the LwM2M Client changes error code Resource Instance to any non-zero value to indicate the error type. When any other error happens, a new error code Resource Instance is created. When an error associated with a Resource Instance is no longer present, that Resource Instance is deleted. When the single existing error is no longer present, the LwM2M Client returns to the original no error state where Instance 0 has value 0.
This error code Resource MAY be observed by the LwM2M Server. How to deal with LwM2M Clients error report depends on the policy of the LwM2M Server. Error codes in between 16 and 32 are specific to the Device and may have different meanings among implementations.]]></Description>
</Item>
<Item ID="12">
<Name>Reset Error Code</Name>
<Operations>E</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type></Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Delete all error code Resource Instances and create only one zero-value error code that implies no error, then re-evaluate all error conditions and update and create Resources Instances to capture all current error conditions.]]></Description>
</Item>
<Item ID="13">
<Name>Current Time</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Time</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Current UNIX time of the LwM2M Client.
The LwM2M Client should be responsible to increase this time value as every second elapses.
The LwM2M Server is able to write this Resource to make the LwM2M Client synchronized with the LwM2M Server.]]></Description>
</Item>
<Item ID="14">
<Name>UTC Offset</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Indicates the UTC offset currently in effect for this LwM2M Device. UTC+X [ISO 8601].]]></Description>
</Item>
<Item ID="15">
<Name>Timezone</Name>
<Operations>RW</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Indicates in which time zone the LwM2M Device is located, in IANA Timezone (TZ) database format.]]></Description>
</Item>
<Item ID="16">
<Name>Supported Binding and Modes</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Mandatory</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Indicates which bindings and modes are supported in the LwM2M Client. The possible values are those listed in the LwM2M Core Specification.]]></Description>
</Item>
<Item ID="17"><Name>Device Type</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Type of the device (manufacturer specified string: e.g. smart meters / dev Class / ...)]]></Description>
</Item>
<Item ID="18"><Name>Hardware Version</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Current hardware version of the device]]></Description>
</Item>
<Item ID="19"><Name>Software Version</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>String</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Current software version of the device (manufacturer specified string). On elaborated LwM2M device, SW could be split in 2 parts: a firmware one and a higher level software on top.
Both pieces of Software are together managed by LwM2M Firmware Update Object (Object ID 5)]]></Description>
</Item>
<Item ID="20"><Name>Battery Status</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration>0..6</RangeEnumeration>
<Units></Units>
<Description><![CDATA[This value is only valid for the Device Internal Battery if present (one Available Power Sources Resource Instance value is 1).
Battery
Status Meaning Description
0 Normal The battery is operating normally and not on power.
1 Charging The battery is currently charging.
2 Charge Complete The battery is fully charged and still on power.
3 Damaged The battery has some problem.
4 Low Battery The battery is low on charge.
5 Not Installed The battery is not installed.
6 Unknown The battery information is not available.]]></Description>
</Item>
<Item ID="21"><Name>Memory Total</Name>
<Operations>R</Operations>
<MultipleInstances>Single</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Integer</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Total amount of storage space which can store data and software in the LwM2M Device (expressed in kilobytes). Note: 1 kilobyte corresponds to 1000 bytes.]]></Description>
</Item>
<Item ID="22"><Name>ExtDevInfo</Name>
<Operations>R</Operations>
<MultipleInstances>Multiple</MultipleInstances>
<Mandatory>Optional</Mandatory>
<Type>Objlnk</Type>
<RangeEnumeration></RangeEnumeration>
<Units></Units>
<Description><![CDATA[Reference to external "Device" object instance containing information. For example, such an external device can be a Host Device, which is a device into which the Device containing the LwM2M client is embedded. This Resource may be used to retrieve information about the Host Device.]]></Description>
</Item></Resources>
<Description2></Description2>
</Object>
</LWM2M>

View File

@ -0,0 +1,78 @@
#
# Copyright © 2016-2022 The Thingsboard Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
monitoring:
auth:
base_url: '${AUTH_BASE_URL:http://localhost:8080}'
username: '${AUTH_USERNAME:tenant@thingsboard.org}'
password: '${AUTH_PASSWORD:tenant}'
ws:
base_url: '${WS_BASE_URL:ws://localhost:8080}'
check_timeout_ms: '${WS_CHECK_TIMEOUT_MS:3000}'
request_timeout_ms: '${WS_REQUEST_TIMEOUT_MS:5000}'
failure_threshold: '${MONITORING_FAILURE_THRESHOLD:1}'
transports:
mqtt:
enabled: '${MQTT_TRANSPORT_MONITORING_ENABLED:true}'
monitoring_rate_ms: '${MQTT_TRANSPORT_MONITORING_RATE_MS:10000}'
request_timeout_ms: '${MQTT_REQUEST_TIMEOUT_MS:4000}'
initial_delay_ms: '${MQTT_TRANSPORT_MONITORING_INITIAL_DELAY_MS:0}'
qos: '${MQTT_QOS_LEVEL:1}'
targets:
- base_url: "tcp://localhost"
device:
id:
access_token:
coap:
enabled: '${COAP_TRANSPORT_MONITORING_ENABLED:false}'
monitoring_rate_ms: '${COAP_TRANSPORT_MONITORING_RATE_MS:10000}'
request_timeout_ms: '${COAP_REQUEST_TIMEOUT_MS:4000}'
initial_delay_ms: '${COAP_TRANSPORT_MONITORING_INITIAL_DELAY_MS:0}'
targets:
- base_url:
device:
id:
access_token:
lwm2m:
enabled: '${LWM2M_TRANSPORT_MONITORING_ENABLED:false}'
monitoring_rate_ms: '${LWM2M_TRANSPORT_MONITORING_RATE_MS:10000}'
request_timeout_ms: '${LWM2M_REQUEST_TIMEOUT_MS:4000}'
initial_delay_ms: '${LWM2M_TRANSPORT_MONITORING_INITIAL_DELAY_MS:0}'
targets:
- base_url:
device:
id:
access_token:
http:
enabled: '${HTTP_TRANSPORT_MONITORING_ENABLED:false}'
monitoring_rate_ms: '${HTTP_TRANSPORT_MONITORING_RATE_MS:10000}'
request_timeout_ms: '${HTTP_REQUEST_TIMEOUT_MS:4000}'
initial_delay_ms: '${HTTP_TRANSPORT_MONITORING_INITIAL_DELAY_MS:0}'
targets:
- base_url:
device:
id:
access_token:
notification_channels:
slack:
enabled: '${SLACK_NOTIFICATION_CHANNEL_ENABLED:false}'
webhook_url: '${SLACK_WEBHOOK_URL:}'

View File

@ -0,0 +1,28 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.monitoring;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class MonitoringServiceApplicationTests {
@Test
void contextLoads() {
}
}

View File

@ -153,6 +153,7 @@
<module>application</module>
<module>msa</module>
<module>rest-client</module>
<module>monitoring</module>
</modules>
<profiles>