public override void Walk(IDefinition definition)
        {
            IList <Variable> list = new List <Variable>();

            if (VersionCode == VersionCode.V1)
            {
                Messenger.Walk(
                    VersionCode,
                    Agent,
                    GetCommunity,
                    new ObjectIdentifier(definition.GetNumericalForm()),
                    list,
                    Timeout,
                    WalkMode.WithinSubtree);
            }
            else
            {
                Messenger.BulkWalk(
                    VersionCode,
                    Agent,
                    GetCommunity,
                    new ObjectIdentifier(definition.GetNumericalForm()),
                    list,
                    Timeout,
                    10,
                    WalkMode.WithinSubtree,
                    null,
                    null);
            }

            foreach (Variable v in list)
            {
                Logger.Info(v.ToString(Objects));
            }
        }
Beispiel #2
0
        private void RefreshTable()
        {
            // TODO: how to get rid of infinite loop?
            // will use WatchDog class to optimize this.
            while (true)
            {
                IProfileRegistry registry = Program.Container.Resolve <IProfileRegistry>();
                if (registry == null)
                {
                    break;
                }

                IList <Variable> list = new List <Variable>();
                Thread.Sleep(Convert.ToInt32(textBoxRefresh.Text, CultureInfo.CurrentCulture) * 1000);
                NormalAgentProfile prof = registry.DefaultProfile as NormalAgentProfile;
                int rows;
                if (prof != null)
                {
                    rows = Messenger.Walk(
                        prof.VersionCode,
                        prof.Agent,
                        prof.GetCommunity,
                        new ObjectIdentifier(_definition.GetNumericalForm()),
                        list,
                        prof.Timeout,
                        WalkMode.WithinSubtree);
                }
                else
                {
                    SecureAgentProfile p         = (SecureAgentProfile)registry.DefaultProfile;
                    Discovery          discovery = Messenger.GetNextDiscovery(SnmpType.GetBulkRequestPdu);
                    ReportMessage      report    = discovery.GetResponse(p.Timeout, p.Agent);
                    rows = Messenger.BulkWalk(
                        VersionCode.V3,
                        p.Agent,
                        new OctetString(p.UserName),
                        new ObjectIdentifier(_definition.GetNumericalForm()),
                        list,
                        p.Timeout,
                        10,
                        WalkMode.WithinSubtree,
                        p.Privacy,
                        report);
                }

                SetRows(rows);
                PopulateGrid(list);
            }
        }
Beispiel #3
0
        //-------------------------------------------------------
        private void m_menuWalk_Click(object sender, EventArgs e)
        {
            IDefinition definition = GetCurrent();

            if (definition != null)
            {
                if (m_connexion == null)
                {
                    if (!SetupConnexion())
                    {
                        return;
                    }
                }
                CResultAErreurType <IList <Variable> > result = m_connexion.Walk(definition.GetNumericalForm());
                if (!result)
                {
                    CFormAfficheErreur.Show(result.Erreur);
                }
                else
                {
                    CFormViewSNMPResult.ViewResult("Walk " + definition.Name,
                                                   result.DataType,
                                                   this,
                                                   definition.Tree);
                }
            }
        }
