产品定价 立即试用
社区版
generate dashboard report
入门 文档 指南 安装 架构 API 常见问题

generate dashboard report

根据指定配置截取仪表板并生成截图。仪表板由运行无头浏览器的独立reports server截取。生成的报表保存为blob实体,其ID添加到消息元数据的 attachments 键下。报表生成成功则消息路由到 Success,生成出错则路由到 Failure

使用方法

生成仪表板报表的典型流程如下:

  1. 消息到达“generate dashboard report”节点,消息数据中可包含完整报表配置,或节点使用其预配置的报表设置。

  2. 节点请求reports server(系统默认或自定义端点)生成仪表板报表。reports server在无头浏览器中打开仪表板并截取截图。

  3. 生成的报表以blob实体形式保存到ThingsBoard,其ID追加到消息的 attachments 元数据字段。

  4. 若报表成功生成并保存,消息经 Success 连接路由;若生成过程中出错,经 Failure 连接路由。

文档信息图标

需要Reports server: 使用此节点前,请确保reports server已正确配置且可访问。系统默认reports server URL由 REPORTS_SERVER_ENDPOINT_URL 环境变量控制(默认:http://localhost:8383)。

配置

配置指定报表如何生成以及使用哪个reports server。

  • Use system reports server - 启用时使用ThingsBoard中配置的默认reports server。禁用时需提供自定义reports server端点URL。
  • Reports server endpoint URL - 要使用的自定义reports server URL(仅在 Use system reports server 禁用时适用)。
  • Use report config from message - 启用时从传入消息的 reportConfig 字段读取报表配置。禁用时使用本节点中指定的报表配置。
  • Report configuration - 要使用的仪表板报表配置(仅在 Use report config from message 禁用时适用)。包含仪表板ID、时区、输出格式、timewindow等设置。

报表配置结构

提供报表配置(在节点或消息中)时,使用以下字段:

  • baseUrl(必填)- reports server可访问的ThingsBoard UI基础URL(如 “https://thingsboard.cloud”)
  • dashboardId(必填)- 要截取的仪表板UUID
  • state - 报表生成时打开的仪表板状态
  • timezone(必填)- 仪表板显示时区(如 “America/New_York”)
  • useDashboardTimewindow - 若为true,使用仪表板自身配置的timewindow
  • timewindow - 报表生成时使用的具体仪表板timewindow配置(JSON对象)
  • namePattern(必填)- 生成报表的文件名模式。支持在 %d{} 占位符内使用 Java SimpleDateFormat 语法进行日期格式化(如 “report-%d{yyyy-MM-dd_HH:mm:ss}”)
  • type - 报表文件格式:PDF、PNG或JPEG(默认:PDF)
  • useCurrentUserCredentials - 若为true,使用创建报表配置的用户的凭证
  • userId(必填)- 用于打开仪表板的用户凭证的UUID

JSON Schema

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "TbGenerateReportNodeConfiguration",
  "type": "object",
  "properties": {
    "useSystemReportsServer": {
      "type": "boolean",
      "description": "Whether to use the system-configured reports server.",
      "default": true
    },
    "reportsServerEndpointUrl": {
      "type": "string",
      "format": "uri",
      "description": "Custom reports server endpoint URL (used when 'useSystemReportsServer' is false)."
    },
    "useReportConfigFromMessage": {
      "type": "boolean",
      "description": "Whether to read report configuration from the incoming message.",
      "default": true
    },
    "reportConfig": {
      "type": "object",
      "description": "Dashboard report configuration (used when 'useReportConfigFromMessage' is false).",
      "properties": {
        "baseUrl": {
          "type": "string",
          "format": "uri",
          "description": "Base URL of ThingsBoard UI accessible by the reports server."
        },
        "dashboardId": {
          "type": "string",
          "format": "uuid",
          "description": "UUID of the dashboard to capture."
        },
        "state": {
          "type": "string",
          "description": "Dashboard state to apply during report generation."
        },
        "timezone": {
          "type": "string",
          "description": "Timezone for the dashboard presentation."
        },
        "useDashboardTimewindow": {
          "type": "boolean",
          "description": "Whether to use the dashboard's configured timewindow."
        },
        "timewindow": {
          "type": "object",
          "description": "Specific timewindow configuration for the dashboard."
        },
        "namePattern": {
          "type": "string",
          "description": "File name pattern for the generated report."
        },
        "type": {
          "type": "string",
          "enum": [
            "PDF",
            "PNG",
            "JPEG"
          ],
          "description": "Report file format."
        },
        "useCurrentUserCredentials": {
          "type": "boolean",
          "description": "Whether to use the current user's credentials."
        },
        "userId": {
          "type": "string",
          "format": "uuid",
          "description": "UUID of the user whose credentials will be used."
        }
      },
      "required": [
        "baseUrl",
        "dashboardId",
        "timezone",
        "namePattern",
        "userId"
      ]
    }
  },
  "additionalProperties": false
}

消息处理算法

  1. 节点确定报表配置来源:
    • 若启用 Use report config from message,从传入消息数据中提取 reportConfig
    • 否则使用节点设置中指定的报表配置
  2. 节点确定使用的reports server:
    • 若启用 Use system reports server,使用默认系统reports server
    • 否则使用自定义reports server端点URL
  3. 节点向reports server提交报表生成请求,server将:
    • 在无头浏览器中打开指定仪表板
    • 应用指定仪表板状态和timewindow
    • 以请求的格式截取截图
  4. 生成的报表数据保存为blob实体,包含:
    • 二进制报表数据
    • 基于报表格式的content type
    • 基于name pattern的报表名称
    • 与用户所属租户和客户的关联
  5. blob实体ID追加到消息元数据:
    • attachments 元数据字段已存在,blob ID以逗号分隔追加
    • 否则创建 attachments 字段并写入blob ID
  6. 更新后的消息经相应连接转发。

输出连接

  • Success
    • 报表已成功生成并保存。传出消息在 attachments 元数据字段中包含blob实体ID。
  • Failure
    • 报表生成过程中出错,例如:
      • 消息中的报表配置无效
      • Reports server不可用或不可达
      • 仪表板截图截取失败
      • blob实体保存失败
      • 用户未找到

示例

示例1 — 使用节点设置生成仪表板报表

传入消息

任意消息。

节点配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "useSystemReportsServer": true,
  "reportsServerEndpointUrl": null,
  "useReportConfigFromMessage": false,
  "reportConfig": {
    "baseUrl": "http://localhost:8080",
    "useDashboardTimewindow": true,
    "timewindow": {
      "selectedTab": 1,
      "history": {
        "historyType": 0,
        "interval": 1000,
        "timewindowMs": 86400000
      }
    },
    "type": "pdf",
    "timezone": "America/New_York",
    "dashboardId": "31815190-a35d-11f0-84cf-d3d34cbac472",
    "state": "",
    "namePattern": "report-%d{yyyy-MM-dd_HH:mm:ss}",
    "useCurrentUserCredentials": true,
    "userId": "f5e2b870-a2d7-11f0-b6e3-69416924d372"
  }
}

传出消息

与传入消息完全相同的消息,并将blob实体ID添加到 attachments 元数据字段:

1
2
3
{
  "attachments": "9f8e7d6c-5b4a-3c2b-1a0f-e9d8c7b6a5f4"
}

Success 连接路由。

结果

仪表板的PDF报表已生成,保存为blob实体,其ID已添加到消息元数据。