huyuanming
5 years ago
31 changed files with 747 additions and 266 deletions
@ -0,0 +1,57 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package cn.escheduler.alert.manager; |
||||||
|
|
||||||
|
import cn.escheduler.alert.utils.Constants; |
||||||
|
import cn.escheduler.alert.utils.EnterpriseWeChatUtils; |
||||||
|
import cn.escheduler.dao.model.Alert; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Enterprise WeChat Manager |
||||||
|
*/ |
||||||
|
public class EnterpriseWeChatManager { |
||||||
|
private static final Logger logger = LoggerFactory.getLogger(MsgManager.class); |
||||||
|
/** |
||||||
|
* Enterprise We Chat send |
||||||
|
* @param alert |
||||||
|
*/ |
||||||
|
public Map<String,Object> send(Alert alert, String token){ |
||||||
|
Map<String,Object> retMap = new HashMap<>(); |
||||||
|
retMap.put(Constants.STATUS, false); |
||||||
|
String agentId = EnterpriseWeChatUtils.enterpriseWeChatAgentId; |
||||||
|
String users = EnterpriseWeChatUtils.enterpriseWeChatUsers; |
||||||
|
List<String> userList = Arrays.asList(users.split(",")); |
||||||
|
logger.info("send message {}",alert); |
||||||
|
String msg = EnterpriseWeChatUtils.makeUserSendMsg(userList, agentId,EnterpriseWeChatUtils.markdownByAlert(alert)); |
||||||
|
try { |
||||||
|
EnterpriseWeChatUtils.sendEnterpriseWeChat(Constants.UTF_8, msg, token); |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
} |
||||||
|
retMap.put(Constants.STATUS, true); |
||||||
|
return retMap; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package cn.escheduler.common.utils; |
||||||
|
|
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* http utils |
||||||
|
*/ |
||||||
|
public class IpUtils { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(IpUtils.class); |
||||||
|
public static final String DOT = "."; |
||||||
|
|
||||||
|
/** |
||||||
|
* ip str to long <p> |
||||||
|
* |
||||||
|
* @param ipStr ip string |
||||||
|
*/ |
||||||
|
public static Long ipToLong(String ipStr) { |
||||||
|
String[] ipSet = ipStr.split("\\" + DOT); |
||||||
|
|
||||||
|
return Long.parseLong(ipSet[0]) << 24 | Long.parseLong(ipSet[1]) << 16 | Long.parseLong(ipSet[2]) << 8 | Long.parseLong(ipSet[3]); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* long to ip |
||||||
|
* @param ipLong the long number converted from IP |
||||||
|
* @return String |
||||||
|
*/ |
||||||
|
public static String longToIp(long ipLong) { |
||||||
|
long[] ipNumbers = new long[4]; |
||||||
|
long tmp = 0xFF; |
||||||
|
ipNumbers[0] = ipLong >> 24 & tmp; |
||||||
|
ipNumbers[1] = ipLong >> 16 & tmp; |
||||||
|
ipNumbers[2] = ipLong >> 8 & tmp; |
||||||
|
ipNumbers[3] = ipLong & tmp; |
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder(16); |
||||||
|
sb.append(ipNumbers[0]).append(DOT) |
||||||
|
.append(ipNumbers[1]).append(DOT) |
||||||
|
.append(ipNumbers[2]).append(DOT) |
||||||
|
.append(ipNumbers[3]); |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args){ |
||||||
|
long ipLong = ipToLong("11.3.4.5"); |
||||||
|
logger.info(longToIp(ipLong)); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue