|
@@ -5,53 +5,54 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.ws.fastapi.entity.Pact;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
-import com.ws.fastapi.entity.Pact;
|
|
|
-
|
|
|
|
|
|
public class ConfUtil {
|
|
|
-
|
|
|
- public static String getPath() {
|
|
|
- String path = System.getProperty("user.dir").replace("\\", "/");
|
|
|
- path = path.substring(0, path.lastIndexOf("/"));
|
|
|
- return path + "/workspace/bin";
|
|
|
- }
|
|
|
+
|
|
|
+ public static String getPath() {
|
|
|
+ String path = System.getProperty("user.dir").replace("\\", "/");
|
|
|
+ path = path.substring(0, path.lastIndexOf("/"));
|
|
|
+ return path + "/workspace/bin";
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 创建opcda配置文件
|
|
|
+ *
|
|
|
* @param obj
|
|
|
* @return
|
|
|
*/
|
|
|
public static String createOpcDaConf(JSONObject obj) {
|
|
|
StringBuilder buffer;
|
|
|
FileWriter writer;
|
|
|
- buffer = new StringBuilder();
|
|
|
- buffer.append("[[inputs.opcda]]\n")
|
|
|
- .append("name = \"").append(obj.getStr("name")).append("\"\n")
|
|
|
- .append("server = \"").append(obj.getStr("server")).append("\"\n")
|
|
|
- .append("nodes = [\"").append(obj.getStr("ip")).append("\"]\n")
|
|
|
- .append("items = [\n");
|
|
|
- JSONArray items = obj.getJSONArray("items");
|
|
|
- for (int j = 0; j < items.size(); j++) {
|
|
|
- buffer.append("{ item = \"").append(items.getStr(j)).append("\"");
|
|
|
- buffer.append(", tags = [[\"DataSource\", \"").append(obj.getStr("datasource")).append("\"]]");
|
|
|
- buffer.append("},\n");
|
|
|
- }
|
|
|
- buffer.append("]\n");
|
|
|
- String url = getPath() + "/opcDa/da_" + obj.getStr("id") + "_" + obj.getStr("interval") + ".conf";
|
|
|
- writer = new FileWriter(url);
|
|
|
- writer.write(buffer.toString());
|
|
|
+ buffer = new StringBuilder();
|
|
|
+ buffer.append("[[inputs.opcda]]\n")
|
|
|
+ .append("name = \"").append(obj.getStr("name")).append("\"\n")
|
|
|
+ .append("server = \"").append(obj.getStr("server")).append("\"\n")
|
|
|
+ .append("nodes = [\"").append(obj.getStr("ip")).append("\"]\n")
|
|
|
+ .append("items = [\n");
|
|
|
+ JSONArray items = obj.getJSONArray("items");
|
|
|
+ for (int j = 0; j < items.size(); j++) {
|
|
|
+ buffer.append("{ item = \"").append(items.getStr(j)).append("\"");
|
|
|
+ buffer.append(", tags = [[\"DataSource\", \"").append(obj.getStr("datasource")).append("\"]]");
|
|
|
+ buffer.append("},\n");
|
|
|
+ }
|
|
|
+ buffer.append("]\n");
|
|
|
+ String url = getPath() + "/opcDa/da_" + obj.getStr("id") + "_" + obj.getStr("interval") + ".conf";
|
|
|
+ writer = new FileWriter(url);
|
|
|
+ writer.write(buffer.toString());
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建telegraf配置文件
|
|
|
+ *
|
|
|
* @param obj
|
|
|
*/
|
|
|
public static void createTelegrafConf(JSONObject obj) {
|
|
|
- String path = ConfUtil.getPath();
|
|
|
+ String path = ConfUtil.getPath();
|
|
|
JSONObject agent = obj.getJSONObject("agent");
|
|
|
StringBuilder buffer = new StringBuilder();
|
|
|
// 默认数据收集间隔
|
|
@@ -102,7 +103,7 @@ public class ConfUtil {
|
|
|
} else if (Pact.OPC_UA.getValue().equals(item.getStr("type"))) {
|
|
|
buffer.append(createOpcUa(item));
|
|
|
} else if (Pact.OPC_UA_fast.getValue().equals(item.getStr("type"))) {
|
|
|
- buffer.append(createOpcUaFast(item));
|
|
|
+ buffer.append(createOpcUaFast(item));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -112,7 +113,7 @@ public class ConfUtil {
|
|
|
.append("token = \"").append(output.getStr("token")).append("\"\n")
|
|
|
.append("organization = \"").append(output.getStr("organization")).append("\"\n")
|
|
|
.append("bucket = \"").append(output.getStr("bucket")).append("\"\n");
|
|
|
- FileWriter writer = new FileWriter(getPath() + "/telegraf_"+ agent.getStr("interval") +".conf");
|
|
|
+ FileWriter writer = new FileWriter(getPath() + "/telegraf_" + agent.getStr("interval") + ".conf");
|
|
|
writer.write(buffer.toString());
|
|
|
}
|
|
|
|
|
@@ -125,10 +126,10 @@ public class ConfUtil {
|
|
|
.append("request_timeout=\"5s\"\n")
|
|
|
.append("security_policy=\"auto\"\n")
|
|
|
.append("security_mode=\"auto\"\n");
|
|
|
- Integer isAnonymous = item.getInt("isAnonymous");
|
|
|
- if (isAnonymous == 1) {
|
|
|
+ Integer identityProvider = item.getInt("identityProvider");
|
|
|
+ if (identityProvider == 0) {
|
|
|
builder.append("auth_method=\"Anonymous\"\n");
|
|
|
- } else {
|
|
|
+ } else if (identityProvider == 1) {
|
|
|
builder.append("auth_method=\"UserName\"\n")
|
|
|
.append("username=\"").append(item.getStr("userName")).append("\"\n")
|
|
|
.append("password=\"").append(item.getStr("password")).append("\"\n");
|
|
@@ -157,7 +158,7 @@ public class ConfUtil {
|
|
|
builder.append("]\n");
|
|
|
return builder.toString();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private static String createOpcUaFast(JSONObject item) {
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
builder.append("[[inputs.opcua_listener]]\n")
|
|
@@ -168,10 +169,10 @@ public class ConfUtil {
|
|
|
.append("request_timeout=\"5s\"\n")
|
|
|
.append("security_policy=\"auto\"\n")
|
|
|
.append("security_mode=\"auto\"\n");
|
|
|
- Integer isAnonymous = item.getInt("isAnonymous");
|
|
|
- if (isAnonymous == 1) {
|
|
|
+ Integer identityProvider = item.getInt("identityProvider");
|
|
|
+ if (identityProvider == 0) {
|
|
|
builder.append("auth_method=\"Anonymous\"\n");
|
|
|
- } else {
|
|
|
+ } else if (identityProvider == 1) {
|
|
|
builder.append("auth_method=\"UserName\"\n")
|
|
|
.append("username=\"").append(item.getStr("userName")).append("\"\n")
|
|
|
.append("password=\"").append(item.getStr("password")).append("\"\n");
|