Beispiel #4
0
        //------------------------------------
        public void DisplayElement(IDefinition definition)
        {
            m_definition = definition;
            NotificationType notificationType = definition.Entity as NotificationType;

            m_exLinkField.FillDialogFromObjet(notificationType);

            //Ajoute les \r à la description
            string strDesc = definition.Description;

            if (!strDesc.Contains("\r"))
            {
                strDesc = strDesc.Replace("\n", "\r\n");
            }
            m_lblDescription.Text = strDesc;

            //Récupère l'OID
            m_lblOID.Text = ObjectIdentifier.Convert(definition.GetNumericalForm());



            m_wndListeObjects.Items.Clear();
            foreach (string strObject in notificationType.Objects)
            {
                m_wndListeObjects.Items.Add(strObject);
            }
        }
        public override void Walk(IDefinition definition)
        {
            if (string.IsNullOrEmpty(UserName))
            {
                Logger.Info("User name need to be specified for v3.");
                return;
            }

            Discovery        discovery = Messenger.NextDiscovery;
            ReportMessage    report    = discovery.GetResponse(Timeout, Agent);
            IList <Variable> list      = new List <Variable>();

            Messenger.BulkWalk(
                VersionCode.V3,
                Agent,
                new OctetString(UserName),
                new ObjectIdentifier(definition.GetNumericalForm()),
                list,
                Timeout,
                10,
                WalkMode.WithinSubtree,
                _privacy,
                report);

            foreach (Variable v in list)
            {
                Logger.Info(v.ToString(Objects));
            }
        }
        internal override void GetTable(IDefinition def)
        {
            Discovery        discovery = Messenger.NextDiscovery;
            ReportMessage    report    = discovery.GetResponse(Timeout, Agent);
            IList <Variable> list      = new List <Variable>();
            int rows = Messenger.BulkWalk(
                VersionCode.V3,
                Agent,
                new OctetString(UserName),
                new ObjectIdentifier(def.GetNumericalForm()),
                list,
                Timeout,
                10,
                WalkMode.WithinSubtree,
                _privacy,
                report);

            // How many rows are there?
            if (rows > 0)
            {
                FormTable newTable = new FormTable(def);
                newTable.SetRows(rows);
                newTable.PopulateGrid(list);
                newTable.Show();
            }
            else
            {
                foreach (Variable t in list)
                {
                    Logger.Info(t.ToString());
                }
            }
        }
        private static void PersistModuleToFile(string folder, IModule module, IObjectTree tree)
        {
            string fileName = Path.Combine(folder, module.Name + ".module");

            using (StreamWriter writer = new StreamWriter(fileName))
            {
                writer.Write("#");
                foreach (string dependent in module.Dependents)
                {
                    writer.Write(dependent);
                    writer.Write(',');
                }

                writer.WriteLine();
                foreach (IEntity entity in module.Entities)
                {
                    IDefinition node = tree.Find(module.Name, entity.Name);
                    if (node == null)
                    {
                        continue;
                    }

                    uint[] id = node.GetNumericalForm();

                    /* 0: id
                     * 1: type
                     * 2: name
                     * 3: parent name
                     */
                    writer.WriteLine(ObjectIdentifier.Convert(id) + "," + entity.GetType() + "," + entity.Name + "," + entity.Parent);
                }

                writer.Close();
            }
        }
Beispiel #8
0
        //----------------------------------
        public void GetSNMP()
        {
            IDefinition definition = GetCurrent();

            if (definition != null)
            {
                if (m_connexion == null)
                {
                    if (!SetupConnexion())
                    {
                        return;
                    }
                }
                List <uint> lstOID = new List <uint>(definition.GetNumericalForm());
                lstOID.Add(0);
                CResultAErreurType <Variable> result = m_connexion.Get(lstOID.ToArray());
                if (!result)
                {
                    CFormAfficheErreur.Show(result.Erreur);
                }
                else
                {
                    CFormViewSNMPResult.ViewResult("Get " + definition.Name,
                                                   result.DataType,
                                                   this,
                                                   definition.Tree);
                }
            }
        }
        private static ObjectIdentifier GetIdForGet(IDefinition def)
        {
            if (def.Type == DefinitionType.Scalar)
            {
                return(ObjectIdentifier.Create(def.GetNumericalForm(), 0));
            }

            uint index;

            using (FormIndex form = new FormIndex())
            {
                form.ShowDialog();
                index = form.Index;
            }

            return(ObjectIdentifier.Create(def.GetNumericalForm(), index));
        }
        //-------------------------------------------
        public CDefinitionProprieteDynamiqueSnmpTable(IDefinition definition)
            : base(definition.Name,
                   ObjectIdentifier.Convert(definition.GetNumericalForm()).Replace('.', '_'),
                   new CDynamicSnmpTableDef(definition), "")

        {
            Rubrique = CInterrogateurSnmp.CalcRubriqueChamp(definition);
        }
 //-------------------------------------------
 public CDefinitionProprieteDynamiqueSnmpColumn(IDefinition definition)
     : base(definition.Name,
            ObjectIdentifier.Convert(definition.GetNumericalForm()).Replace('.', '_'),
            new CTypeResultatExpression(typeof(string), true),
            false, true)
 {
     //Rubrique = CMibDynamic.CalcRubriqueChamp(definition);
 }
