//---------------------------------------------------------------------- public CSnmpProxy GetTypePourSupervision(CMemoryDb database) { if (database == null) { database = CMemoryDbPourSupervision.GetMemoryDb(ContexteDonnee); } CSnmpProxy proxy = new CSnmpProxy(database); if (!proxy.ReadIfExist(Id.ToString(), false)) { proxy.CreateNew(Id.ToString()); } else if (!proxy.IsToRead()) { return(proxy); } proxy.Row[CMemoryDb.c_champIsToRead] = false; proxy.Libelle = Libelle; proxy.AdresseIP = GetIPFromString(AdresseIp); proxy.Port = Port; proxy.Priorite = Priorite; proxy.FrequencePollingMinutes = FrequencePollingMinutes; return(proxy); }
//--------------------------------------------- /// ///////////////////////////////////////////// public CAgentSnmpPourSupervision GetAgentPourSupervision(CMemoryDb database, bool bAvecEntites) { if (database == null) { database = CMemoryDbPourSupervision.GetMemoryDb(ContexteDonnee); } CAgentSnmpPourSupervision agent = new CAgentSnmpPourSupervision(database); if (!agent.ReadIfExist(Id.ToString(), false)) { agent.CreateNew(Id.ToString()); } else if (!agent.IsToRead()) { return(agent); } agent.Row[CMemoryDb.c_champIsToRead] = false; CTypeAgentPourSupervision typeAgent = TypeAgent.GetTypeAgentPourSupervision(database); agent.TypeAgent = typeAgent; agent.Ip = SnmpIp; agent.Timeout = Timeout; agent.SnmpPort = SnmpPort; agent.SnmpVersion = SnmpVersion; agent.Communaute = SnmpCommunaute; agent.TrapsIpString = TrapsIpsString; foreach (CSnmpPollingSetup setup in ParametresPolling) { CSnmpPollingSetup newSetup = database.ImporteObjet(setup, true, false) as CSnmpPollingSetup; newSetup.Agent = agent; } foreach (CSnmpHotelPollingSetup setup in ParametresHotelPolling) { CSnmpHotelPollingSetup newSetup = database.ImporteObjet(setup, true, false) as CSnmpHotelPollingSetup; newSetup.Agent = agent; } if (bAvecEntites) { foreach (CEntiteSnmp entite in EntitesSnmp) { if (entite.EntiteSnmpParente == null) { CTypeEntiteSnmpPourSupervision typeEntite = typeAgent.TypesEntites.FirstOrDefault(te => te.Id == entite.TypeEntiteSnmp.Id.ToString()); if (typeEntite != null) { CEntiteSnmpPourSupervision ett = entite.GetEntitePourSupervision(typeEntite); if (ett != null) { ett.AgentSnmp = agent; } } } } } return(agent); }
/// ///////////////////////////////////////////// public CResultAErreur InitEntitesFromSnmpInContexteCourant() { CResultAErreur result = CResultAErreur.True; CMemoryDb database = CMemoryDbPourSupervision.GetMemoryDb(ContexteDonnee); CAgentSnmpPourSupervision agent = GetAgentPourSupervision(database, false); if (agent != null) { result = agent.FillFromSNMP(new CInterrogateurSnmp()); if (result) { result = MapEntitesFromSNMP(agent); } } if (result) { LastUpdateDateFromSNMP = DateTime.Now; } return(result); }
/// ///////////////////////////////////////////////////////// public CTypeAgentPourSupervision GetTypeAgentPourSupervision(CMemoryDb database) { if (database == null) { database = CMemoryDbPourSupervision.GetMemoryDb(ContexteDonnee); } CTypeAgentPourSupervision typeAgent = new CTypeAgentPourSupervision(database); if (!typeAgent.ReadIfExist(Id.ToString(), false)) { typeAgent.CreateNew(Id.ToString()); } else if (!typeAgent.IsToRead()) { return(typeAgent); } typeAgent.Row[CMemoryDb.c_champIsToRead] = false; foreach (CEasyQuery query in Queries) { typeAgent.AddQuery(query); } typeAgent.Fonctions = FonctionsDynamiques; foreach (CTrapHandler handler in TrapHandlers) { database.ImporteObjet(handler, true, false); } foreach (CTypeEntiteSnmp typeEntite in TypesEntites) { if (typeEntite.TypeParent == null) { typeEntite.GetTypeEntitePourSupervision(database, true); } } foreach (CAgentFinderFromKey finder in AgentFinders) { database.ImporteObjet(finder, true, false); } return(typeAgent); }
//---------------------------------------------------------------------------------------------------- public IDonneeSynchronisationMediation GetUpdatesForProxy(int nIdProxy, int nIdLastSyncSession) { using (CSessionClient session = CSessionClient.CreateInstance()) { CResultAErreur result = session.OpenSession(new CAuthentificationSessionProcess()); if (!result) { return(null); } using (CContexteDonneesSynchro ctx = new CContexteDonneesSynchro(session.IdSession, true)) { CSc2iDataServer connexionManager = CSc2iDataServer.GetInstance(); IDatabaseConnexionSynchronisable cnxSync = connexionManager.GetDatabaseConnexion(session.IdSession, typeof(CTypeAgentSnmpServeur)) as IDatabaseConnexionSynchronisable; if (cnxSync == null) { return(null); } cnxSync.IncrementeSyncSession(); int nIdSyncMax = cnxSync.IdSyncSession - 1; CFiltresSynchronisation filtres = new CFiltresSynchronisation(); filtres.AddFiltreForTable(CTypeAlarme.c_nomTable, null, false); filtres.AddFiltreForTable(CSeveriteAlarme.c_nomTable, null, false); filtres.AddFiltreForTable(CTypeAgentSnmp.c_nomTable, null, false); filtres.AddFiltreForTable(CAgentSnmp.c_nomTable, new CFiltreData(CSnmpProxyInDb.c_champId + "=@1", nIdProxy) , false); filtres.AddFiltreForTable(CTypeEntiteSnmp.c_nomTable, null, false); filtres.AddFiltreForTable(CEntiteSnmp.c_nomTable, new CFiltreDataAvance( CEntiteSnmp.c_nomTable, CAgentSnmp.c_nomTable + "." + CSnmpProxyInDb.c_champId + "=@1", nIdProxy), false); filtres.AddFiltreForTable(CRelationTypeEntiteSnmp_ChampCustom.c_nomTable, null, false); filtres.AddFiltreForTable(CRelationEntiteSnmp_ChampCustom.c_nomTable, new CFiltreDataAvance(CRelationEntiteSnmp_ChampCustom.c_nomTable, CEntiteSnmp.c_nomTable + "." + CAgentSnmp.c_nomTable + "." + CSnmpProxyInDb.c_champId + "=@1", nIdProxy), false); // Prend uniquement les Filtrages d'alarme compris entre les dates de validité et marqués Enabled filtres.AddFiltreForTable(CParametrageFiltrageAlarmes.c_nomTable, new CFiltreData( CParametrageFiltrageAlarmes.c_champIsActif + " = @1 AND " + CParametrageFiltrageAlarmes.c_champDateDebutValidite + " <= @2 AND " + CParametrageFiltrageAlarmes.c_champDateFinValidite + " > @2", true, DateTime.Now.Date), false); filtres.AddFiltreForTable(CCategorieMasquageAlarme.c_nomTable, null, false); DateTime dt = DateTime.Now; // Créer le MemoryDB bool bHasData = false; result = ctx.FillWithModifsFromVersion(nIdLastSyncSession, nIdSyncMax, ref bHasData, filtres, true); if (!result) { return(null); } TimeSpan sp = DateTime.Now - dt; Console.WriteLine("Lecture modifs médiation : " + sp.TotalMilliseconds); dt = DateTime.Now; CDonneesSynchronisationMediation donneesSynchro = new CDonneesSynchronisationMediation( CMemoryDbPourSupervision.GetMemoryDb(ctx), nIdSyncMax); CListeObjetsDonnees lstObjets = new CListeObjetsDonnees(ctx, typeof(CSeveriteAlarme)); lstObjets.InterditLectureInDB = true; foreach (CSeveriteAlarme severite in lstObjets) { severite.GetTypeForSupervision(donneesSynchro.Database); } lstObjets = new CListeObjetsDonnees(ctx, typeof(CTypeAlarme)); lstObjets.InterditLectureInDB = true; foreach (CTypeAlarme type in lstObjets) { type.GetTypeForSupervision(donneesSynchro.Database, true); } lstObjets = new CListeObjetsDonnees(ctx, typeof(CTypeAgentSnmp)); lstObjets.InterditLectureInDB = true; lstObjets.ReadDependances("TypesEntites"); foreach (CTypeAgentSnmp type in lstObjets) { type.GetTypeAgentPourSupervision(donneesSynchro.Database); } lstObjets = new CListeObjetsDonnees(ctx, typeof(CAgentSnmp)); lstObjets.InterditLectureInDB = true; lstObjets.ReadDependances("EntitesSnmp", "EntitesSnmp.RelationsChampsCustom", "EntitesSnmp.SiteSupervise", "EntitesSnmp.EquipementLogiqueSupervise", "EntitesSnmp.EquipementLogiqueSupervise.Site", "EntitesSnmp.LienReseauSupervise"); foreach (CAgentSnmp agent in lstObjets) { agent.GetAgentPourSupervision(donneesSynchro.Database, true); } lstObjets = new CListeObjetsDonnees(ctx, typeof(CParametrageFiltrageAlarmes)); lstObjets.InterditLectureInDB = true; foreach (CParametrageFiltrageAlarmes parametreFiltre in lstObjets) { parametreFiltre.GetLocalParametrageForSupervision(donneesSynchro.Database); } lstObjets = new CListeObjetsDonnees(ctx, typeof(CCategorieMasquageAlarme)); lstObjets.InterditLectureInDB = true; foreach (CCategorieMasquageAlarme categorie in lstObjets) { categorie.GetLocalCategorieForSupervision(donneesSynchro.Database); } //S'assure que les entités des valeurs de champ entité sont chargés lstObjets = new CListeObjetsDonnees(ctx, typeof(CRelationEntiteSnmp_ChampCustom)); lstObjets.InterditLectureInDB = true; foreach (CRelationEntiteSnmp_ChampCustom rel in lstObjets) { if (rel != null && rel.ElementAChamps != null) { ((CObjetDonnee)rel.ElementAChamps).AssureData(); } } lstObjets = new CListeObjetsDonnees(ctx, typeof(CEntiteSnmp)); lstObjets.InterditLectureInDB = true; foreach (CEntiteSnmp entite in lstObjets) { CTypeEntiteSnmp typeEntite = entite.TypeEntiteSnmp; futurocom.snmp.entitesnmp.CTypeEntiteSnmpPourSupervision te = typeEntite.GetTypeEntitePourSupervision(donneesSynchro.Database, true); entite.GetEntitePourSupervision(te); } sp = DateTime.Now - dt; Console.WriteLine("Intégration modifs médiation : " + sp.TotalMilliseconds); return(donneesSynchro); } } }