Exemple #1
0
 //-------------------------------------------------------
 public void InitControle(CAgentSnmpPourSupervision agent,
                          ITypeDonneeCumulee typeDonneeCumulee)
 {
     m_agent             = agent;
     m_typeDonneeCumulee = typeDonneeCumulee;
     m_txtFormule.Init(new CFournisseurGeneriqueProprietesDynamiques(), new CObjetPourSousProprietes(m_agent));
 }
Exemple #2
0
        //------------------------------------------------------------
        public CResultAErreur GetValue(object objet, string strPropriete)
        {
            CResultAErreur            result = CResultAErreur.True;
            CAgentSnmpPourSupervision agent  = objet as CAgentSnmpPourSupervision;

            if (agent == null)
            {
                return(result);
            }
            string strOID = strPropriete.Replace("_", ".");

            if (agent.HasCacheOID)
            {
                result.Data = agent.GetValeurSNMPEnCache(strOID);
            }
            else
            {
                result.Data = agent.ReadSnmpString(strOID);
            }
            if (result.Data != null && result.Data is ISnmpData)
            {
                result.Data = ((ISnmpData)result.Data).ConvertToTypeDotNet();
            }
            return(result);
        }
Exemple #3
0
        //---------------------------------------------

        /// /////////////////////////////////////////////
        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);
        }
Exemple #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            CAgentSnmpPourSupervision agent = new CAgentSnmpPourSupervision();

            agent.TypeAgent   = m_baseHandlers;
            agent.Ip          = "172.16.1.200";
            agent.SnmpVersion = VersionCode.V1;
            agent.SnmpPort    = 161;
            agent.Communaute  = "public";
            agent.FillFromSNMP(m_baseHandlers.AgentAssocie);
        }
 //--------------------------------------------------
 public void Init(CSnmpHotelPollingSetup pollingSetup,
                  CAgentSnmpPourSupervision agent)
 {
     m_agent                      = agent;
     m_setup                      = pollingSetup;
     m_txtLibelle.Text            = pollingSetup.Libelle;
     m_txtFrequence.UnitValue     = new CValeurUnite(m_setup.FrequenceMinutes, CClasseUniteTemps.c_idMIN);
     m_txtIP.Text                 = pollingSetup.HotelIp;
     m_txtNumPort.IntValue        = pollingSetup.HotelPort;
     m_extModeEdition.ModeEdition = !pollingSetup.Id.StartsWith(CSnmpHotelPollingSetup.c_IdPollingSystem);
     m_controleItem.LockEdition   = !m_extModeEdition.ModeEdition;
     FillListeChamps();
 }
Exemple #6
0
 public static bool EditeSetup(CSnmpHotelPollingSetup setup,
                               CAgentSnmpPourSupervision agent)
 {
     using (CFormEditeHotelPollingSetup frm = new CFormEditeHotelPollingSetup())
     {
         frm.m_panelSetup.Init(
             setup,
             agent);
         if (frm.ShowDialog() == DialogResult.OK)
         {
             return(true);
         }
         return(false);
     }
 }
Exemple #7
0
 public static bool EditeSetup(CSnmpPollingSetup setup,
                               CAgentSnmpPourSupervision agent,
                               IEnumerable <ITypeDonneeCumulee> lstTypesDonnees)
 {
     using (CFormEditePollingSetup frm = new CFormEditePollingSetup())
     {
         frm.m_panelSetup.Init(setup,
                               agent,
                               lstTypesDonnees);
         if (frm.ShowDialog() == DialogResult.OK)
         {
             return(true);
         }
         return(false);
     }
 }
Exemple #8
0
        //--------------------------------------------------
        public void Init(CSnmpPollingSetup pollingSetup,
                         CAgentSnmpPourSupervision agent,
                         IEnumerable <ITypeDonneeCumulee> lstTypesDonneesCumulees)
        {
            m_agent = agent;
            m_listeTypesDonneesCumulees = lstTypesDonneesCumulees;
            m_setup                             = pollingSetup;
            m_txtLibelle.Text                   = pollingSetup.Libelle;
            m_txtFrequence.UnitValue            = new CValeurUnite(m_setup.FrequenceMinutes, CClasseUniteTemps.c_idMIN);
            m_cmbTypesDonnees.ListDonnees       = lstTypesDonneesCumulees;
            m_cmbTypesDonnees.ProprieteAffichee = "Libelle";
            ITypeDonneeCumulee tp = lstTypesDonneesCumulees.FirstOrDefault(t => t.Id == pollingSetup.IdTypeDonneeCumulee);

            m_cmbTypesDonnees.SelectedValue = tp;

            FillListeChamps();
        }