Beispiel #12
0
        //---------------------------------------------------
        public static CColumnDefinitionSNMP FromDefinition(IDefinition definition)
        {
            CColumnDefinitionSNMP col = new CColumnDefinitionSNMP();

            col.ColumnName = definition.Name;
            col.OID        = definition.GetNumericalForm();
            col.DataType   = typeof(string);
            return(col);
        }
Beispiel #13
0
        //---------------------------------------------------
        public void InitDialog(IDefinition definition, IObjectTree mibTree)
        {
            m_definition   = definition;
            m_trap         = m_definition.Entity as TrapType;
            m_notification = m_definition.Entity as NotificationType;


            InitComboVersions();
            InitComboGenericCode();

            m_cmbGenericCode.Text = GenericCode.EnterpriseSpecific.ToString();
            m_cmbTrapVersion.Text = VersionCode.V1.ToString();

            string strOID = ObjectIdentifier.Convert(m_definition.GetNumericalForm());

            if (strOID.IndexOf('.') >= 0)
            {
                string strGeneric = strOID.Substring(strOID.LastIndexOf('.') + 1);
                strOID = strOID.Substring(0, strOID.LastIndexOf('.'));
                m_txtSpecificCode.Text = strGeneric;
            }
            m_txtEntreprise.Text = strOID;
            m_txtCommunity.Text  = "public";

            m_panelVariables.SuspendDrawing();
            m_panelVariables.ClearAndDisposeControls();
            List <string> lstVariables = new List <string>();

            if (m_trap != null)
            {
                lstVariables.AddRange(m_trap.Variables);
            }
            else if (m_notification != null)
            {
                lstVariables.AddRange(m_notification.Objects);
            }
            foreach (string strVariable in lstVariables)
            {
                IDefinition defVar = mibTree.Find(strVariable);
                if (defVar != null)
                {
                    CControlTrapVariable ctrl = new CControlTrapVariable();
                    m_panelVariables.Controls.Add(ctrl);
                    ctrl.Dock = DockStyle.Top;
                    ctrl.BringToFront();
                    ctrl.Init(defVar);
                }
            }
            m_panelVariables.ResumeDrawing();
        }
