use of com.actiontech.dble.config.model.AlarmConfig in project dble by actiontech.
the class AlarmAppender method refreshConfig.
/**
* refresh config of alarm address and re create the stub
*/
public static void refreshConfig() {
try {
AlarmConfig config = DbleServer.getInstance().getConfig().getAlarm();
if (config != null) {
// put the old config into _old
grpcUrlOld = grpcUrl;
serverIdOld = serverId;
alertComponentIdOld = alertComponentId;
portOld = port;
grpcUrlOld = grpcUrl;
grpcLevelOld = grpcLevel;
grpcLevel = "error".equalsIgnoreCase(config.getLevel()) ? 200 : 300;
serverId = config.getServerId();
port = Integer.parseInt(config.getPort());
grpcUrl = config.getUrl();
alertComponentId = config.getComponentId();
if (port != portOld || !grpcUrlOld.equals(grpcUrl)) {
Channel channel = ManagedChannelBuilder.forAddress(grpcUrl, port).usePlaintext(true).build();
stub = UcoreGrpc.newBlockingStub(channel);
}
} else {
stub = null;
}
} catch (Exception e) {
// config not ready yeat
return;
}
}
use of com.actiontech.dble.config.model.AlarmConfig in project dble by actiontech.
the class AlarmConfigLoader method load.
@Override
public void load(Element root, XMLServerLoader xsl, boolean isLowerCaseTableNames) throws IllegalAccessException, InvocationTargetException {
AlarmConfig alarmConfig = xsl.getAlarm();
NodeList list = root.getElementsByTagName("alarm");
if (list != null && list.getLength() > 0) {
Node node = list.item(0);
if (node instanceof Element) {
Element e = (Element) node;
alarmConfig.setUrl(ConfigUtil.loadElement(e, "url").getTextContent());
alarmConfig.setPort(ConfigUtil.loadElement(e, "port").getTextContent());
alarmConfig.setLevel(ConfigUtil.loadElement(e, "level").getTextContent());
alarmConfig.setServerId(ConfigUtil.loadElement(e, "serverId").getTextContent());
alarmConfig.setComponentId(ConfigUtil.loadElement(e, "componentId").getTextContent());
alarmConfig.setComponentType(ConfigUtil.loadElement(e, "componentType").getTextContent());
}
}
}
use of com.actiontech.dble.config.model.AlarmConfig in project dble by actiontech.
the class AlarmAppender method append.
@Override
public void append(LogEvent event) {
if (stub == null && DbleStartup.isInitZKend()) {
// only if the dbleserver init config file finished than the config can be use for alert
try {
AlarmConfig config = DbleServer.getInstance().getConfig().getAlarm();
if (config != null && config.getUrl() != null) {
grpcLevel = "error".equalsIgnoreCase(config.getLevel()) ? 200 : 300;
serverId = config.getServerId();
port = Integer.parseInt(config.getPort());
grpcUrl = config.getUrl();
alertComponentId = config.getComponentId();
ushardCode = config.getComponentType();
Channel channel = ManagedChannelBuilder.forAddress(grpcUrl, port).usePlaintext(true).build();
stub = UcoreGrpc.newBlockingStub(channel);
}
} catch (Exception e) {
// config not ready yeat
return;
}
}
if (stub != null) {
if (grpcLevel >= event.getLevel().intLevel()) {
String data = new String(getLayout().toByteArray(event));
String[] d = data.split("::");
if (d.length >= 2) {
String level = event.getLevel().intLevel() == 300 ? "WARN" : "CRITICAL";
UcoreInterface.AlertInput inpurt = UcoreInterface.AlertInput.newBuilder().setCode(d[0]).setDesc(d[1]).setLevel(level).setSourceComponentType(ushardCode).setSourceComponentId(alertComponentId).setAlertComponentId(alertComponentId).setAlertComponentType(ushardCode).setServerId(serverId).setTimestampUnix(System.currentTimeMillis() * 1000000).build();
stub.alert(inpurt);
}
}
}
}
Aggregations