Exemple #1
0
        //-------------------------------------------------------------------------------
        private CColumnDefinitionSNMP GetSourceColumn(int nIdChampCustom)
        {
            if (TypeEntiteSnmp == null)
            {
                return(null);
            }
            CChampEntiteFromQueryToChampCustom field = TypeEntiteSnmp.ChampsFromQuery.FirstOrDefault(c => c.IdChampCustom != null &&
                                                                                                     c.IdChampCustom == nIdChampCustom);

            if (field != null)
            {
                return(GetSourceColumn(TypeEntiteSnmp.FindSourceObjetInQuery().DataType, field));
            }
            return(null);
        }
Exemple #2
0
        //-------------------------------------------------------------------------------
        public CResultAErreurType <string> GetFieldOIDWithEntitePourSupervision(int nIdChampCustom, CEntiteSnmpPourSupervision ettPourSup)
        {
            CResultAErreurType <string> resString = new CResultAErreurType <string>();
            CColumnDefinitionSNMP       colSnmp   = GetSourceColumn(nIdChampCustom);

            if (colSnmp == null)
            {
                CChampCustom champ    = new CChampCustom(ContexteDonnee);
                string       strChamp = nIdChampCustom.ToString();
                if (champ.ReadIfExists(nIdChampCustom))
                {
                    strChamp = champ.Nom;
                }
                resString.EmpileErreur(I.T("Can not find snmp source for @1|20099", strChamp));
                return(resString);
            }

            IEnumerable <CChampEntiteFromQueryToChampCustom> lstChamps = TypeEntiteSnmp.ChampsFromQuery;
            CChampEntiteFromQueryToChampCustom assocChamp = lstChamps.FirstOrDefault(c => c.IdChampCustom == nIdChampCustom);
            string strOID   = colSnmp.OIDString;
            string strIndex = Index;

            if (assocChamp != null && assocChamp.Champ.FormuleIndex != null)
            {
                if (ettPourSup == null)
                {
                    ettPourSup = GetEntitePourSupervision(TypeEntiteSnmp.GetTypeEntitePourSupervision(null, false));
                }
                CContexteEvaluationExpression ctxEval = new CContexteEvaluationExpression(ettPourSup);
                CResultAErreur resTmp = assocChamp.Champ.FormuleIndex.Eval(ctxEval);
                if (resTmp && resTmp.Data != null)
                {
                    strIndex = resTmp.Data.ToString();
                }
            }
            if (strIndex.Length > 0)
            {
                if (!strIndex.StartsWith("."))
                {
                    strOID += ".";
                }
                strOID += strIndex;
            }
            resString.DataType = strOID;
            return(resString);
        }
Exemple #3
0
        //-------------------------------------------------------------------------------
        private CColumnDefinitionSNMP GetSourceColumn(
            IObjetDeEasyQuery objetDeQuery,
            CChampEntiteFromQueryToChampCustom champ)
        {
            if (objetDeQuery == null || objetDeQuery.Query == null)
            {
                return(null);
            }

            ITableDefinition  table = null;
            IColumnDefinition col   = null;

            if (objetDeQuery.Query.FindSource(champ.Champ.ColonneSource, objetDeQuery,
                                              out table,
                                              out col))
            {
                return(col as CColumnDefinitionSNMP);
            }
            return(null);
        }
Exemple #4
0
        public bool SetSnmpValueForField(int nIdChampCustom, object value)
        {
            ITableDefinition  table = null;
            IColumnDefinition col   = null;

            CResultAErreurType <IObjetDeEasyQuery> resObj = TypeEntiteSnmp.FindSourceObjetInQuery();

            if (!resObj || resObj.DataType == null)
            {
                return(false);
            }

            IObjetDeEasyQuery objetSource = resObj.DataType;
            CEasyQuery        query       = objetSource.Query;
            IEnumerable <CChampEntiteFromQueryToChampCustom> lstChamps = TypeEntiteSnmp.ChampsFromQuery;
            CChampEntiteFromQueryToChampCustom champ = null;

            foreach (CChampEntiteFromQueryToChampCustom champTest in lstChamps)
            {
                if (champTest.IdChampCustom != null &&
                    champTest.IdChampCustom == nIdChampCustom)
                {
                    champ = champTest;
                    break;
                }
            }
            if (champ == null)
            {
                return(false);
            }

            if (query.FindSource(champ.Champ.ColonneSource, objetSource,
                                 out table,
                                 out col))
            {
                CEntiteSnmpPourSupervision ettPourSup = null;
                CColumnDefinitionSNMP      colSnmp    = col as CColumnDefinitionSNMP;

                if (colSnmp != null && !colSnmp.IsReadOnly)
                {
                    ISnmpData snmpVal = AbstractTypeAssignment.GetSnmpFromDotNet(colSnmp.SnmpType, value);
                    if (snmpVal == null && value != null)
                    {
                        snmpVal = new OctetString(value.ToString());
                    }
                    if (snmpVal != null)
                    {
                        string strIndex = Index;
                        if (champ.Champ.FormuleIndex != null)
                        {
                            if (ettPourSup == null)
                            {
                                ettPourSup = GetEntitePourSupervision(TypeEntiteSnmp.GetTypeEntitePourSupervision(null, false));
                            }
                            CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(ettPourSup);
                            CResultAErreur restTmp            = champ.Champ.FormuleIndex.Eval(ctx);
                            if (restTmp && restTmp.Data != null)
                            {
                                strIndex = restTmp.Data.ToString();
                            }
                        }
                        if (!strIndex.StartsWith("."))
                        {
                            strIndex = "." + strIndex;
                        }
                        try
                        {
                            CInterrogateurSnmp agent = new CInterrogateurSnmp();
                            agent.Connexion.Version  = AgentSnmp.SnmpVersion;
                            agent.ConnexionIp        = AgentSnmp.SnmpIp;
                            agent.ConnexionPort      = AgentSnmp.SnmpPort;
                            agent.ConnexionCommunity = AgentSnmp.SnmpCommunaute;
                            CResultAErreur resTmp = agent.Set(colSnmp.OIDString + strIndex, snmpVal);
                            if (resTmp)
                            {
                                return(true);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            return(false);
        }