Beispiel #14
0
        //-------------------------------------------------------
        private void m_mnuVoirTable_Click(object sender, EventArgs e)
        {
            IDefinition definition = GetCurrent();

            if (definition != null)
            {
                if (m_connexion == null)
                {
                    if (!SetupConnexion())
                    {
                        return;
                    }
                }
                CResultAErreurType <DataTable> result = m_connexion.GetTable(definition.GetNumericalForm());
                if (!result)
                {
                    CFormAfficheErreur.Show(result.Erreur);
                }
                else
                {
                    DataTable   table = result.DataType;
                    IObjectTree tree  = definition.Tree;
                    if (tree != null)
                    {
                        foreach (DataColumn col in table.Columns)
                        {
                            try
                            {
                                uint[]      oid = ObjectIdentifier.Convert(col.ColumnName);
                                IDefinition def = tree.Find(oid);
                                if (def != null)
                                {
                                    col.ColumnName = def.Name;
                                }
                            }
                            catch
                            {
                            }
                        }
                    }

                    CFormVisuTable.ShowTable("Table " + definition.Name, result.DataType);
                }
            }
        }
        //-----------------------------------------
        private void FillTable(IDefinition definition)
        {
            AssureTable();
            if (TableContenu == null)
            {
                return;
            }
            DataRow row = TableContenu.NewRow();

            row[c_strColumnOID]  = ObjectIdentifier.Convert(definition.GetNumericalForm());
            row[c_strColumnName] = definition.Name;
            row[c_strColumnType] = definition.Type.ToString();
            TableContenu.Rows.Add(row);
            foreach (IDefinition child in definition.Children)
            {
                FillTable(child);
            }
        }
 internal override void GetTable(IDefinition def)
 {
     IList<Variable> list = new List<Variable>();
     int rows = Messenger.Walk(VersionCode, Agent, GetCommunity, new ObjectIdentifier(def.GetNumericalForm()), list, Timeout, WalkMode.WithinSubtree);
     
     // How many rows are there?
     if (rows > 0)
     {
         FormTable newTable = new FormTable(def);
         newTable.SetRows(rows);
         newTable.PopulateGrid(list);
         newTable.Show();
     }
     else
     {
         foreach (Variable t in list)
         {
             Logger.Info(t.ToString());
         }
     }
 }
Beispiel #17
0
        //------------------------------------
        public void DisplayElement(IDefinition definition)
        {
            OidValueAssignment objectType = definition.Entity as OidValueAssignment;

            m_exLinkField.FillDialogFromObjet(objectType);
            m_definition = definition;

            //Ajoute les \r à la description
            string strDesc = definition.Description;

            if (!strDesc.Contains("\r"))
            {
                strDesc = strDesc.Replace("\n", "\r\n");
            }
            m_lblDescription.Text = strDesc;

            //Récupère l'OID
            m_lblOID.Text = ObjectIdentifier.Convert(definition.GetNumericalForm());

            UpdateVisuPages();
        }
Beispiel #18
0
        //-----------------------------------
        public static CTableDefinitionSNMP FromDefinition(
            CEasyQuerySource laBase,
            IDefinition def,
            CEasyQuerySourceFolder folder

            )
        {
            CTableDefinitionSNMP table = null;

            if (def.Type == DefinitionType.Table)
            {
                table           = new CTableDefinitionSNMP(laBase);
                table.TableName = def.Name;
                table.OID       = def.GetNumericalForm();

                if (folder != null)
                {
                    table.FolderId = folder.Id;
                }

                if (def.Children.Count() == 1)
                {
                    CColumnDefinitionSimple colIndex = new CColumnDefinitionSimple("Index", typeof(string));
                    table.AddColumn(colIndex);
                    IDefinition entry = def.Children.ElementAt(0);
                    foreach (IDefinition col in entry.Children)
                    {
                        if (col.Type == DefinitionType.Column)
                        {
                            CColumnDefinitionSNMP newCol = new CColumnDefinitionSNMP();
                            newCol.ColumnName = col.Name;
                            newCol.OID        = col.GetNumericalForm();
                            newCol.DataType   = typeof(string);
                            table.AddColumn(newCol);
                        }
                    }
                }
            }
            return(table);
        }
Beispiel #19
0
        internal void Walk(Manager manager, IDefinition def)
        {
            IList <Variable> list = new List <Variable>();

            int rows = Messenger.Walk(VersionCode, AgentIP, new OctetString(GetCommunity), new ObjectIdentifier(def.GetNumericalForm()), list, 1000, WalkMode.WithinSubtree);

            //
            // How many rows are there?
            //
            if (rows > 0)
            {
                FormTable newTable = new FormTable(def);
                newTable.SetRows(rows);
                newTable.PopulateGrid(list);
                newTable.Show();
            }
            else
            {
                TraceSource source = new TraceSource("Browser");
                for (int i = 0; i < list.Count; i++)
                {
                    source.TraceInformation(list[i].ToString());
                }

                source.Flush();
                source.Close();
            }
        }
