大屏监控 Metabase 集成到 Java 项目
Posted 爪哇笔记
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了大屏监控 Metabase 集成到 Java 项目相关的知识,希望对你有一定的参考价值。
前言
分享
集成
// you will need to install via 'npm install jsonwebtoken' or in your package.json
var jwt = require("jsonwebtoken");
var METABASE_SITE_URL = "http://127.0.0.1:3000";
var METABASE_SECRET_KEY = "76e7feb6e9456f9f924a9f463d03cbcaedf72b4a68844fa88e5f05c6345d409d";
var payload = {
resource: { dashboard: 2 },
params: {},
exp: Math.round(Date.now() / 1000) + (10 * 60) // 10 minute expiration
};
var token = jwt.sign(payload, METABASE_SECRET_KEY);
var iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true&titled=true";
import com.alibaba.fastjson.JSONObject;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Base64;
import java.util.Date;
import java.util.Map;
/**
* 报表生成加密URL
*/
public class JWTUtils {
/**
* 创建token
*/
public static String createJWT(Map<String, Object> payload, String secretKey){
try {
String metaBaseEncodedSecretKey = Base64.getEncoder().encodeToString(secretKey.getBytes());
return Jwts.builder()
.setHeaderParam("typ", "JWT")
.setClaims(payload)
.signWith(SignatureAlgorithm.HS256, metaBaseEncodedSecretKey)
.setIssuedAt(new Date())
.compact();
}catch (Exception e){
e.printStackTrace();
}
return null;
}
/**
* 创建token
*/
public static String getTokenUrl(Integer dashboard,String secretKey){
int round = Math.round(System.currentTimeMillis() / 1000)+10*60; // 10 minute expiration
JSONObject resource = new JSONObject();
resource.put("dashboard",dashboard);
JSONObject payload = new JSONObject();
payload.put("resource",resource);
payload.put("params",new JSONObject());
payload.put("exp",round);
String token = JWTUtils.createJWT(payload,secretKey);
return BI_SITE_URL + "/embed/dashboard/" + token + "#theme=night&bordered=false&titled=false";
}
private static final String BI_SITE_URL = "http://127.0.0.1:3000";
public static void main(String[] args) {
String secretKey = "******";
String url = getTokenUrl(2,secretKey);
System.out.println(url);
}
}
预览
小结
以上是关于大屏监控 Metabase 集成到 Java 项目的主要内容,如果未能解决你的问题,请参考以下文章