Ejemplo n.º 1
0
        /// <summary>
        /// Le data du result contient un CRequeteSNMPOID
        /// </summary>
        /// <param name="contexte"></param>
        /// <returns></returns>
        public virtual CResultAErreur GetRequeteSNMPOID(CContexteDonnee contexte)
        {
            CResultAErreur  result     = CResultAErreur.True;
            CRequeteSnmpOID requeteOID = new CRequeteSnmpOID();

            requeteOID.IpAgent   = IpAgent;
            requeteOID.Community = Community;
            requeteOID.OID       = GetOID(contexte);
            if (requeteOID.OID.Length == 0)
            {
                result.EmpileErreur(I.T("Can not find OID for SNMP object @1|30001", GetDescriptionVariableSNMP()));
                return(result);
            }
            requeteOID.Type = GetType(contexte);
            if (requeteOID.Type.Length == 0)
            {
                result.EmpileErreur(I.T("Can not find Type for SNMP object @1|30002", GetDescriptionVariableSNMP()));
                return(result);
            }
            requeteOID.TimeOut     = TimeOut;
            requeteOID.NbRetry     = NbRetry;
            requeteOID.VersionSNMP = VersionSNMP;
            requeteOID.Port        = Port;
            result.Data            = requeteOID;
            return(result);
        }
Ejemplo n.º 2
0
        public static bool RefreshFromSNMP(object obj)
        {
            CEquipementLogique eqpt = obj as CEquipementLogique;

            if (eqpt == null)
            {
                return(false);
            }
            CSpvEquip eqptSpv = CSpvEquip.GetObjetSpvFromObjetTimos(eqpt);

            if (eqptSpv == null)
            {
                return(false);
            }
            string strIP         = eqptSpv.AdresseIP;
            string strCommunaute = eqptSpv.CommunauteSnmp;

            CChampCustom[] lstChamps           = eqpt.TousLesChamps;
            string         strOldContexteModif = eqpt.ContexteDonnee.IdModificationContextuelle;;

            eqpt.ContexteDonnee.IdModificationContextuelle = CSpvChampCustomSNMP.c_contexteModificationRefreshFromSNMP;
            IRequeteSNMPServeur requeteurServeur = C2iFactory.GetNewObjetForSession("CRequeteSNMPServeur", typeof(IRequeteSNMPServeur), eqpt.ContexteDonnee.IdSession) as IRequeteSNMPServeur;

            foreach (CChampCustom champ in lstChamps)
            {
                CSpvChampCustomSNMP champSNMP = CSpvChampCustomSNMP.GetObjetSpvFromObjetTimos(champ);
                if (champSNMP != null && champSNMP.OID != null && champSNMP.OID.Length > 0 &&
                    champSNMP.FormuleIndex != null)
                {
                    CContexteEvaluationExpression ctxFormule = new CContexteEvaluationExpression(eqpt);
                    CResultAErreur result = champSNMP.FormuleIndex.Eval(ctxFormule);
                    if (result)
                    {
                        try
                        {
                            int             nIndex  = Convert.ToInt32(result.Data);
                            string          strOid  = champSNMP.OID + "." + nIndex.ToString();
                            CRequeteSnmpOID requete = new CRequeteSnmpOID(strIP, strCommunaute, strOid);
                            result = requeteurServeur.GetValue(requete);
                            if (result)
                            {
                                eqpt.SetValeurChamp(champ, result.Data);
                            }
                        }
                        catch {}
                    }
                }
            }
            eqpt.ContexteDonnee.IdModificationContextuelle = strOldContexteModif;
            return(true);
        }
Ejemplo n.º 3
0
        public CResultAErreur SetValueSNMP(CContexteDonnee contexte, object valeur)
        {
            CResultAErreur      result           = CResultAErreur.True;
            IRequeteSNMPServeur requeteurServeur = C2iFactory.GetNewObjetForSession("CRequeteSNMPServeur", typeof(IRequeteSNMPServeur), contexte.IdSession) as IRequeteSNMPServeur;

            if (requeteurServeur == null)
            {
                result.EmpileErreur(I.T("Can not instanciate SNMP Query server|20001"));
                return(result);
            }
            result = GetRequeteSNMPOID(contexte);
            if (!result)
            {
                return(result);
            }
            CRequeteSnmpOID requeteOID = result.Data as CRequeteSnmpOID;

            if (requeteOID == null)
            {
                result.EmpileErreur(I.T("Error while creating OID SNMP QUERY|20005"));
                return(result);
            }
            return(requeteurServeur.SetValue(requeteOID, valeur));
        }