Beispiel #20
0
 //-------------------------------------------------------------------------
 public CDefinitionProprieteDynamiqueSNMPVariable(IDefinition definition)
     : base(definition.Name, ObjectIdentifier.Convert(definition.GetNumericalForm()).Replace('.', '_'),
            new CTypeResultatExpression(typeof(string), false), false, false)
 {
     Rubrique = CInterrogateurSnmp.CalcRubriqueChamp(definition);
 }
        internal override void GetTable(IDefinition def)
        {
            Discovery discovery = Messenger.NextDiscovery;
            ReportMessage report = discovery.GetResponse(Timeout, Agent);
            IList<Variable> list = new List<Variable>();
            int rows = Messenger.BulkWalk(
                VersionCode.V3,
                Agent, 
                new OctetString(UserName),
                new ObjectIdentifier(def.GetNumericalForm()), 
                list, 
                Timeout, 
                10,
                WalkMode.WithinSubtree, 
                _privacy, 
                report);

            // How many rows are there?
            if (rows > 0)
            {
                FormTable newTable = new FormTable(def);
                newTable.SetRows(rows);
                newTable.PopulateGrid(list);
                newTable.Show();
            }
            else
            {
                foreach (Variable t in list)
                {
                    Logger.Info(t.ToString());
                }
            }
        }
 private static ObjectIdentifier GetIdForGetNext(IDefinition def)
 {
     return(def.Type == DefinitionType.Scalar ? ObjectIdentifier.Create(def.GetNumericalForm(), 0) : new ObjectIdentifier(def.GetNumericalForm()));
 }
        public override void Walk(IDefinition definition)
        {
            if (string.IsNullOrEmpty(UserName))
            {
                Logger.Info("User name need to be specified for v3.");
                return;
            }

            Discovery discovery = Messenger.NextDiscovery;
            ReportMessage report = discovery.GetResponse(Timeout, Agent);
            IList<Variable> list = new List<Variable>();
            Messenger.BulkWalk(
                VersionCode.V3,
                Agent, 
                new OctetString(UserName),
                new ObjectIdentifier(definition.GetNumericalForm()),
                list,
                Timeout, 
                10,
                WalkMode.WithinSubtree, 
                _privacy, 
                report);

            foreach (Variable v in list)
            {
                Logger.Info(v.ToString(Objects));
            }
        }
        public override void Walk(IDefinition definition)
        {
            IList<Variable> list = new List<Variable>();
            if (VersionCode == VersionCode.V1)
            {
                Messenger.Walk(
                    VersionCode, 
                    Agent, 
                    GetCommunity,
                    new ObjectIdentifier(definition.GetNumericalForm()),
                    list,
                    Timeout,
                    WalkMode.WithinSubtree);
            }
            else
            {
                Messenger.BulkWalk(
                    VersionCode,
                    Agent, 
                    GetCommunity,
                    new ObjectIdentifier(definition.GetNumericalForm()), 
                    list, 
                    Timeout,
                    10,
                    WalkMode.WithinSubtree, 
                    null, 
                    null);
            }

            foreach (Variable v in list)
            {
                Logger.Info(v.ToString(Objects));
            }
        }
        //------------------------------------
        public void DisplayElement(IDefinition definition)
        {
            ObjectType objectType = definition.Entity as ObjectType;

            m_exLinkField.FillDialogFromObjet(objectType);
            m_definition = definition;

            //Ajoute les \r à la description
            string strDesc = definition.Description;

            if (!strDesc.Contains("\r"))
            {
                strDesc = strDesc.Replace("\n", "\r\n");
            }
            m_lblDescription.Text = strDesc;

            if (objectType.Syntax != null)
            {
                m_lblDataType.Text = objectType.Syntax.GetType().Name;
            }

            //Récupère l'OID
            m_lblOID.Text = ObjectIdentifier.Convert(definition.GetNumericalForm());

            if (objectType != null)
            {
                switch (objectType.Access)
                {
                case MaxAccess.notAccessible:
                    m_txtAccess.Text = I.T("Not accessible|20005");
                    break;

                case MaxAccess.accessibleForNotify:
                    m_txtAccess.Text = I.T("Accessible for notify|20006");
                    break;

                case MaxAccess.readOnly:
                    m_txtAccess.Text = I.T("Read only|20007");
                    break;

                case MaxAccess.readWrite:
                    m_txtAccess.Text = I.T("Read / Write|20008");
                    break;

                case MaxAccess.readCreate:
                    m_txtAccess.Text = I.T("Read / Create|20009");
                    break;

                default:
                    break;
                }
            }

            m_wndListeIndices.Items.Clear();
            if (objectType != null)
            {
                foreach (string strIndice in objectType.Indices)
                {
                    m_wndListeIndices.Items.Add(strIndice);
                }
            }
            if (m_definition.Type == DefinitionType.Table || m_definition.Type == DefinitionType.Entry)
            {
                FillPageTable();
            }

            UpdateVisuPages();
        }
