/// <summary> /// 解析保活消息 /// </summary> /// <param name="eSight">The e sight.</param> /// <param name="json">The json.</param> private void AnalysisAlive(HWESightHost eSight, string json) { HWLogger.GetESightSubscribeLogger(eSight.HostIP).Info($"Analysis Alive Message. "); var instance = this.FindInstance(eSight); instance.UpdateAliveTime(DateTime.Now); }
/// <summary> /// 测试eSight是否能够连通。 /// </summary> /// <param name="eSight">The e sight.</param> /// <returns>失败返回错误码,成功返回为空字符</returns> public string TestEsSession(HWESightHost eSight) { try { using (var eSSession = new ESightSession(eSight)) { eSSession.TestConnection(); } } catch (ESSessionExpceion ess) { HWLogger.UI.Error(ess); if (ess.Code == "1") { return(ConstMgr.ErrorCode.SYS_USER_LOGING); } return(ess.Code); } catch (Exception se) { HWLogger.UI.Error(se); return(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR); } return(string.Empty); }
/// <summary> /// Runs when update feSight. /// </summary> /// <param name="fusionDirector">The fusion director.</param> private void RunUpdateESight(HWESightHost eSight) { HWLogger.GetESightNotifyLogger(eSight.HostIP).Info($"Recieve: update eSight"); var instance = this.FindInstance(eSight); instance.Sync(); }
/// <summary> /// Saves the new es session. /// </summary> /// <param name="eSight">The e sight.</param> /// <returns>IESSession.</returns> public ESightSession SaveSession(HWESightHost eSight) { // 测试连接... using (var eSSession = new ESightSession(eSight)) { eSSession.TestConnection(); } // 查找已有的eSesssion,防止重复 var iEsSession = this.FindEsSession(eSight.HostIP); if (iEsSession == null) { // 没有找到已有的eSight. iEsSession = new ESightSession(eSight); } iEsSession.ESight = eSight; lock (this.eSightSessions) { // 锁定向量,防止并发 this.eSightSessions[iEsSession.ESight.HostIP.ToUpper()] = iEsSession; // 存储到缓存。 } HWLogger.UI.Info("SaveSession eSight" + eSight.HostIP); return(iEsSession); }
/// <summary> /// 查找eSight主机信息,并且打开. /// </summary> /// <param name="hostIP">主机IP</param> /// <returns>返回查找到的eSight,没有找到返回为null</returns> public IESSession FindAndOpenESSession(string hostIP) { try { IESSession iESSession = FindESSession(hostIP); //Find eSightHost... HWESightHost hwESightHost = HWESightHostDal.Instance.FindByIP(hostIP); if (iESSession != null) { if (IsSameESightHost(hwESightHost, iESSession.HWESightHost)) { iESSession.Open(); } else { iESSession.InitESight(hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC); iESSession.Open(); } } return(iESSession); } catch (Exception se) { LogUtil.HWLogger.API.Error(se); throw; } }
/// <summary> /// Convert OM MonitoringObject to HWESightHost Entity Function /// </summary> /// <returns></returns> private static Func <EnterpriseManagementObject, HWESightHost> ConvertMonitoringObjectToESightHost() { return(obj => { var props = OM12Connection.GetManagementPackProperties(obj); HWESightHost appliance = new HWESightHost { HostIP = obj[props["Host"]].Value as String, HostPort = Convert.ToInt32(obj[props["Port"]].Value), AliasName = obj[props["AliasName"]].Value as String, SystemID = obj[props["SystemId"]].Value as String, LoginAccount = obj[props["LoginAccount"]].Value as String, LoginPd = obj[props["LoginPassword"]].Value as String, CreateTime = ((DateTime)obj[props["CreatedOn"]].Value).ToLocalTime(), LastModifyTime = ((DateTime)obj[props["LastModifiedOn"]].Value).ToLocalTime(), OpenID = obj[props["OpenID"]].Value as String, SubscribeID = obj[props["SubscribeID"]].Value as String, SubKeepAliveStatus = Convert.ToInt32(obj[props["SubKeepAliveStatus"]].Value), SubscriptionAlarmStatus = Convert.ToInt32(obj[props["SubscriptionAlarmStatus"]].Value), SubscriptionNeDeviceStatus = Convert.ToInt32(obj[props["SubscriptionNeDeviceStatus"]].Value), SubKeepAliveError = obj[props["SubKeepAliveError"]].Value as String, SubscripeAlarmError = obj[props["SubscripeAlarmError"]].Value as String, SubscripeNeDeviceError = obj[props["SubscripeNeDeviceError"]].Value as String, //LatestConnectInfo = obj[props["LatestConnectInfo"]].Value as String, //LatestStatus = obj[props["LatestStatus"]].Value as string, }; return appliance; }); }
private ApiResult SaveNoCert(object eventData) { ApiResult ret = new ApiResult(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR, ""); try { var jsData = JsonUtil.SerializeObject(eventData); var newJsData = CommonBLLMethodHelper.HidePassword(jsData); LogUtil.HWLogger.UI.InfoFormat("Saving eSight configuration(No Cert)..., the param is [{0}]", newJsData); HWESightHost hwESightHost = GetESightConfigFromUI(jsData); var eSSession = ESightEngine.Instance.SaveESSession(hwESightHost.HostIP, hwESightHost.AliasName, hwESightHost.HostPort); LogUtil.HWLogger.UI.Info("Saving eSight configuration(No Cert) successful!"); ret.Code = "0"; ret.Success = true; ret.Msg = "Saving eSight configuration successful!"; } catch (BaseException ex) { LogUtil.HWLogger.UI.Error("Saving eSight configuration failed: ", ex); ret.Code = string.Format("{0}{1}", ex.ErrorModel, ex.Code); ret.Success = false; ret.ExceptionMsg = ex.Message; } catch (Exception ex) { LogUtil.HWLogger.UI.Error("Saving eSight configuration failed: ", ex); ret.Code = ConstMgr.ErrorCode.SYS_UNKNOWN_ERR; ret.Success = false; ret.ExceptionMsg = ex.InnerException.Message ?? ex.Message; } return(ret); }
/// <summary> /// Initializes a new instance of the <see cref="ESightSyncInstance"/> class. /// </summary> /// <param name="eSight"> /// The e sight. /// </param> public ESightSyncInstance(HWESightHost eSight) { this.Session = new ESightSession(eSight); this.NeedUpdateDnQueue = new Queue <string>(); var worker = new Thread(this.DoJob); worker.Start(); }
public static void ClassInitialize(TestContext context) { _hwESightHost = new HWESightHost(); _hwESightHost.HostIP = "127.0.0.1"; _hwESightHost.HostPort = 32102; _hwESightHost.LoginAccount = "test"; _hwESightHost.LoginPwd = "test"; _esSession = new ESSession(); _esSession.SetHttpMode(true); _esSession.InitESight(_hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC); }
/// <summary> /// Inserts the entity. /// </summary> /// <param name="model">The model.</param> public void InsertEntity(HWESightHost model) { var list = this.GetList(); list.Add(model); using (var fs = new FileStream(this.filePath, FileMode.Create)) { var bf = new BinaryFormatter(); bf.Serialize(fs, list); } }
/// <summary> /// 是否相同的eSight实体。 /// </summary> /// <param name="host1"> /// host1 /// </param> /// <param name="host2"> /// host2 /// </param> /// <returns> /// bool /// </returns> public bool IsSameESightHost(HWESightHost host1, HWESightHost host2) { if (host1.HostIP != host2.HostIP) { return(false); } if (host1.HostPort != host2.HostPort) { return(false); } if (host1.AliasName != host2.AliasName) { return(false); } if (host1.LoginAccount != host2.LoginAccount) { return(false); } if (host1.LoginPd != host2.LoginPd) { return(false); } if (host1.CertPath != host2.CertPath) { return(false); } if (host1.SubscriptionAlarmStatus != host2.SubscriptionAlarmStatus) { return(false); } if (host1.SubscripeAlarmError != host2.SubscripeAlarmError) { return(false); } if (host1.SubKeepAliveStatus != host2.SubKeepAliveStatus) { return(false); } if (host1.SubKeepAliveError != host2.SubKeepAliveError) { return(false); } if (host1.SubscriptionNeDeviceStatus != host2.SubscriptionNeDeviceStatus) { return(false); } if (host1.SubscripeNeDeviceError != host2.SubscripeNeDeviceError) { return(false); } return(true); }
/// <summary> /// 初始化eSight信息 /// </summary> /// <param name="hostIP">主机IP</param> /// <param name="port">端口</param> /// <param name="userAccount">用户账户</param> /// <param name="passowrd">密码</param> /// <param name="certpath">证书路径</param> /// <param name="timeoutSec">超时时间默认为:ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC</param> private void InitESight(string hostIP, int port, string userAccount, string passowrd, string certpath, int timeoutSec) { if (_hwESightHost == null) { _hwESightHost = new HWESightHost(); } _hwESightHost.HostIP = hostIP; _hwESightHost.LoginAccount = userAccount; _hwESightHost.LoginPwd = passowrd; _hwESightHost.HostPort = port; _hwESightHost.CertPath = certpath; InitESight(_hwESightHost, timeoutSec); }
/// <summary> /// Finds the instance. /// </summary> /// <param name="eSight">The e sight.</param> /// <returns>Huawei.SCOM.ESightPlugin.Service.ESightSyncInstance.</returns> private ESightSyncInstance FindInstance(HWESightHost eSight) { var syncInstance = this.SyncInstances.FirstOrDefault(y => y.ESightIp == eSight.HostIP); if (syncInstance == null) { syncInstance = new ESightSyncInstance(eSight); this.SyncInstances.Add(syncInstance); } else { syncInstance.UpdateESight(eSight); } return(syncInstance); }
/// <summary> /// Initializes a new instance of the <see cref="ESightSyncInstance"/> class. /// </summary> /// <param name="eSight"> /// The e sight. /// </param> public ESightSyncInstance(HWESightHost eSight) { logger = new ESightLogger(eSight.HostIP); this.IsRunning = true; this.Session = new ESightSession(eSight); this.UpdateDnTasks = new List <UpdateDnTask>(); this.LastAliveTime = DateTime.Now; this.alarmQueue = new Queue <AlarmData>(); this.StartAlarmEventProcessor(); this.StartNeDeviceEventProcessor(); this.StartKeepAliveJob(); this.pluginConfig = ConfigHelper.GetPluginConfig(); var scheduler = new LimitedConcurrencyLevelTaskScheduler(pluginConfig.ThreadCount); taskFactory = new TaskFactory(cts.Token, TaskCreationOptions.HideScheduler, TaskContinuationOptions.HideScheduler, scheduler); }
public void ChkOpenResultTest() { ESSession esSession = new ESSession(); HWESightHost hwESightHost = new HWESightHost(); hwESightHost.HostIP = "127.0.0.1"; hwESightHost.HostPort = 32102; hwESightHost.LoginAccount = "test"; hwESightHost.LoginPwd = "test"; esSession = new ESSession(); esSession.SetHttpMode(true); esSession.InitESight(hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC); JObject result = JsonUtil.DeserializeObject <JObject>("{\"code\":1,\"data\":\"bfec0163 - dd56 - 473e-b11f - 6d5845e1b684\", \"description\":\"Operation success.\"}"); esSession.ChkOpenResult(result); }
/// <summary> /// 解析告警变更消息 /// </summary> /// <param name="eSight">The eSight.</param> /// <param name="json">The json.</param> /// <exception cref="System.Exception"></exception> private void AnalysisAlarm(HWESightHost eSight, string json) { try { var messge = JsonUtil.DeserializeObject <TcpMessage <NotifyModel <AlarmData> > >(json); var alarmData = messge.Data; if (alarmData != null) { var dn = alarmData.Data.NeDN; var alarmSn = alarmData.Data.AlarmSN; HWLogger.GetESightNotifyLogger(eSight.HostIP).Info($"[alarmSn:{alarmSn}] AnalysisAlarm.[DN:{dn}][optType:{alarmData.Data.OptType}][alarmName:{alarmData.Data.AlarmName}] "); var instance = this.FindInstance(eSight); instance.UpdateAliveTime(DateTime.Now);//更新保活時間(esight在发生告警后不会发送保活信息) var serverType = instance.GetServerTypeByDn(dn); if (serverType == ServerTypeEnum.ChildBlade) { //更新子刀片的管理板 var childDeviceId = $"{eSight.HostIP}-{dn}"; var parentDn = BladeConnector.Instance.GetParentDn(childDeviceId); instance.StartUpdateTask(parentDn, ServerTypeEnum.Blade, alarmSn); } if (serverType == ServerTypeEnum.ChildHighdensity) { //更新子刀片的管理板 var childDeviceId = $"{eSight.HostIP}-{dn}"; var parentDn = HighdensityConnector.Instance.GetParentDn(childDeviceId); instance.StartUpdateTask(parentDn, ServerTypeEnum.Highdensity, alarmSn); } if (serverType == ServerTypeEnum.Switch) { //交换板告警 只用更新管理板 var childDeviceId = $"{eSight.HostIP}-{dn}"; var parentDn = BladeConnector.Instance.GetSwitchParentDn(childDeviceId); instance.StartUpdateTask(parentDn, ServerTypeEnum.Blade, alarmSn); instance.SubmitNewAlarm(alarmData.Data); return; } instance.StartUpdateTask(alarmData.Data.NeDN, serverType, alarmSn); instance.SubmitNewAlarm(alarmData.Data); } } catch (Exception e) { HWLogger.GetESightNotifyLogger(eSight.HostIP).Error(e, $"AnalysisAlarm Error."); } }
/// <summary> /// 解析设备变更消息 /// </summary> /// <param name="eSight">The e sight.</param> /// <param name="json">The json.</param> /// <exception cref="System.Exception"> /// </exception> private void AnalysisNeDevice(HWESightHost eSight, string json) { try { var messge = JsonUtil.DeserializeObject <TcpMessage <NotifyModel <NedeviceData> > >(json); var nedeviceData = messge.Data; if (nedeviceData == null) { return; } var dn = nedeviceData.Data.DeviceId; HWLogger.GetESightNotifyLogger(eSight.HostIP).Info($"AnalysisNeDevice [MsgType:{nedeviceData.MsgType}] [DN:{dn}][deviceName:{nedeviceData.Data.DeviceName}][desc:{nedeviceData.Data.Description}] "); var instance = this.FindInstance(eSight); instance.UpdateAliveTime(DateTime.Now);//更新保活時間(esight在发生告警后不会发送保活信息) switch (nedeviceData.MsgType) { case 1: // 新增 //instance.Sync(); break; case 2: // 删除 // 高密的设备变更消息需要单独处理 var deleteServerType = instance.GetServerTypeByDn(dn); if (deleteServerType == ServerTypeEnum.ChildHighdensity || deleteServerType == ServerTypeEnum.Highdensity) { instance.SyncHighdensityList(); } else { instance.DeleteServer(dn, deleteServerType); } break; case 3: // 修改 var modifyServerType = instance.GetServerTypeByDn(dn); instance.StartUpdateTask(dn, modifyServerType, 0); break; default: break; } } catch (Exception e) { HWLogger.GetESightNotifyLogger(eSight.HostIP).Error(e, $"AnalysisNeDevice Error."); } }
/// <summary> /// 保存当前eSight连接对象信息或状态到服务器。 /// </summary public bool SaveToDB() { CheckInit(); try { System.Threading.Monitor.Enter(_lockInstance);//开锁 IHWESightHostDal hwESightHostDal = HWESightHostDal.Instance; LogUtil.HWLogger.API.DebugFormat("db id={0}", this.HWESightHost.ID); if (this.HWESightHost.ID > 0)//是否新的eSight对象 { HWESightHost hwESightHost = hwESightHostDal.GetEntityById(this.HWESightHost.ID); if (hwESightHost != null)//是否新的eSight对象,是否找到 { LogUtil.HWLogger.API.DebugFormat("update old id={0}", _hwESightHost.ID); hwESightHostDal.UpdateEntity(this._hwESightHost); } else //重新保存一个新的。 { LogUtil.HWLogger.API.Debug("add1 old id=" + HWESightHost.ID); int oldid = _hwESightHost.ID; //_hwESightHost.ID = 0; _hwESightHost.CreateTime = System.DateTime.Now; hwESightHostDal.UpdateEntity(_hwESightHost); LogUtil.HWLogger.API.DebugFormat("add old id={0},new id={1}", oldid, _hwESightHost.ID); } } else { //插入新的eSight对象。 _hwESightHost.CreateTime = System.DateTime.Now; _hwESightHost.ID = hwESightHostDal.InsertEntity(_hwESightHost); LogUtil.HWLogger.API.DebugFormat("add1 id=" + _hwESightHost.ID); } } catch (Exception se) { LogUtil.HWLogger.API.Error(se); throw; } finally { System.Threading.Monitor.Exit(_lockInstance);//释放锁。 } return(true); }
/// <summary> /// Updates the entity. /// </summary> /// <param name="model">The model.</param> public void UpdateEntity(HWESightHost model) { var list = this.GetList(); var oldModel = list.FirstOrDefault(x => x.HostIP == model.HostIP); if (oldModel == null) { throw new Exception($"Can not find the eSight:{model.HostIP}"); } list.Remove(oldModel); list.Add(model); using (var fs = new FileStream(this.filePath, FileMode.Create)) { var bf = new BinaryFormatter(); bf.Serialize(fs, list); } }
/// <summary> /// The test. /// </summary> /// <param name="eSight">The e sight.</param> /// <returns>The <see cref="ApiResult" />.</returns> public static ApiResult Test(HWESightHost eSight) { var ret = new ApiResult(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR, string.Empty); try { var json = JsonUtil.SerializeObject(eSight); HWLogger.UI.InfoFormat("Testing eSight connect..., the param is [{0}]", HidePd(json)); var LoginPd = eSight.LoginPd; eSight.LoginPd = EncryptUtil.EncryptPwd(LoginPd); var testResult = ESightEngine.Instance.TestEsSession(eSight); if (string.IsNullOrEmpty(testResult)) { HWLogger.UI.Info("Testing eSight connect successful!"); ret.Code = "0"; ret.Success = true; ret.Msg = "Testing eSight connect successful!"; } else { HWLogger.UI.Info("Testing eSight connect failed!"); ret.Code = testResult; ret.Success = false; ret.ExceptionMsg = "Testing eSight connect failed!"; } } catch (BaseException ex) { HWLogger.UI.Error("Testing eSight connect failed: ", ex); ret.Success = false; ret.Code = $"{ex.ErrorModel}{ex.Code}"; ret.ExceptionMsg = ex.Message; } catch (Exception ex) { HWLogger.UI.Error("Testing eSight connect failed: ", ex); ret.Code = ConstMgr.ErrorCode.SYS_UNKNOWN_ERR; ret.Success = false; ret.Msg = "Testing eSight connect failed!"; ret.ExceptionMsg = ex.InnerException?.Message ?? ex.Message; } return(ret); }
private ApiResult Test(object eventData) { ApiResult ret = new ApiResult(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR, ""); try { var jsData = JsonUtil.SerializeObject(eventData); var newJsData = CommonBLLMethodHelper.HidePassword(jsData); LogUtil.HWLogger.UI.InfoFormat("Testing eSight connect..., the param is [{0}]", newJsData); HWESightHost hwESightHost = GetESightConfigFromUI(jsData); string testResult = ESightEngine.Instance.TestESSession(hwESightHost.HostIP, hwESightHost.HostPort, hwESightHost.LoginAccount, hwESightHost.LoginPwd); if (string.IsNullOrEmpty(testResult)) { LogUtil.HWLogger.UI.Info("Testing eSight connect successful!"); ret.Code = "0"; ret.Success = true; ret.Msg = "Testing eSight connect successful!"; } else { LogUtil.HWLogger.UI.Info("Testing eSight connect failed!"); ret.Code = testResult; ret.Success = false; ret.ExceptionMsg = "Testing eSight connect failed!"; } } catch (BaseException ex) { LogUtil.HWLogger.UI.Error("Testing eSight connect failed: ", ex); ret.Success = false; ret.Code = string.Format("{0}{1}", ex.ErrorModel, ex.Code); ret.ExceptionMsg = ex.Message; } catch (Exception ex) { LogUtil.HWLogger.UI.Error("Testing eSight connect failed: ", ex); ret.Code = ConstMgr.ErrorCode.SYS_UNKNOWN_ERR; ret.Success = false; ret.Msg = "Testing eSight connect failed!"; ret.ExceptionMsg = ex.InnerException.Message ?? ex.Message; } return(ret); }
/// <summary> /// The update entity. /// </summary> /// <param name="model"> /// The model. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public int UpdateEntity(HWESightHost model) { try { var filePath = this.FilePath + "\\eSight.bin"; var list = new List <HWESightHost>(); if (File.Exists(filePath)) { using (var fs = new FileStream(filePath, FileMode.Open)) { var bf = new BinaryFormatter(); list = bf.Deserialize(fs) as List <HWESightHost>; } if (list != null) { var oldModel = list.FirstOrDefault(x => x.HostIP == model.HostIP); if (oldModel == null) { return(-1); } list.Remove(oldModel); model.ID = oldModel.ID; list.Add(model); using (var fs = new FileStream(filePath, FileMode.Create)) { var bf = new BinaryFormatter(); bf.Serialize(fs, list); } return(1); } } } catch (Exception ex) { HWLogger.UI.Error("UpdateEntity Error:" + ex); throw; } return(-1); }
/// <summary> /// 是否相同的eSight实体。 /// </summary> /// <param name="host1">host1</param> /// <param name="host2">host2</param> /// <returns>bool</returns> private bool IsSameESightHost(HWESightHost host1, HWESightHost host2) { var propsToSerialise = new List <string>() { "HostIP", "HostPort", "AliasName", "LoginAccount", "LoginPwd", "CertPath" }; DynamicContractResolver contractResolver = new DynamicContractResolver(propsToSerialise); string str1 = JsonConvert.SerializeObject(host1, Formatting.None, new JsonSerializerSettings { ContractResolver = contractResolver }); string str2 = JsonConvert.SerializeObject(host2, Formatting.None, new JsonSerializerSettings { ContractResolver = contractResolver }); return(string.Equals(str1, str2)); }
public void DisposeESightTest() { ESSession esSession = new ESSession(); HWESightHost hwESightHost = new HWESightHost(); hwESightHost.HostIP = "127.0.0.1"; hwESightHost.HostPort = 32102; hwESightHost.LoginAccount = "test"; hwESightHost.LoginPwd = "test"; esSession = new ESSession(); esSession.SetHttpMode(true); esSession.InitESight(hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC); esSession.Open(); bool isSccu = esSession.SaveToDB(); Assert.IsTrue(isSccu); esSession.HClient = null; //esSession.HWESightHost.HostIP = "xxx.xxx.xxx"; esSession.Dispose(); }
/// <summary> /// The insert entity. /// </summary> /// <param name="model"> /// The model. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public int InsertEntity(HWESightHost model) { var id = 0; try { HWLogger.UI.Info("FilePath" + FilePath); var filePath = FilePath + "\\eSight.bin"; var list = new List <HWESightHost>(); if (File.Exists(filePath)) { using (var fs = new FileStream(filePath, FileMode.Open)) { var bf = new BinaryFormatter(); list = bf.Deserialize(fs) as List <HWESightHost>; } if (list.Count > 0) { id = list.Max(x => x.ID); } } model.ID = id + 1; list.Add(model); using (var fs = new FileStream(filePath, FileMode.Create)) { var bf = new BinaryFormatter(); bf.Serialize(fs, list); } return(model.ID); } catch (Exception ex) { HWLogger.UI.Error("FilePath" + FilePath); HWLogger.UI.Error("InsertEntity Error:" + ex); throw; } }
public void DeleteESightTestZero() { ESSession esSession = new ESSession(); HWESightHost hwESightHost = new HWESightHost(); hwESightHost.HostIP = "127.0.0.1"; hwESightHost.HostPort = 32102; hwESightHost.LoginAccount = "test"; hwESightHost.LoginPwd = "test"; esSession = new ESSession(); esSession.SetHttpMode(true); esSession.InitESight(hwESightHost, ConstMgr.HWESightHost.DEFAULT_TIMEOUT_SEC); bool isSccu = esSession.SaveToDB(); Assert.IsTrue(isSccu); int oldId = esSession.HWESightHost.ID; esSession.HWESightHost.ID = 0; isSccu = esSession.DeleteESight(); Assert.IsTrue(isSccu); esSession.HWESightHost.ID = oldId; esSession.DeleteESight(); }
/// <summary> /// Updates the e sight. /// </summary> /// <param name="eSight">The e sight.</param> public void UpdateESight(HWESightHost eSight) { this.Session.ESight = eSight; }
/// <summary> /// Initializes a new instance of the <see cref="ESightSession"/> class. /// </summary> /// <param name="eSight">The e sight.</param> public ESightSession(HWESightHost eSight) { this.ESight = eSight; logger = new ESightLogger(eSight.HostIP); }
/// <summary> /// The process request. /// </summary> /// <param name="context"> /// The context. /// </param> public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; context.Response.AddHeader("Access-Control-Allow-Origin", "*"); var action = context.Request.QueryString["action"]; switch (action) { case "list": var query = new ParamPagingOfQueryESight(); query.PageNo = 1; query.PageSize = 100000; query.HostIp = context.Request.Form["hostIP"] ?? string.Empty; var list = ESightHelper.GetList(query); Task.Run(() => { ESightEngine.Instance.CheckAllESightConnection(); }); context.Response.Write(JsonUtil.SerializeObject(list).Replace("null", "\"\"")); break; case "test": var testModel = new HWESightHost(); testModel.HostIP = context.Request.Form["hostIP"]; testModel.HostPort = Convert.ToInt32(context.Request.Form["hostPort"]); testModel.LoginAccount = context.Request.Form["loginAccount"]; testModel.LoginPd = context.Request.Form["LoginPd"]; context.Response.Write(JsonUtil.SerializeObject(ESightHelper.Test(testModel))); break; case "add": var addModel = new HWESightHost(); addModel.AliasName = context.Request.Form["aliasName"]; addModel.HostIP = context.Request.Form["hostIP"]; addModel.HostPort = Convert.ToInt32(context.Request.Form["hostPort"]); addModel.LoginAccount = context.Request.Form["loginAccount"]; addModel.SystemID = context.Request.Form["systemId"]; addModel.LoginPd = context.Request.Form["LoginPd"]; addModel.SubscripeNeDeviceError = string.Empty; addModel.SubscripeAlarmError = string.Empty; context.Response.Write(JsonUtil.SerializeObject(ESightHelper.Add(addModel))); break; case "update": var updateModel = new HWESightHost(); updateModel.AliasName = context.Request.Form["aliasName"]; updateModel.HostIP = context.Request.Form["hostIP"]; updateModel.HostPort = Convert.ToInt32(context.Request.Form["hostPort"]); updateModel.LoginAccount = context.Request.Form["loginAccount"]; updateModel.SystemID = context.Request.Form["systemId"]; updateModel.LoginPd = context.Request.Form["LoginPd"]; if (!string.IsNullOrWhiteSpace(updateModel.LoginAccount)) { context.Response.Write(JsonUtil.SerializeObject(ESightHelper.Update(updateModel))); } else { context.Response.Write(JsonUtil.SerializeObject(ESightHelper.UpdateWithOutPass(updateModel))); } break; case "delete": var ids = context.Request.Form["ids"]; var result = ESightHelper.Delete(ids); context.Response.Write(JsonUtil.SerializeObject(result)); break; default: var ret = new WebReturnLGResult <HWESightHost> { Code = CoreUtil.GetObjTranNull <int>( ConstMgr.ErrorCode.SYS_UNKNOWN_ERR), Description = string.Empty }; ret.Code = -999999; context.Response.Write(JsonUtil.SerializeObject(ret)); break; } }
/// <summary> /// Updates the with out pass. /// </summary> /// <param name="model">The new e sight.</param> /// <returns>Huawei.SCOM.ESightPlugin.WebServer.Model.ApiResult.</returns> public static ApiResult UpdateWithOutPass(HWESightHost model) { var ret = new ApiResult(ConstMgr.ErrorCode.SYS_UNKNOWN_ERR, string.Empty); try { var json = JsonUtil.SerializeObject(model); HWLogger.UI.InfoFormat("Update eSight , the param is [{0}]", HidePd(json)); #region 赋值 var eSight = ESightDal.Instance.GetEntityByHostIp(model.HostIP); if (eSight == null) { ret.Code = "-81111"; ret.Success = false; ret.Msg = $"can not find eSight: hostip {model.HostIP}"; return(ret); } eSight.AliasName = model.AliasName; eSight.HostPort = model.HostPort; eSight.LastModifyTime = DateTime.Now; var oldSystemId = eSight.SystemID; var isChangeSystemId = oldSystemId != model.SystemID; if (isChangeSystemId) { // 修改了systemId,需要重新订阅 eSight.SystemID = model.SystemID; eSight.SubscribeID = Guid.NewGuid().ToString(); eSight.SubscripeNeDeviceError = string.Empty; eSight.SubscripeAlarmError = string.Empty; eSight.SubscriptionNeDeviceStatus = 0; eSight.SubscriptionAlarmStatus = 0; } #endregion ESightEngine.Instance.SaveSession(eSight); if (isChangeSystemId) { // 修改了systemId,在session保存成功后重新订阅 UnSubscribeESight(eSight.HostIP, oldSystemId); } // UpdateWithOutPass ESightDal.Instance.UpdateEntity(eSight); // 告诉服务 Task.Run(() => { var message = new TcpMessage <string>(eSight.HostIP, TcpMessageType.SyncESight, "Update ESight WithOut Pass"); NotifyClient.Instance.SendMsg(message); }); HWLogger.UI.Info("Update eSight successful!"); ret.Code = "0"; ret.Success = true; ret.Msg = "Update eSight successful!"; } catch (BaseException ex) { HWLogger.UI.Error("Update eSight failed: ", ex); ret.Code = $"{ex.ErrorModel}{ex.Code}"; ret.Success = false; ret.ExceptionMsg = ex.Message; } catch (Exception ex) { HWLogger.UI.Error("Update eSight failed: ", ex); ret.Code = ConstMgr.ErrorCode.SYS_UNKNOWN_ERR; ret.Success = false; ret.ExceptionMsg = ex.InnerException == null ? ex.Message : ex.InnerException.Message; } return(ret); }