private Task SyncHistoryAlarm()
 {
     return(Task.Run(async() =>
     {
         logger.Polling.Info($"Start Sync History Alarm");
         var existAlarmData = new List <AlarmData>();
         var existEnclosureAlarmData = EnclosureConnector.Instance.GetExistAlarmDatas(this.FusionDirectorIp);
         var existServerAlarmData = ServerConnector.Instance.GetExistAlarmDatas(this.FusionDirectorIp);
         existAlarmData.AddRange(existEnclosureAlarmData);
         existAlarmData.AddRange(existServerAlarmData);
         logger.Polling.Info($"Get exist events success:[Enclosure:{existAlarmData.Count}] Server:{existServerAlarmData.Count}");
         int totalPage = 1;
         int startPage = 0;
         var allVaildEvent = new List <EventSummary>();
         while (startPage < totalPage)
         {
             try
             {
                 startPage++;
                 var filter = "(EventView='CurrentAlert')";
                 //"(EventOrder='FirstOccurTime desc')"
                 var result = await eventService.GetEventListCollectionAsync(100, (startPage - 1) * 100, filter, "(EventOrder=First_Occur_Time asc)");
                 totalPage = (result.MembersCount - result.MembersCount % 100) / 100 + 1;
                 var validList = result.Members.Where(x => x.EventCategory == "BMC" || x.EventCategory == "Enclosure").ToList();
                 allVaildEvent.AddRange(validList);
                 logger.Polling.Info($"SyncHistoryAlarm Success:[TotalCount:{result.Members.Count}] VaildCount:{validList.Count} Enclosure:{validList.Count(x => x.EventCategory == "Enclosure")} BMC:{validList.Count(x => x.EventCategory == "BMC")} Switch:{validList.Count(x => x.EventCategory == "Switch")} ");
                 foreach (var eventSummary in validList)
                 {
                     try
                     {
                         var alarm = new AlarmData(eventSummary);
                         var existAlarm = existAlarmData.FirstOrDefault(x => x.Sn == alarm.Sn);
                         //对比本次列表中的告警和已存在的告警,如果不同再去插入
                         if (existAlarm == null || !CompareAlarmData(alarm, existAlarm))
                         {
                             var info = await eventService.GetEventsInfoAsync(eventSummary.SerialNumber.ToString());
                             AlarmDatas.Enqueue(new AlarmData(info));
                         }
                     }
                     catch (Exception e)
                     {
                         OnPollingError($"GetEventsInfoAsync Error. EventID:{eventSummary.EventID}.", e);
                     }
                 }
             }
             catch (Exception ex)
             {
                 OnPollingError($"SyncHistoryAlarm Error.pageNo:{startPage}.", ex);
             }
         }
         //检查未关闭的告警,在本次历史告警查询中是否存在,不存在则关闭
         EnclosureConnector.Instance.CheckUnclosedAlert(this.FusionDirectorIp, allVaildEvent.Select(x => x.SerialNumber.ToString()).ToList());
         ServerConnector.Instance.CheckUnclosedAlert(this.FusionDirectorIp, allVaildEvent.Select(x => x.SerialNumber.ToString()).ToList());
     }));
 }
Beispiel #2
0
 private void LoadMoreItems()
 {
     if (AlarmDatas.Any())
     {
         var start  = Alarms.Count;
         var lenght = start + AppConstant.PAGE_SIZE < AlarmDatas.Count ? start + AppConstant.PAGE_SIZE : AlarmDatas.Count;
         for (int i = start; i < lenght; i++)
         {
             Alarms.Add(AlarmDatas[i]);
         }
     }
 }
        /// <summary>
        ///启用插入事件的任务
        /// </summary>
        /// <returns>Task.</returns>
        private void RunInsertEventTask()
        {
            Task.Run(() =>
            {
                while (this.IsRunning)
                {
                    if (AlarmDatas.Count > 0)
                    {
                        var alarm = AlarmDatas.Dequeue();
                        try
                        {
                            var eventData = new EventData(alarm, this.FusionDirectorIp);
                            switch (alarm.EventCategory)
                            {
                            case "BMC":
                                ServerConnector.Instance.InsertEvent(eventData);
                                break;

                            case "Enclosure":
                                EnclosureConnector.Instance.InsertEvent(eventData);
                                break;

                            default:
                                OnPollingError($"Unknown EventCategory: {alarm.EventCategory}.");
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            OnPollingError($"Insert Event Error.AlarmId:{alarm.AlarmId}.", e);
                        }
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(2));
                }
            });
        }
Beispiel #4
0
        public ResultBase UploadAlarmDatas([FromBody] AlarmDatas UploadAlarmDatas)
        {
            ResultAlarm res = new ResultAlarm();

            LoggerManager.Log.Info("Upload alarm datas!\n");

            if (UploadAlarmDatas == null)
            {
                res.IsSuccess = false;
                return(res);
            }


            if (CompanyManagerHelper.CheckDeviceCode(UploadAlarmDatas.DeviceInfo) == false)
            {
                res.IsSuccess = false;
                return(res);
            }



            try
            {
                string AlarmJsonString = JsonConvert.SerializeObject(UploadAlarmDatas);
                //JsonSerializer serializer = new JsonSerializer();
                //StringReader sr = new StringReader(AlarmJsonString);
                //object o = serializer.Deserialize(new JsonTextReader(sr), typeof(AlarmItemBase));

                //var ja = JArray.Parse(AlarmJsonString);



                var client = RedisManager.GetClient();


                client.Select(1);
                string RedisHashName = $"[AlarmList]-[{UploadAlarmDatas.DeviceInfo.CompanyCode}]";
                client.RPush(RedisHashName, AlarmJsonString);


                //client.Select(0);
                ////更新实时故障的状态
                //string DataRedisHashName = $"[{UploadAlarmDatas.DeviceInfo.CompanyCode}]-[{UploadAlarmDatas.DeviceInfo.DeviceCode}]"; ;
                ////Dictionary<string, string> TagDictionary = UploadDatas.Datas.ToDictionary(x => x.TagName, y => y.TagValue);
                //var alarmUUID = Guid.NewGuid().ToString();
                //client.HSet(DataRedisHashName, $"AlarmUpdateCode", alarmUUID);
            }
            catch (Exception ex)
            {
                LoggerManager.Log.Info("更新Resis数据库出错!\n");
                res.IsSuccess = false;
                return(res);
            }


            try
            {
                AlarmState[] temp_uuid_list = new AlarmState[UploadAlarmDatas.AlarmList.Length];



                for (int i = 0; i < UploadAlarmDatas.AlarmList.Length; i++)
                {
                    temp_uuid_list[i] = new AlarmState();

                    temp_uuid_list[i].uuid_code = UploadAlarmDatas.AlarmList[i].AlarmUUID;
                    temp_uuid_list[i].AlarmTime = UploadAlarmDatas.AlarmList[i].AlarmDate;
                }
                res.AlarmUuidList = temp_uuid_list;
            }
            catch
            {
            }



            return(res);
        }