Beispiel #26
0
        //-----------------------------------
        private static void FillListeTables(
            CEasyQuerySource laBase,
            IDefinition definition,
            List <ITableDefinition> lstToFill,
            CEasyQuerySourceFolder folderRacine)
        {
            CTableDefinitionSnmpOfScalar tableScalars = null;

            if (definition.Entity != null)
            {
                tableScalars           = new CTableDefinitionSnmpOfScalar();
                tableScalars.OIDRacine = definition.GetNumericalForm();
                tableScalars.TableName = folderRacine.Name + "_Scalars";
                tableScalars.FolderId  = folderRacine.Id;
            }
            foreach (IDefinition children in definition.Children)
            {
                if (children.Type == DefinitionType.Table)
                {
                    CTableDefinitionSNMP table = FromDefinition(laBase, children, folderRacine);
                    if (table != null)
                    {
                        lstToFill.Add(table);
                        laBase.AddTableUniquementPourObjetConnexion(table);
                    }
                }
                else if (children.Type == DefinitionType.OidValueAssignment)
                {
                    CEasyQuerySourceFolder folder = folderRacine.GetSubFolderWithCreate(children.Name);
                    FillListeTables(laBase, children, lstToFill, folder);
                }
                else if (children.Type == DefinitionType.Scalar)
                {
                    if (children.Type == DefinitionType.Scalar && tableScalars != null)
                    {
                        CColumnDefinitionSNMP colSnmp = new CColumnDefinitionSNMP();
                        colSnmp.ColumnName = children.Name;
                        colSnmp.OID        = children.GetNumericalForm();
                        Type       tp      = typeof(string);
                        ObjectType objType = children.Entity as ObjectType;
                        if (objType != null)
                        {
                            TextualConvention conv = objType.Syntax as TextualConvention;
                            if (conv != null)
                            {
                                tp = ((AbstractTypeAssignment)conv.Syntax).GetTypeDotNet();
                            }
                            else
                            {
                                AbstractTypeAssignment abs = objType.Syntax as AbstractTypeAssignment;
                                if (abs != null)
                                {
                                    tp = abs.GetTypeDotNet();
                                }
                            }
                        }
                        switch (objType.Access)
                        {
                        case MaxAccess.accessibleForNotify:
                        case MaxAccess.readOnly:
                            colSnmp.IsReadOnly = true;
                            break;

                        case MaxAccess.readWrite:
                        case MaxAccess.readCreate:
                            colSnmp.IsReadOnly = false;
                            break;
                        }
                        colSnmp.DataType = tp;
                        tableScalars.AddColumn(colSnmp);
                    }
                }
            }
            if (tableScalars != null && tableScalars.Columns.Count() > 0)
            {
                laBase.AddTableUniquementPourObjetConnexion(tableScalars);
                tableScalars.Base = laBase;
            }
        }
