Ejemplo n.º 1
0
 public ResponseBase <LoadCommandListResponse> LoadCommandList(LoadCommandListRequest req)
 {
     try
     {
         tb_node node = null;
         if (!string.IsNullOrEmpty(req.NodeId))
         {
             int nodeId = int.Parse(req.NodeId);
             if (nodeId > 0)
             {
                 node = noderepository.FindSingle(x => x.id == nodeId);
                 if (node == null)
                 {
                     return(ResponseToClient <LoadCommandListResponse>(ResponesStatus.Failed, "当前节点" + req.NodeId + "不存在库中!"));
                 }
             }
         }
         List <tb_commandlibdetail> lib = cmdlibdetailrepository.Find(x => x.isdel == 0).OrderByDescending(x => x.createtime).Take(node.maxrefreshcommandqueuecount).ToList();
         if (lib.Count <= 0)
         {
             return(ResponseToClient <LoadCommandListResponse>(ResponesStatus.Failed, "当前暂无命令列表"));
         }
         LoadCommandListResponse data = new LoadCommandListResponse()
         {
             NodeId = req.NodeId,
             CommandLibDetailList = lib
         };
         return(ResponseToClient <LoadCommandListResponse>(ResponesStatus.Success, "", data));
     }
     catch (Exception ex)
     {
         return(ResponseToClient <LoadCommandListResponse>(ResponesStatus.Exception, JsonConvert.SerializeObject(ex)));
     }
 }
Ejemplo n.º 2
0
        protected override void Run()
        {
            lock (lockObj)
            {
                int monitorstatus = (int)MonitorStatus.Monitoring;
                List <tb_nodemonitor> nodemonitorlist = nodemonitorRep.Find(x => x.isdel == 0 && x.monitorstatus == monitorstatus).ToList();
                List <tb_user>        userList        = userRep.Find(x => x.isdel == 0).ToList();
                StringBuilder         strLog          = new StringBuilder();
                nodemonitorlist.ForEach(x =>
                {
                    try
                    {
                        tb_node node            = nodeRep.FindSingle(m => m.id == x.nodeid);
                        List <int> uidlist      = node.alarmuserid.ConvertToList();
                        List <tb_user> userlist = userList.Where(m => uidlist.Contains(m.id)).ToList();
                        string alaramperson     = node.alarmtype == (int)AlarmType.Email ? string.Join(",", userlist.Select(m => m.useremail).ToArray()) : string.Join(",", userlist.Select(m => m.usermobile).ToArray());
                        if (x.monitorstatus == (int)MonitorStatus.Monitoring)//运行中
                        {
                            #region 检测心跳
                            double totalsecond = Math.Abs(x.lastmonitortime.Subtract(DateTime.Now).TotalSeconds);
                            if (totalsecond > (20 + x.interval / 1000) || totalsecond < 0)//大于10s 说明心跳不正常
                            {
                                nodemonitorRep.UpdateById(new List <int>()
                                {
                                    x.id
                                }, new Dictionary <string, string>()
                                {
                                    { "monitorstatus", ((int)NodeStatus.NoRun).ToString() }
                                });                                                                                                                                               //, { "refreshcommandqueuestatus", ((int)RefreshCommandQueueStatus.NoRefresh).ToString() }
                                if (node.nodestatus != (int)NodeStatus.NoRun)
                                {
                                    string title = "节点(编号):" + node.nodename + "(" + x.nodeid.ToString() + "),监控组件:" +
                                                   x.classname + ",心跳异常,已自动更新为未监控状态,请及时处理该节点下该监控组件!";
                                    StringBuilder strContent = new StringBuilder();
                                    strContent.AppendLine("节点(编号):" + node.nodename + "(" + node.id.ToString() +
                                                          ")<br/>");
                                    strContent.AppendLine("节点监控组件名称(编号):" + x.name + "(" + x.id.ToString() + ")<br/>");
                                    strContent.AppendLine("节点监控组件描述:" + x.discription + "<br/>");
                                    strContent.AppendLine("节点监控类名,命名空间:" + x.classname + "," +
                                                          x.classnamespace.ToString() + "<br/>");
                                    strContent.AppendLine("节点监控组件最后一次心跳时间:" + x.lastmonitortime + "<br/>");
                                    AlarmHelper.AlarmAsync(node.isenablealarm, (AlarmType)node.alarmtype, alaramperson,
                                                           title, strContent.ToString());
                                }
                            }

                            #endregion
                        }
                    }
                    catch (Exception ex)
                    {
                        strLog.AppendLine("监控节点监控组件异常:" + JsonConvert.SerializeObject(ex));
                    }
                });
                if (strLog.Length > 0)
                {
                    log.Error(strLog.ToString());
                }
            }
        }
 static GlobalNodeConfig()
 {
     NodeInfo = new tb_node();
 }