public static CmdbApplicationDetail getApplicationDetail(string EPRID) { try { uCmdbObject ucmdbObj = getApplicationAttributes(EPRID); CmdbApplicationDetail AppDetailObj = BuildCmdbApplicationDetail(ucmdbObj); return(AppDetailObj); } catch (Exception ex) { throw ex; } }
public static bool CheckEPRID(string EPRID) { try { uCmdbObject cmdbObj = getApplicationAttributes(EPRID); if (cmdbObj.configurationItems.Length > 0) { return(true); } } catch (Exception) //only return false if there is an error { } return(false); }
static public uCmdbObject getApplicationAttributes(string EPRID) { try { string jsonString; string uCMDBServerName = System.Configuration.ConfigurationManager.AppSettings["uCMDBServerName"].ToString(); string url = string.Format("https://{0}/bws2/query/dccp_getPortfolioAppAttributes_by_hp_app_prtfl_id/hp_app_prtfl_id/", uCMDBServerName); url += EPRID; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Accept = "application/json"; request.ContentType = "application/json"; request.Headers.Add("Authorization", "Basic Y3NtX3VjbWRiOkNzbVByb2dyYW0xIQ=="); request.Timeout = 2 * 60 * 1000; // Milliseconds 60000 = 1 minute HttpWebResponse ws = (HttpWebResponse)request.GetResponse(); jsonString = string.Empty; using (StreamReader sreader = new StreamReader(ws.GetResponseStream())) { jsonString = sreader.ReadToEnd(); } JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); uCmdbObject ucmdbObj = jsSerializer.Deserialize <uCmdbObject>(jsonString); return(ucmdbObj); } catch (WebException wex) { throw wex; } catch (Exception ex) { throw ex; } }
public static CmdbApplicationDetail BuildCmdbApplicationDetail(uCmdbObject ucmdbObj) { CmdbApplicationDetail cmdbAppDetailObj = new CmdbApplicationDetail(); List <string> itAssetOwners = new List <string>(); //Select the correct CI for the app foreach (uCmdbCi appCi in ucmdbObj.configurationItems) { if (appCi.type == "hpprtflapp") { uCmdbAttributes appAttributes = appCi.attributes; cmdbAppDetailObj.setConfigurationItem(appAttributes.hp_leg_ci_lgcl_nm); cmdbAppDetailObj.setEpridStatus(appAttributes.hp_ci_stat_nm); } else if (appCi.type == "organization") { //Select the correct relationship for the Org foreach (uCmdbRelationship appRelationship in ucmdbObj.relationships) { if ((appCi.ucmdbId == appRelationship.endpoint1.ucmdbId & appRelationship.endpoint1.type == "organization") & appRelationship.type == "hpitassetowner") { uCmdbAttributes appAttributes = appCi.attributes; switch ((int)appAttributes.hp_org_lvl_nbr)// for our purpose we only need L2 and L3 { case 2: //set lvl 2 org value cmdbAppDetailObj.setLevel2OrgId(appAttributes.name); break; case 3: cmdbAppDetailObj.setLevel3OrgID(appAttributes.name); break; } var childID = appRelationship.endpoint1.ucmdbId; for (int x = (int)appAttributes.hp_org_lvl_nbr; x >= 1; x--) { foreach (uCmdbRelationship appRelationship2 in ucmdbObj.relationships) { if (childID == appRelationship2.endpoint2.ucmdbId) { childID = appRelationship2.endpoint1.ucmdbId; foreach (uCmdbCi appCi2 in ucmdbObj.configurationItems) { if (appCi2.ucmdbId == childID) { //set values uCmdbAttributes appAttributes2 = appCi2.attributes; switch ((int)appAttributes2.hp_org_lvl_nbr)// for our purpose we only need L2 and L3 { case 2: //set lvl 2 org value cmdbAppDetailObj.setLevel2OrgId(appAttributes2.name); break; case 3: cmdbAppDetailObj.setLevel3OrgID(appAttributes2.name); break; } break; //exit appCi2 loop once found } } break; //exit appRelationship2 loop once found } } } break; //exit appRelationship loop once found } } } } return(cmdbAppDetailObj); }