Beispiel #27
0
        //-----------------------------------
        public static CTableDefinitionSNMP FromDefinition(
            CEasyQuerySource laBase,
            IDefinition def,
            CEasyQuerySourceFolder folder

            )
        {
            CTableDefinitionSNMP table = null;

            if (def.Type == DefinitionType.Table)
            {
                table           = new CTableDefinitionSNMP(laBase);
                table.TableName = def.Name;
                table.OID       = def.GetNumericalForm();

                if (folder != null)
                {
                    table.FolderId = folder.Id;
                }

                if (def.Children.Count() == 1)
                {
                    CColumnDefinitionSimple colIndex = new CColumnDefinitionSimple("Index", typeof(string));
                    table.AddColumn(colIndex);
                    IDefinition entry = def.Children.ElementAt(0);
                    foreach (IDefinition col in entry.Children)
                    {
                        if (col.Type == DefinitionType.Column)
                        {
                            ObjectType objType = col.Entity as ObjectType;
                            if (objType != null && objType.Access != MaxAccess.notAccessible)
                            {
                                CColumnDefinitionSNMP newCol = new CColumnDefinitionSNMP();
                                newCol.ColumnName  = col.Name;
                                newCol.Description = col.Description;
                                newCol.OID         = col.GetNumericalForm();
                                TextualConvention conv = objType.Syntax as TextualConvention;
                                if (conv != null)
                                {
                                    newCol.SnmpType = conv.Syntax as AbstractTypeAssignment;
                                }
                                else
                                {
                                    newCol.SnmpType = objType.Syntax as AbstractTypeAssignment;
                                }
                                if (newCol.SnmpType == null)
                                {
                                    newCol.DataType   = typeof(string);
                                    newCol.IsReadOnly = true;
                                }
                                switch (objType.Access)
                                {
                                case MaxAccess.accessibleForNotify:
                                case MaxAccess.readOnly:
                                    newCol.IsReadOnly = true;
                                    break;

                                case MaxAccess.readWrite:
                                case MaxAccess.readCreate:
                                    newCol.IsReadOnly = false;
                                    break;
                                }
                                table.AddColumn(newCol);
                            }
                        }
                    }
                }
            }
            return(table);
        }
