首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SNMP4j代理snmp表

SNMP4j代理snmp表
EN

Stack Overflow用户
提问于 2013-08-30 23:55:26
回答 1查看 1.9K关注 0票数 2

我使用snmp4j api在SNMP代理上创建,但遇到snmp表注册问题。

一旦我注册了一个表,表中的and和行。之后,如果我设置了table中的值,所有的行都被设置为相同的值。我从JSON创建了snmp表

在下表中,如果我设置了值

.1.3.6.1.4.1.1.201.6.2。它为下表中注册的所有行设置值。有谁知道如何使用snmmpj代理正确注册和设置值。

代码语言:javascript
复制
{
        "tableName": "table1", 
        "tableId": ".1.3.6.1.4.1.1.201.6.1", 
        "columns": [
            {
                "columnName": "column1", 
                "columnOID": 1, 
                "dataType": 70, 
                "accessType": 1,
                "defaultValue":0
            }, 
            {
                "columnName": "column2", 
                "columnOID": 2, 
                "dataType": 70, 
                "accessType": 1,
                "defaultValue":0
            }, 
            {
                "columnName": "column3", 
                "columnOID": 3, 
                "dataType": 70, 
                "accessType": 1,
                "defaultValue":0
            },

        ]
    }



 public static MOTable<MOTableRow<Variable>, MOColumn<Variable>, MOTableModel<MOTableRow<Variable>>> createTableFromJSON(
        JSONObject data) {
    MOTable table = null;

    if (data != null) {
        MOTableSubIndex[] subIndex = new MOTableSubIndex[] { moFactory
                .createSubIndex(null, SMIConstants.SYNTAX_INTEGER, 1, 100) };
        MOTableIndex index = moFactory.createIndex(subIndex, false,
                new MOTableIndexValidator() {
                    public boolean isValidIndex(OID index) {
                        boolean isValidIndex = true;
                        return isValidIndex;
                    }
                });
        Object indexesObj = data.get("indexValues");
        if(indexesObj!=null){
            String indexes = data.getString("indexValues");
            String tableOID = data.getString("tableId");
            JSONArray columnArray = data.getJSONArray("columns");
            int columnSize = columnArray.size();
            MOColumn[] columns = new MOColumn[columnSize];
            Variable[] initialValues = new Variable[columnSize];
            for (int i = 0; i < columnSize; i++) {
                JSONObject columnObject = columnArray.getJSONObject(i);
                columns[i] = moFactory.createColumn(columnObject
                        .getInt("columnOID"), columnObject.getInt("dataType"),
                        moFactory.createAccess(columnObject
                                .getInt("accessType")));
                initialValues[i] = getVariable(columnObject.get("defaultValue"));

            }

            MOTableModel tableModel = moFactory.createTableModel(new OID(
                    tableOID), index, columns);

            table = moFactory.createTable(new OID(tableOID), index, columns,
                    tableModel);
            String[] indexArrString = indexes.split(";");
            for(String indexStr: indexArrString){
                MOTableRow<Variable> row = createRow(new Integer(indexStr.trim()), initialValues);
                table.addRow(row);
            }
        }
        }

    return table;

}
EN

回答 1

Stack Overflow用户

发布于 2014-02-02 19:40:28

首先,OID不是以点(由ASN.1指定)开头的。

其次,您似乎没有使用任何行索引数据。行由它们的索引标识。行索引是表格实例OID的实例标识符后缀:

代码语言:javascript
复制
<tableOID>.1.<rowIndex>

can由几个编码为OID的子索引值组成。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18537050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档