Exemple #9
0
 /// <summary>
 /// Retourne true si une clé de l'agent correspond au finder
 /// </summary>
 /// <param name="agent"></param>
 /// <returns></returns>
 public bool MatchAgent(CTrapInstance trap, CAgentSnmpPourSupervision agent)
 {
     if (FormuleCleSpecifique != null)
     {
         CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(trap);
         CResultAErreur result             = FormuleCleSpecifique.Eval(ctx);
         if (!result || result.Data == null)
         {
             return(false);
         }
         if (agent.TrapsIpString.Contains("," + result.Data.ToString() + ","))
         {
             return(true);
         }
     }
     return(false);
 }
        //----------------------------------------------------------------------
        internal CResultAErreur DoPoll(
            CDataHotelClient client,
            CAgentSnmpPourSupervision agent)
        {
            CResultAErreur result = CResultAErreur.True;

            if (m_formulePolling != null)
            {
                try
                {
                    CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(agent);
                    result = m_formulePolling.Eval(ctx);
                    if (!result || result.Data == null)
                    {
                        result.EmpileErreur("Error while polling " + HotelTable + "." + HotelField);
                        return(result);
                    }
                    double?fVal = result.Data as double?;
                    if (fVal == null)
                    {
                        fVal = result.Data as Int32?;
                        if (fVal == null)
                        {
                            fVal = Convert.ToDouble(result.Data);
                        }
                    }
                    if (fVal != null)
                    {
                        client.GetRoomServer().SendData(
                            HotelTable,
                            HotelField,
                            EntityId,
                            DateTime.Now,
                            fVal.Value);
                    }
                }
                catch (Exception e)
                {
                    result.EmpileErreur(new CErreurException(e));
                    result.EmpileErreur("Error while polling " + HotelTable + "." + HotelField);
                    return(result);
                }
            }
            return(result);
        }
Exemple #11
0
        /// /////////////////////////////////////////////
        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 void DoPoll()
        {
            //Vérifie la connexion à l'hotel
            CDataHotelClient client = new CDataHotelClient(HotelIp, HotelPort);

            if (client.SafePing())
            {
                //Extrait tous les OID à lire
                HashSet <string> strOids = new HashSet <string>();
                foreach (CSnmpHotelPolledData data in PolledDatas)
                {
                    data.ExtractOids(strOids);
                }
                IList <Variable>            lstVars    = Agent.ReadSnmp(strOids.ToArray());
                Dictionary <string, object> dicValeurs = new Dictionary <string, object>();
                foreach (Variable v in lstVars)
                {
                    string strOID = v.Id.ToString();
                    dicValeurs[strOID] = v.Data;
                }

                try
                {
                    CAgentSnmpPourSupervision agent = Agent;
                    agent.SetCacheOID(dicValeurs);

                    //C'est parti
                    foreach (CSnmpHotelPolledData data in PolledDatas)
                    {
                        data.DoPoll(client, agent);
                    }
                }
                finally
                {
                    Agent.SetCacheOID(null);
                }
            }
        }
Exemple #13
0
 //--------------------------------------------------------------------
 public void UpdateAgentIpFromMediation(string strAgentId, string strNewIp, bool bUpdateTimosDb)
 {
     if (m_traiteurAlarme != null)
     {
         m_traiteurAlarme.UpdateAgentIpFromMediation(strAgentId, strNewIp, bUpdateTimosDb);
     }
     else
     {
         CServiceMediation service = CServiceMediation.GetDefaultInstance();
         if (service != null && service.Configuration != null && service.Configuration.DataBase != null)
         {
             CAgentSnmpPourSupervision agent = service.Configuration.DataBase.GetEntite <CAgentSnmpPourSupervision>(strAgentId);
             if (agent != null)
             {
                 agent.Ip = strNewIp;
             }
         }
         foreach (CSnmpProxy proxy in CSnmpProxyConfiguration.GetInstance().GetProxiesPrecedents())
         {
             ISnmpConnexion cnx = proxy.GetConnexion();
             cnx.UpdateAgentIpFromMediation(strAgentId, strNewIp, bUpdateTimosDb);
         }
     }
 }
Exemple #14
0
        /// /////////////////////////////////////////////
        private CResultAErreur MapEntitesFromSNMP(CAgentSnmpPourSupervision agent)
        {
            CResultAErreur      result      = CResultAErreur.True;
            HashSet <int>       entitesVues = new HashSet <int>();
            CListeObjetsDonnees lstEntites  = EntitesSnmp;

            foreach (CEntiteSnmpPourSupervision entiteFromSnmp in agent.Entites)
            {
                CEntiteSnmp entite = new CEntiteSnmp(ContexteDonnee);
                lstEntites.Filtre = new CFiltreData(CEntiteSnmp.c_champIndex + "=@1 and " +
                                                    CTypeEntiteSnmp.c_champId + "=@2",
                                                    entiteFromSnmp.Index,
                                                    entiteFromSnmp.TypeEntite.Id);
                if (lstEntites.Count == 0)
                {
                    entite = new CEntiteSnmp(ContexteDonnee);
                    entite.CreateNewInCurrentContexte();
                    entite.AgentSnmp = this;
                }
                else
                {
                    entite = lstEntites[0] as CEntiteSnmp;
                }
                result = entite.FillFromSnmp(entiteFromSnmp);
                if (!result)
                {
                    return(result);
                }
                entitesVues.Add(entite.Id);
            }
            foreach (CEntiteSnmp entite in EntitesSnmp)
            {
                entite.IsFromSnmp = entitesVues.Contains(entite.Id);
            }
            return(result);
        }
