Parcourir la source

处理阿里云eip找不到公网的bug

dodo hold il y a 1 an
Parent
commit
1c769a2492

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
molilian.api/Properties/PublishProfiles/latest.pubxml.user


+ 56 - 9
molilian.core/Core/aliyun/AliyunCore.cs

@@ -13,6 +13,8 @@ using static AlibabaCloud.SDK.Vpc20160428.Models.DescribeEipAddressesResponseBod
 using AlibabaCloud.SDK.ImageSearch20210501.Models;
 using static AlibabaCloud.SDK.Ecs20140526.Models.DescribeNetworkInterfacesResponseBody.DescribeNetworkInterfacesResponseBodyNetworkInterfaceSets;
 using TencentCloud.Cam.V20190116.Models;
+using static AlibabaCloud.SDK.Vpc20160428.Models.DescribeNetworkAclAttributesResponseBody;
+using static AlibabaCloud.SDK.Ecs20140526.Models.DescribeNetworkInterfaceAttributeResponseBody;
 
 namespace molilian.core
 {
@@ -184,14 +186,42 @@ namespace molilian.core
                         var privateIps = networkInterface?.PrivateIpSets;
 
                         var taraget = privateIps?.PrivateIpSet.Where(e => e.PrivateIpAddress.Equals(privateIp)).FirstOrDefault();
-                        if (taraget == null) break;
+                        if (taraget == null) continue;
 
                         //找到当前公网IP
                         string currentPublicIp = taraget?.AssociatedPublicIp?.PublicIpAddress;
-                        if (string.IsNullOrEmpty(currentPublicIp)) throw new Exception("没有找到公网IP");
+                        DescribeEipAddressesResponseBodyEipAddressesEipAddress currentEip;
+                        if (string.IsNullOrEmpty(currentPublicIp))
+                        {
+                            var currentEips = DescribeEipsAddresse(region, string.Empty);
+                            currentEip = currentEips?.Where(e => privateIp.Equals(e.PrivateIpAddress))?.FirstOrDefault();
+                            currentPublicIp = currentEip?.IpAddress;
+
+                            if (string.IsNullOrEmpty(currentPublicIp))
+                            {
+                                var emptyPrivateEips = currentEips?.Where(e => string.IsNullOrEmpty(e.PrivateIpAddress));
+                                foreach (var emptyEip in emptyPrivateEips)
+                                {
+                                    var body = DescribeNetworkInterfaceAttribute(region, emptyEip.InstanceId);
+                                    if (body != null)
+                                    {
+                                        if (body.PrivateIpAddress == privateIp)
+                                        {
+                                            currentEip = emptyEip;
+                                            currentPublicIp = emptyEip?.IpAddress;
+                                            break;
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            currentEip = DescribeEipAddresse(region, currentPublicIp) ?? throw new Exception("没有找到 EIP");
+                        }
+                        if (currentEip == null) throw new Exception("没有找到 EIP");
 
                         //第1步、获取当前的公网EIP
-                        var currentEip = DescribeEipAddresse(region, currentPublicIp) ?? throw new Exception("没有找到 EIP");
                         var currentAllocationId = currentEip.AllocationId;
 
                         //第2步、申请新的公网ip
@@ -368,13 +398,14 @@ namespace molilian.core
             }
         }
 
-        public List<DescribeEipAddressesResponseBodyEipAddressesEipAddress> DescribeEipAddresses(string region, string eipAddress)
+
+        public DescribeEipAddressesResponseBodyEipAddressesEipAddress DescribeEipAddresse(string region, string eipAddress)
         {
             try
             {
                 var response = plus.DescribeEipAddresses(region, eipAddress);
-                var list = response?.Body?.EipAddresses?.EipAddress;
-                return list;
+                var eip = response?.Body?.EipAddresses?.EipAddress?.FirstOrDefault();
+                return eip;
             }
             catch (Exception ex)
             {
@@ -382,13 +413,28 @@ namespace molilian.core
             }
         }
 
-        public DescribeEipAddressesResponseBodyEipAddressesEipAddress DescribeEipAddresse(string region, string eipAddress)
+
+        public List<DescribeEipAddressesResponseBodyEipAddressesEipAddress> DescribeEipsAddresse(string region, string eipAddress)
         {
             try
             {
                 var response = plus.DescribeEipAddresses(region, eipAddress);
-                var eip = response?.Body?.EipAddresses?.EipAddress?.FirstOrDefault();
-                return eip;
+                var eips = response?.Body?.EipAddresses?.EipAddress;
+                return eips;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+        }
+
+        public DescribeNetworkInterfaceAttributeResponseBody DescribeNetworkInterfaceAttribute(string region, string networkInterfaceId)
+        {
+            try
+            {
+                var response = plus.DescribeNetworkInterfaceAttribute(region, networkInterfaceId);
+                var body = response?.Body;
+                return body;
             }
             catch (Exception ex)
             {
@@ -396,6 +442,7 @@ namespace molilian.core
             }
         }
 
+
         public bool ReleaseEipAddress(string region, string allocationId)
         {
             try

+ 24 - 1
molilian.core/Core/aliyun/AliyunPoolCore.cs

@@ -150,13 +150,36 @@ namespace molilian.core
                             var privateIps = networkInterface?.PrivateIpSets;
                             foreach (var taraget in privateIps.PrivateIpSet)
                             {
+                                string privateIp = taraget.PrivateIpAddress;
                                 //找到当前公网IP
                                 string currentPublicIp = taraget?.AssociatedPublicIp?.PublicIpAddress;
+                                if (string.IsNullOrEmpty(currentPublicIp))
+                                {
+                                    var currentEips = core.DescribeEipsAddresse(region, string.Empty);
+                                    var currentEip = currentEips?.Where(e => privateIp.Equals(e.PrivateIpAddress))?.FirstOrDefault();
+                                    currentPublicIp = currentEip?.IpAddress;
 
+                                    if (string.IsNullOrEmpty(currentPublicIp))
+                                    {
+                                        var emptyPrivateEips = currentEips?.Where(e => string.IsNullOrEmpty(e.PrivateIpAddress));
+                                        foreach (var emptyEip in emptyPrivateEips)
+                                        {
+                                            var body = core.DescribeNetworkInterfaceAttribute(region, emptyEip.InstanceId);
+                                            if (body != null)
+                                            {
+                                                if (body.PrivateIpAddress == privateIp)
+                                                {
+                                                    currentPublicIp = emptyEip?.IpAddress;
+                                                    break;
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
                                 data.AddressIps.Add(new AddressIpDTO
                                 {
                                     networkInterfaceId = networkInterfaceId,
-                                    privateIp = taraget.PrivateIpAddress,
+                                    privateIp = privateIp,
                                     publicIp = currentPublicIp,
                                 });
                             }

+ 51 - 8
molilian.core/Core/log/jd.cs

@@ -2,6 +2,8 @@
 using CSRedis;
 using System.Data;
 using YunhuiKit;
+using static dodohold.core.ZTOExpress.CreateOrderArgs;
+using System.Xml.Linq;
 
 namespace molilian.core
 {
@@ -142,19 +144,21 @@ namespace molilian.core
                     //saveClientRequestTotal(response.channel, response.ip, response.oaid);
                 }
 
-                if (!response.success && ("nologin".Equals(response.reason) ||
-                    "方法不存在".Equals(response.reason) ||
-                    "未登录".Equals(response.reason)))
-                {
-                    await JdPoolCore.DisabledAsync(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
-                }
+                //if (!response.success && ("nologin".Equals(response.reason) ||
+                //    "方法不存在".Equals(response.reason) ||
+                //    "未登录".Equals(response.reason)))
+                //{
+                //    await JdPoolCore.DisabledAsync(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
+                //}
+
                 if ("没有匹配账号".Equals(response.reason))
                 {
                     await JdPoolCore.AccountExhaustedAsync();
                 }
 
-                string failure_key = ":total:continuous_failure";
-                string failure_lock_key = ":lock:continuous_failure";
+                string failure_key = $":total:continuous_failure:{response.accountId}";
+                string failure_lock_key = $":lock:continuous_failure:{response.accountId}";
+
                 if (response.success) await RedisKit.DelAsync(failure_key);
 
                 //连续错误发送报警
@@ -183,9 +187,48 @@ namespace molilian.core
                             NotifyCore.AnPushNotify(response.reason, message);
                         }
                     }
+                }
+
+                string nologin_key = $":total:continuous_nologin:{response.accountId}";
+                string nologin_lock_key = $":lock:continuous_nologin:{response.accountId}";
+
+                //连续错误发送报警
+                if (!response.success && ("nologin".Equals(response.reason) ||
+                    "方法不存在".Equals(response.reason) ||
+                    "未登录".Equals(response.reason)))
+                {
+                    var total = await RedisKit.IncrByAsync(nologin_key);
+                    await RedisKit.ExpireAsync(nologin_key, 3600);
 
+                    if (total > 3)
+                    {
+                        //没有锁定记录才发送,
+                        string lockfFlag = await RedisKit.GetAsync<string>(nologin_lock_key);
+                        if (string.IsNullOrEmpty(lockfFlag))
+                        {
+                            await JdPoolCore.DisabledAsync(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
+                            await RedisKit.SetAsync(nologin_lock_key, 1, 60);
+                            await RedisKit.ExpireAsync(nologin_key, 86400);
+                        }
+                    }
+                    else
+                    {
+                        NotifyCore.Notify(new NifyMessage
+                        {
+                            message = $"【京东联盟{response.accountId}:{response.accountName}】cookie 掉线({total})\n\n{response.rawContent}",
+                            priority = NifyMessagePriority.high,
+                            tags = ["red_circle"]
+                        });
+                    }
+                }
+                else
+                {
+                    await RedisKit.DelAsync(nologin_key);
                 }
 
+
+
+
             }
             catch (Exception ex) { }
         }

+ 1 - 1
molilian.core/Plus/Alimama/orders.cs

@@ -454,10 +454,10 @@ SET  order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + ord
                             throw response.ResponseException;
                         }
                         body = response.Body();
-#if DEBUG
                         _ = new LoggerLibrary("debug", "GetTkOrders")
                             .Info(body)
                             .SaveAsync();
+#if DEBUG
 #endif
 
                         if (body.Contains("{\"action\":\"captcha\""))

+ 3 - 0
molilian.core/Plus/Aliyun/Ecs.cs

@@ -75,6 +75,7 @@ namespace molilian.core
 
             DescribeNetworkInterfacesRequest describeNetworkInterfacesRequest = new()
             {
+                MaxResults = 500,
                 RegionId = region,
                 InstanceId = instanceId,
             };
@@ -410,6 +411,7 @@ namespace molilian.core
 
             DescribeInstancesRequest describeInstancesRequest = new()
             {
+                MaxResults = 100,
                 RegionId = region,
             };
 
@@ -606,6 +608,7 @@ namespace molilian.core
             AlibabaCloud.SDK.Ecs20140526.Client client = new(config);
             DescribeNetworkInterfacesRequest describeNetworkInterfacesRequest = new()
             {
+                MaxResults = 500,
                 RegionId = region,
             };
             AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();

+ 6 - 2
molilian.core/Plus/Aliyun/Vpc.cs

@@ -1,11 +1,13 @@
-using AlibabaCloud.SDK.Vpc20160428.Models;
+using AlibabaCloud.SDK.Ecs20140526.Models;
+using AlibabaCloud.SDK.Vpc20160428.Models;
 using Tea;
+using TencentCloud.Vpc.V20170312.Models;
 
 namespace molilian.core
 {
     public partial class AliyunPlus
     {
-        public DescribeEipAddressesResponse DescribeEipAddresses(string region, string eipAddress)
+        public AlibabaCloud.SDK.Vpc20160428.Models.DescribeEipAddressesResponse DescribeEipAddresses(string region, string eipAddress)
         {
             AlibabaCloud.OpenApiClient.Models.Config config = new()
             {
@@ -16,6 +18,7 @@ namespace molilian.core
             AlibabaCloud.SDK.Vpc20160428.Client client = new(config);
             AlibabaCloud.SDK.Vpc20160428.Models.DescribeEipAddressesRequest describeEipAddressesRequest = new AlibabaCloud.SDK.Vpc20160428.Models.DescribeEipAddressesRequest
             {
+                PageSize = 100,
                 RegionId = region,
                 EipAddress = eipAddress
             };
@@ -52,6 +55,7 @@ namespace molilian.core
             return null;
         }
 
+
         /// <summary>
         /// 申请弹性公网IP
         /// </summary>

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff