예제 #1
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);
        }
예제 #2
0
 //-----------------------------------------------
 public void AddValue(CTrapFieldValueBrute value)
 {
     m_listeValues.Add(value);
 }