Beispiel #28
0
        //---------------------------------------
        public static CTrapHandler CreateFromMib(
            IObjectTree tree,
            IDefinition defNotification,
            CMemoryDb db)
        {
            NotificationType notification = defNotification.Entity as NotificationType;

            if (notification != null)
            {
                CTrapHandler handler = new CTrapHandler(db);
                handler.CreateNew();
                handler.Libelle     = defNotification.Name;
                handler.Description = defNotification.Description;
                foreach (string strObjet in notification.Objects)
                {
                    CTrapField field = new CTrapField();
                    field.Name = strObjet;
                    IDefinition def = tree.Find(strObjet);
                    if (def != null)
                    {
                        field.OID = ObjectIdentifier.Convert(def.GetNumericalForm());
                        handler.AddFieldFromTrap(field);
                    }
                }
                handler.GenericRequestedValue    = GenericCode.EnterpriseSpecific;
                handler.EntrepriseRequestedValue = ObjectIdentifier.Convert(defNotification.GetNumericalForm());
                if (handler.EntrepriseRequestedValue.EndsWith("." + notification.Value.ToString()))
                {
                    handler.EntrepriseRequestedValue = handler.EntrepriseRequestedValue.Remove(handler.EntrepriseRequestedValue.Length - notification.Value.ToString().Length - 1);
                }
                handler.SpecificRequestedValue = notification.Value.ToString();
                return(handler);
            }
            TrapType trap = defNotification.Entity as TrapType;

            if (trap != null)
            {
                CTrapHandler handler = new CTrapHandler(db);
                handler.CreateNew();
                handler.Libelle     = trap.Name;
                handler.Description = trap.Description;
                foreach (string strObjet in trap.Variables)
                {
                    CTrapField field = new CTrapField();
                    field.Name = strObjet;
                    IDefinition def = tree.Find(strObjet);
                    if (def != null)
                    {
                        field.OID = ObjectIdentifier.Convert(def.GetNumericalForm());
                        handler.AddFieldFromTrap(field);
                    }
                }
                handler.GenericRequestedValue    = GenericCode.EnterpriseSpecific;
                handler.EntrepriseRequestedValue = ObjectIdentifier.Convert(defNotification.GetNumericalForm());
                if (handler.EntrepriseRequestedValue.EndsWith("." + trap.Value.ToString()))
                {
                    handler.EntrepriseRequestedValue = handler.EntrepriseRequestedValue.Remove(handler.EntrepriseRequestedValue.Length - trap.Value.ToString().Length - 1);
                }
                handler.SpecificRequestedValue = trap.Value.ToString();
                return(handler);
            }
            return(null);
        }
        internal override void GetTable(IDefinition def)
        {
            IList <Variable> list = new List <Variable>();
            int rows = Messenger.Walk(VersionCode, Agent, GetCommunity, new ObjectIdentifier(def.GetNumericalForm()), list, Timeout, WalkMode.WithinSubtree);

            // How many rows are there?
            if (rows > 0)
            {
                FormTable newTable = new FormTable(def);
                newTable.SetRows(rows);
                newTable.PopulateGrid(list);
                newTable.Show();
            }
            else
            {
                foreach (Variable t in list)
                {
                    Logger.Info(t.ToString());
                }
            }
        }
Beispiel #30
0
        //----------------------------------------------------------------
        private CResultAErreurType <CSnmpTrap> CreateTrap()
        {
            CResultAErreurType <CSnmpTrap> result = new CResultAErreurType <CSnmpTrap>();
            CSnmpTrap trap = new CSnmpTrap();

            trap.AgentIpString = m_txtIP.Text;
            trap.Communaute    = m_txtCommunity.Text;

            try
            {
                GenericCode code = (GenericCode)Enum.Parse(typeof(GenericCode), m_cmbGenericCode.Text);
                trap.GenericCode = code;
            }
            catch
            {
                result.EmpileErreur(I.T("Invalid generic code|20115"));
            }
            try
            {
                VersionCode code = (VersionCode)Enum.Parse(typeof(VersionCode), m_cmbTrapVersion.Text);
                trap.VersionCode = code;
            }
            catch
            {
                result.EmpileErreur(I.T("Invalide version code|20116"));
            }
            if (trap.GenericCode == GenericCode.EnterpriseSpecific)
            {
                try
                {
                    trap.EntrepriseOID = new ObjectIdentifier(m_txtEntreprise.Text);
                }
                catch
                {
                    result.EmpileErreur(I.T("Invalid entreprise value|20117"));
                }
                if (m_txtSpecificCode.IntValue == null)
                {
                    result.EmpileErreur(I.T("Invalide specific code[20118"));
                }
                else
                {
                    trap.SpecificCode = m_txtSpecificCode.IntValue.Value;
                }
            }
            trap.TrapDateTime = DateTime.Now;
            foreach (Control ctrl in m_panelVariables.Controls)
            {
                CControlTrapVariable trapV = ctrl as CControlTrapVariable;
                if (trapV != null)
                {
                    CResultAErreurType <ISnmpData> resData = trapV.GetValue();
                    if (!resData)
                    {
                        result.EmpileErreur(resData.Erreur);
                    }
                    else if (resData.DataType != null)
                    {
                        IDefinition def = trapV.Definition;
                        trap.SetVariableValue(ObjectIdentifier.Convert(def.GetNumericalForm()), resData.DataType);
                    }
                }
            }
            if (result)
            {
                result.DataType = trap;
            }
            return(result);
        }