/// <summary> /// 订阅设备变更信息 /// </summary> /// <returns>Huawei.SCOM.ESightPlugin.Models.NotificationResultModel.</returns> /// <exception cref="Exception">Subscription ip can not be localhost /// or /// or</exception> public ESightResult SubscribeNeDevice() { var result = new ESightResult { Code = -1, Description = string.Empty }; try { if (string.IsNullOrEmpty(this.ESight.SubscribeID)) { throw new Exception("SubscribeID can not be empty"); } #region param var pluginConfig = ConfigHelper.GetPluginConfig(); if (pluginConfig.InternetIp == "localhost") { throw new Exception("Subscription ip can not be localhost"); } var alramUrl = HttpUtility.UrlEncode( $"https://{pluginConfig.InternetIp}:{pluginConfig.InternetPort}/NeDeviceNotification/{this.ESight.SubscribeID}"); var param = new { systemID = HttpUtility.UrlEncode(this.ESight.SystemID), openID = this.OpenId, url = alramUrl, dataType = "JSON", desc = "ESightSCOM.ESightPlugin" }; #endregion string urlAlarm = "rest/openapi/notification/common/nedevice"; string url = this.GetFullUrl(urlAlarm); var paramJson = JsonUtil.SerializeObject(param); logger.Api.Info($"SubscribeNeDevice url:{url} param: {paramJson}"); this.CheckAndReLogin(); this.TrustCertificate(); var content = new StringContent(paramJson, Encoding.UTF8, "application/json"); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("openid", this.OpenId); var res = httpClient.PutAsync(url, content).Result; var resultStr = res.Content.ReadAsStringAsync().Result; logger.Api.Info($"SubscribeNeDevice url:{url} result: {resultStr}"); if (!res.IsSuccessStatusCode) { var errMsg = $"Accessing[{url}] ,StatusCode:[{res.StatusCode}],ReasonPhrase:[{res.ReasonPhrase}], Error occurred: [{resultStr}]"; throw new Exception(errMsg); } result = JsonUtil.DeserializeObject <ESightResult>(resultStr); } catch (Exception ex) { result.Description = ex.Message; logger.Api.Error("SubscribeNeDevice Error: ", ex); } return(result); }
/// <summary> /// 取消订阅告警信息 /// </summary> /// <param name="systemId">The system identifier.</param> /// <returns>System.Object.</returns> /// <exception cref="System.Exception">UnSubscribeAlarm Error: + resultStr</exception> public ESightResult UnSubscribeAlarm(string systemId) { var result = new ESightResult { Code = -1, Description = string.Empty }; try { string url = this.GetFullUrl($"rest/openapi/notification/common/alarm?systemID={systemId}&desc=ESightSCOM.ESightPlugin"); logger.Api.Info($"UnSubscribeAlarm url:{url} "); this.CheckAndReLogin(); this.TrustCertificate(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("openid", this.OpenId); var res = httpClient.DeleteAsync(url).Result; var resultStr = res.Content.ReadAsStringAsync().Result; if (!res.IsSuccessStatusCode) { var errMsg = $"Accessing[{url}] ,StatusCode:[{res.StatusCode}],ReasonPhrase:[{res.ReasonPhrase}], Error occurred: [{resultStr}]"; throw new Exception(errMsg); } result = JsonUtil.DeserializeObject <ESightResult>(resultStr); logger.Api.Info($"UnSubscribeAlarm url:{url} result: {resultStr}"); if (result.Code != 0) { throw new Exception("UnSubscribeAlarm Error:" + resultStr); } } catch (Exception ex) { result.Description = ex.Message; logger.Api.Error("UnSubscribeAlarm Error: ", ex); } return(result); }