public object GetDynamicParameters()
        {
            RuntimeDefinedParameterDictionary dynamicParams = null;

            if (serverTypeSet)
            {
                ServerTypeEnum type = ServerType;
                switch (type)
                {
                case ServerTypeEnum.SQL:
                    this.connCmdlet = new SqlConnectionInfoCmdlet(this.MyInvocation);
                    break;

                case ServerTypeEnum.MongoDb:
                    this.connCmdlet = new MongoDbConnectionInfoCmdlet(this.MyInvocation);
                    break;

                case ServerTypeEnum.SQLMI:
                    this.connCmdlet = new MiSqlConnectionInfoCmdlet(this.MyInvocation);
                    break;

                default:
                    throw new PSArgumentException();
                }

                dynamicParams = connCmdlet.RuntimeDefinedParams;
            }

            return(dynamicParams);
        }
Esempio n. 2
0
 public MonitoringDeviceObject(string deviceId, MonitoringObject Device, ServerTypeEnum serverType, Func <string, MonitoringObject> LoadFunc)
 {
     this.DeviceId   = deviceId;
     this.Device     = Device;
     this.LoadFunc   = LoadFunc;
     this.ServerType = serverType;
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceChangeEventData" /> class.
        /// Initializes a new instance of the <see cref="EventData" /> class.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="eSightIp">The e sight ip.</param>
        public DeviceChangeEventData(NedeviceData data, string eSightIp, ServerTypeEnum serverType)
        {
            this.DeviceId = $"{eSightIp}-{data.DeviceId}";

            this.LoggingComputer = data.DeviceId;
            this.ESightIp        = eSightIp;
            this.Message         = data.Description;
            this.NedeviceData    = data;
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the string array
        /// </summary>
        /// <param name="serverType">server type enumeration</param>
        /// <returns></returns>
        public static string[] Get(ServerTypeEnum serverType)
        {
            string[] servers;
            string   serverName = null;
            string   domain = null;
            uint     level = 101, prefmaxlen = 0xFFFFFFFF, entriesread = 0, totalentries = 0;
            uint     resume_handle = 0;

            try
            {
                unsafe
                {
                    //Get a pointer to the server info structure
                    SERVER_INFO_101 *si = null;
                    SERVER_INFO_101 *pTmp;                     //Temp pointer for use when looping through returned	(pointer) array

                    //this api requires a pointer to a byte array...which is actually a pointer to an array
                    //of SERVER_INFO_101 structures
                    //If the domain parameter is NULL, the primary domain is implied.
                    uint nRes = NetServerEnum(serverName, level, (uint *)&si, prefmaxlen, ref entriesread, ref totalentries, (uint)serverType, domain, resume_handle);
                    servers = new string[entriesread];

                    if (nRes == 0)
                    {
                        //Assign the temp pointer
                        if ((pTmp = si) != null)
                        {
                            //Loop through the entries
                            for (int i = 0; i < entriesread; i++)
                            {
                                try
                                {
                                    servers[i] = Marshal.PtrToStringAuto(pTmp->lpszServerName);
                                }
                                catch (Exception e)
                                {
                                    string error = e.Message;
                                }
                                //Increment the pointer...essentially move to the next structure in	the array
                                pTmp++;
                            }
                        }
                    }
                }
            }
            catch (Exception /*e*/)
            {
                return(null);
            }

            return(servers);
        }
        /// <summary>
        /// The delete server.
        /// </summary>
        /// <param name="dn">The dn.</param>
        /// <param name="serverType">Type of the server.</param>
        public void DeleteServer(string dn, ServerTypeEnum serverType)
        {
            Task.Run(() =>
            {
                try
                {
                    logger.NotifyProcess.Debug($"Delete the server on device change.[Dn:{dn}] [serverType:{serverType}]");
                    var deviceId = $"{this.ESightIp}-{dn}";
                    switch (serverType)
                    {
                    case ServerTypeEnum.Blade:
                        BladeConnector.Instance.RemoveServerByDeviceId(this.ESightIp, deviceId);
                        break;

                    case ServerTypeEnum.ChildBlade:
                        BladeConnector.Instance.RemoveChildBlade(this.ESightIp, deviceId);
                        break;

                    case ServerTypeEnum.Highdensity:
                        HighdensityConnector.Instance.RemoveServerByDeviceId(this.ESightIp, deviceId);
                        break;

                    case ServerTypeEnum.ChildHighdensity:
                        HighdensityConnector.Instance.RemoveChildHighDensityServer(this.ESightIp, deviceId);
                        break;

                    case ServerTypeEnum.Switch:
                        BladeConnector.Instance.RemoveChildSwitch(this.ESightIp, deviceId);
                        break;

                    case ServerTypeEnum.Rack:
                        RackConnector.Instance.RemoveServerByDeviceId(this.ESightIp, deviceId);
                        break;

                    case ServerTypeEnum.KunLun:
                        KunLunConnector.Instance.RemoveServerByDeviceId(this.ESightIp, deviceId);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    logger.NotifyProcess.Error(ex, $"DeleteServer {dn} Error: ");
                }
            });
        }
        /// <summary>
        /// The insert event.
        /// </summary>
        /// <param name="alarmData">The alarm data.</param>
        /// <param name="serverType">Type of the server.</param>
        public void InsertEvent(AlarmData alarmData, ServerTypeEnum serverType)
        {
            Task.Run(() =>
            {
                try
                {
                    //logger.NotifyProcess.Info($"Start InsertEvent. [Dn:{alarmData.NeDN}] [serverType:{serverType}]");

                    var alertModel = new EventData(alarmData, this.ESightIp, serverType);
                    switch (serverType)
                    {
                    case ServerTypeEnum.Blade:
                    case ServerTypeEnum.ChildBlade:
                    case ServerTypeEnum.Switch:
                        BladeConnector.Instance.InsertEvent(alertModel, serverType, this.ESightIp);
                        break;

                    case ServerTypeEnum.Highdensity:
                    case ServerTypeEnum.ChildHighdensity:
                        HighdensityConnector.Instance.InsertEvent(alertModel, serverType, this.ESightIp);
                        break;

                    case ServerTypeEnum.Rack:
                        RackConnector.Instance.InsertEvent(alertModel, this.ESightIp);
                        break;

                    case ServerTypeEnum.KunLun:
                        KunLunConnector.Instance.InsertEvent(alertModel, this.ESightIp);
                        break;
                    }
                    //logger.NotifyProcess.Info($"End InsertEvent {alarmData.NeDN}");
                }
                catch (Exception ex)
                {
                    logger.NotifyProcess.Error(ex, "InsertEvent Error: ");
                }
            });
        }
        /// <summary>
        /// Inserts the device change event.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="serverType">Type of the server.</param>
        public void InsertDeviceChangeEvent(NedeviceData data, ServerTypeEnum serverType)
        {
            Task.Run(() =>
            {
                try
                {
                    //logger.NotifyProcess.Info($"Start Insert deviceChangeEvent.[Dn:{data.DeviceId}] [serverType:{serverType}]");
                    var deviceChangeEventData = new DeviceChangeEventData(data, this.ESightIp, serverType);
                    switch (serverType)
                    {
                    case ServerTypeEnum.Blade:
                    case ServerTypeEnum.ChildBlade:
                    case ServerTypeEnum.Switch:
                        BladeConnector.Instance.InsertDeviceChangeEvent(deviceChangeEventData, serverType, this.ESightIp);
                        break;

                    case ServerTypeEnum.Highdensity:
                    case ServerTypeEnum.ChildHighdensity:
                        HighdensityConnector.Instance.InsertDeviceChangeEvent(deviceChangeEventData, serverType, this.ESightIp);
                        break;

                    case ServerTypeEnum.Rack:
                        RackConnector.Instance.InsertDeviceChangeEvent(deviceChangeEventData, this.ESightIp);
                        break;

                    case ServerTypeEnum.KunLun:
                        KunLunConnector.Instance.InsertDeviceChangeEvent(deviceChangeEventData, this.ESightIp);
                        break;
                    }
                    //logger.NotifyProcess.Info($"End deviceChangeEvent: {data.DeviceId}");
                }
                catch (Exception ex)
                {
                    logger.NotifyProcess.Error(ex, "InsertEvent Error: ");
                }
            });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EventData" /> class.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="eSightIp">The e sight ip.</param>
        /// <param name="serverType">Type of the server.</param>
        public EventData(AlarmData data, string eSightIp, ServerTypeEnum serverType)
        {
            this.AlarmData = data;
            this.OptType   = data.OptType;
            this.DeviceId  = $"{eSightIp}-{data.MoDN}";

            this.ESightIp        = eSightIp;
            this.AlarmSn         = data.AlarmSN;
            this.Channel         = data.AlarmName;
            this.LevelId         = this.GetLevel(data.PerceivedSeverity, data.OptType);
            this.LoggingComputer = data.MoDN;
            this.Message         = data.AlarmName;
            this.CustomData      = new CustomData()
            {
                Dn                    = data.MoDN,
                AlarmSn               = data.AlarmSN,
                OptType               = this.OptTypeTxt,
                EventTime             = TimeHelper.StampToDateTime(data.EventTime.ToString()).ToString(),
                NeType                = string.IsNullOrEmpty(data.NeType) ? string.Empty : data.NeType,
                ObjectInstance        = string.IsNullOrEmpty(data.ObjectInstance) ? string.Empty : data.ObjectInstance,
                ProposedRepairActions = string.IsNullOrEmpty(data.ProposedRepairActions) ? string.Empty : data.ObjectInstance,
                AdditionalInformation = string.IsNullOrEmpty(data.AdditionalInformation) ? string.Empty : data.ObjectInstance
            };
        }
        /// <summary>
        /// 开启一个更新dn的任务
        /// </summary>
        /// <param name="dn">The dn.</param>
        /// <param name="serverType">Type of the server.</param>
        /// <param name="alarmSn">The alarm sn.</param>
        public void StartUpdateTask(string dn, ServerTypeEnum serverType, int alarmSn)
        {
            var deviceId = $"{this.ESightIp}-{dn}";

            try
            {
                logger.NotifyProcess.Info($"[alarmSn:{alarmSn}] New UpdateDnTask.[Dn:{dn}] [serverType:{serverType}]");
                var exsit = this.UpdateDnTasks.FirstOrDefault(x => x.Dn == dn);
                //Dn已存在
                if (exsit != null)
                {
                    #region Dn已存在
                    //如果首次刷新已经执行过,此处再执行一次
                    if (exsit.FirstRefreshTime < DateTime.Now)
                    {
                        exsit.FirstRefreshTime = DateTime.Now.AddSeconds(60);
                        exsit.StartFirstUpdateTask();
                        logger.NotifyProcess.Debug($"[alarmSn:{alarmSn}]-[{dn}] ReStart FirstRefreshTask.[{exsit.FirstRefreshTime:yyyy-MM-dd HH:mm:ss}]");
                    }

                    var oldAlarmSn = exsit.AlarmSn;
                    exsit.AlarmSn = alarmSn;
                    //延长最后一次刷新时间
                    exsit.LastRefreshTime = DateTime.Now.AddSeconds(5 * 60);
                    logger.NotifyProcess.Debug($"[alarmSn:{alarmSn}] [preAlarmSn:{oldAlarmSn}] [{dn}] Delay LastRefreshTime:{exsit.LastRefreshTime:yyyy-MM-dd HH:mm:ss}.");
                    return;

                    #endregion
                }
                if (serverType == ServerTypeEnum.Switch)
                {
                    return;
                }
                // 暂不可以通过交换板的dn获取交换板的详情
                // 交换板DN 上报的告警信息刷新管理板所有部件(包括交换板)健康状态
                var task = new UpdateDnTask(this, dn, alarmSn);

                if (serverType == ServerTypeEnum.Blade)
                {
                    task.UpdateAction = UpdateBladeServer;
                }
                if (serverType == ServerTypeEnum.ChildBlade)
                {
                    task.UpdateAction = UpdateChildBladeServer;
                }
                if (serverType == ServerTypeEnum.ChildHighdensity)
                {
                    task.UpdateAction = UpdateChildHighdensityServer;
                }
                // 高密管理板不会有告警上来
                if (serverType == ServerTypeEnum.Highdensity)
                {
                    task.UpdateAction = UpdateHighdensityServer;
                }
                if (serverType == ServerTypeEnum.Rack)
                {
                    task.UpdateAction = UpdateRackServer;
                }
                if (serverType == ServerTypeEnum.KunLun)
                {
                    task.UpdateAction = UpdateKunLunServer;
                }
                task.FirstRefreshTime = DateTime.Now.AddSeconds(60);
                task.LastRefreshTime  = DateTime.Now.AddSeconds(5 * 60);

                logger.NotifyProcess.Debug($"[alarmSn:{alarmSn}]-[{dn}] Will StartFirstUpdateTask [{task.FirstRefreshTime:yyyy-MM-dd HH:mm:ss}].");
                logger.NotifyProcess.Debug($"[alarmSn:{alarmSn}]-[{dn}] Will StartLastUpdateTask near [{task.LastRefreshTime:yyyy-MM-dd HH:mm:ss}].");

                task.StartFirstUpdateTask();
                task.StartLastUpdateTask((isSuccess, isChange) =>
                {
                    if (isSuccess)
                    {
                        logger.NotifyProcess.Debug($"[alarmSn:{task.AlarmSn}]-[{dn}] End LastRefreshTask.[isChange:{isChange}] .");
                    }
                    else
                    {
                        logger.NotifyProcess.Error($"[alarmSn:{task.AlarmSn}]-[{dn}] LastRefreshTask Faild.");
                    }
                    this.UpdateDnTasks.Remove(task);
                });
                this.UpdateDnTasks.Add(task);
            }
            catch (Exception e)
            {
                logger.NotifyProcess.Debug(e, $"[alarmSn:{alarmSn}]-[Dn:{dn}] [serverType:{serverType}] StartUpdateTask Error.");
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventData" /> class.
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="eSightIp">The e sight ip.</param>
 /// <param name="serverType">Type of the server.</param>
 public EventData(AlarmData data, string eSightIp, ServerTypeEnum serverType)
 {
     this.AlarmData  = data;
     this.ESightIp   = eSightIp;
     this.ServerType = serverType;
 }