Search in sources :

Example 1 with AlarmConfig

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;
    }
}
Also used : Channel(io.grpc.Channel) AlarmConfig(com.actiontech.dble.config.model.AlarmConfig)

Example 2 with AlarmConfig

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());
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) AlarmConfig(com.actiontech.dble.config.model.AlarmConfig)

Example 3 with AlarmConfig

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);
            }
        }
    }
}
Also used : Channel(io.grpc.Channel) UcoreInterface(com.actiontech.dble.log.alarm.UcoreInterface) AlarmConfig(com.actiontech.dble.config.model.AlarmConfig)

Aggregations

AlarmConfig (com.actiontech.dble.config.model.AlarmConfig)3 Channel (io.grpc.Channel)2 UcoreInterface (com.actiontech.dble.log.alarm.UcoreInterface)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1