Exemple #15
0
        //-----------------------------------------------
        public static CTrapInstance FromMessage(
            ISnmpMessage message,
            CAgentSnmpPourSupervision agentPourSupervision)
        {
            TrapV1Message        trapV1 = message as TrapV1Message;
            TrapV2Message        trapV2 = message as TrapV2Message;
            InformRequestMessage inform = message as InformRequestMessage;

            if (trapV1 != null)
            {
                CInterrogateurSnmp agent = new CInterrogateurSnmp();
                agent.ConnexionIp        = trapV1.AgentAddress.ToString();
                agent.Connexion.Version  = trapV1.Version;
                agent.ConnexionCommunity = trapV1.Community.ToString();
                agent.ConnexionPort      = 161;
                if (agentPourSupervision != null && agentPourSupervision.TypeAgent != null)
                {
                    agentPourSupervision.TypeAgent.PrepareDynamicSnmpAgent(agent);
                }

                CTrapInstance instance = new CTrapInstance(agent);
                instance.m_strEntreprise = trapV1.Enterprise.ToString();
                instance.m_version       = trapV1.Version;
                instance.m_strAgentIP    = trapV1.AgentAddress.ToString();
                instance.m_strCommunity  = trapV1.Community.ToString();
                instance.GenericCode     = trapV1.Generic;
                instance.SpecificValue   = trapV1.Specific.ToString();
                instance.AgentSnmp       = agentPourSupervision;
                foreach (Variable variable in trapV1.Variables())
                {
                    CTrapFieldValueBrute valeur = new CTrapFieldValueBrute(variable.Id.ToString(), variable.Data.ToString());
                    instance.AddValue(valeur);
                }
                return(instance);
            }
            else if (trapV2 != null)
            {
                CInterrogateurSnmp agent = new CInterrogateurSnmp();
                if (trapV2.SenderIP == null)
                {
                    return(null);
                }
                agent.ConnexionIp       = trapV2.SenderIP.ToString();
                agent.Connexion.Version = trapV2.Version;
                string strCommunauté = "";
                if (trapV2.Parameters != null)
                {
                    if (trapV2.Parameters.UserName != null)
                    {
                        strCommunauté = trapV2.Parameters.UserName.ToString();
                    }
                }
                agent.ConnexionCommunity = strCommunauté;
                agent.ConnexionPort      = 161;
                if (agentPourSupervision != null && agentPourSupervision.TypeAgent != null)
                {
                    agentPourSupervision.TypeAgent.PrepareDynamicSnmpAgent(agent);
                }

                CTrapInstance instance = new CTrapInstance(agent);
                instance.m_strEntreprise = trapV2.Enterprise.ToString();
                instance.m_strAgentIP    = trapV2.SenderIP.ToString();
                instance.m_version       = trapV2.Version;
                instance.m_strCommunity  = strCommunauté;
                if (trapV2.Enterprise.ToString() == ".1.3.6.1.6.3.1.1.5.1")
                {
                    instance.GenericCode = GenericCode.ColdStart;
                }
                else if (trapV2.Enterprise.ToString() == ".1.3.6.1.6.3.1.1.5.2")
                {
                    instance.GenericCode = GenericCode.WarmStart;
                }
                else if (trapV2.Enterprise.ToString() == ".1.3.6.1.6.3.1.1.5.3")
                {
                    instance.GenericCode = GenericCode.LinkDown;
                }
                else if (trapV2.Enterprise.ToString() == ".1.3.6.1.6.3.1.1.5.4")
                {
                    instance.GenericCode = GenericCode.LinkUp;
                }
                else if (trapV2.Enterprise.ToString() == ".1.3.6.1.6.3.1.1.5.5")
                {
                    instance.GenericCode = GenericCode.AuthenticationFailure;
                }
                else if (trapV2.Enterprise.ToString() == ".1.3.6.1.6.3.1.1.5.6")
                {
                    instance.GenericCode = GenericCode.EgpNeighborLoss;
                }
                else
                {
                    instance.GenericCode = GenericCode.EnterpriseSpecific;
                    int nPos = instance.m_strEntreprise.LastIndexOf(".");
                    if (nPos >= 0)
                    {
                        instance.m_strSpecific   = instance.m_strEntreprise.Substring(nPos + 1);
                        instance.m_strEntreprise = instance.m_strEntreprise.Substring(0, nPos);
                    }
                }
                instance.AgentSnmp = agentPourSupervision;
                foreach (Variable variable in trapV2.Variables())
                {
                    CTrapFieldValueBrute valeur = new CTrapFieldValueBrute(variable.Id.ToString(), variable.Data.ToString());
                    instance.AddValue(valeur);
                }
                return(instance);
            }
            return(null);
        }
 public void Init(CAgentSnmpPourSupervision agent)
 {
     m_agent = agent;
     InitChamps();
 }
Exemple #17
0
 public CDefinitionProprieteDynamiqueAgentSnmp(CAgentSnmpPourSupervision agentSnmp)
     : base("SnmpAgent", "SnmpAgent", agentSnmp, "")
 {
 }