見出し画像

ThingsboardのDeviceProfileによるAlarm発行にテレメトリの情報を載せる

何がしたいか

ThingsBoardにはDeviceProfileという機能があります。
この機能を使うと、DeviceProfileを設定したDeviceを一定のルール(例えば指定したテレメトリ値が特定の値を超えたなど)でアラームを発行することができます。

このアラームを契機にRuleChainを使ってメールを送信したり、Slackに通知したりすることができるのですが、アラーム情報の中にテレメトリ値が入ってこないことが問題でした。
これを解決する方法を見つけましたので、メモ代わりに書いておきます。

DeviceProfileの設定

まず、DeviceProfileのAlarm rulesに新しいruleを追加します。
次にAdd detailsを選択します。

Alarm Rule設定

Detailsの設定に ${テレメトリキー名} を設定します

Detailsの設定

Add detailsにテレメトリキーを設定すると、アラーム情報の中にテレメトリ値が付与されて送られてきます。
具体的には以下のような内容のmsgがRuleChainに送られてきます。

{
	"tenantId": {
		"entityType": "TENANT",
		"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
	},
	"customerId": {
		"entityType": "CUSTOMER",
		"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
	},
	"type": "Alarm Rule名",
	"originator": {
		"entityType": "DEVICE",
		"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
	},
	"severity": "WARNING",
	"status": "ACTIVE_UNACK",
	"startTs": 1707179091566,
	"endTs": 1707179091566,
	"ackTs": 0,
	"clearTs": 0,
	"details": {
		"data": "テレメトリ値"
	},
	"propagate": false,
	"propagateToOwner": false,
	"propagateToOwnerHierarchy": false,
	"propagateToTenant": false,
	"propagateRelationTypes": [],
	"id": {
		"entityType": "ALARM",
		"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
	},
	"createdTime": 1707179133543,
	"name": "Alarm Rule名"
}

この中の

  "details": {
		"data": "テレメトリ値"
	},

の部分がテレメトリ値です。
あとはこの値をメールに記載するなり、処理に使用するなりご自由に。

この記事が気に入ったらサポートをしてみませんか?