border

0 今天是
无标题

snmp‎ > ‎

extending-the-NetSnmp-Agent

1. variable2 结构体的定义说明在agent/var_struct.h文件中。 http://www.net-snmp.org/dev/agent/var__struct_8h-source.html
struct variable2 {
    u_char          magic;      /* passed to function as a hint */
    u_char          type;       /* type of variable */
    u_short         acl;        /* access control list for variable */
    FindVarMethod  *findVar;    /* function that finds variable */
    u_char          namelen;    /* length of name below */
    oid             name[2];    /* object identifier of variable */
};


    /*
     * This array structure defines a representation of the
     *  MIB being implemented.
     *
     * The type of the array is 'struct variableN', where N is
     *  large enough to contain the longest OID sub-component
     *  being loaded.  This will normally be the maximum value
     *  of the fifth field in each line.  In this case, the second
     *  and third entries are both of size 2, so we're using
     *  'struct variable2'
     *
     * The supported values for N are listed in <agent/var_struct.h>
     *  If the value you need is not listed there, simply use the
     *  next largest that is.
     *
     * The format of each line is as follows
     *  (using the first entry as an example):
     *      1: EXAMPLESTRING:
     *          The magic number defined in the example header file.
     *          This is passed to the callback routine and is used
     *            to determine which object is being queried.
     *      2: ASN_OCTET_STR:
     *          The type of the object.
     *          Valid types are listed in <snmp_impl.h>
     *      3: RONLY (or RWRITE):
     *          Whether this object can be SET or not.
     *      4: var_example:
     *          The callback routine, used when the object is queried.
     *          This will usually be the same for all objects in a module
     *            and is typically defined later in this file.
     *      5: 1:
     *          The length of the OID sub-component (the next field)
     *      6: {1}:
     *          The OID sub-components of this entry.
     *          In other words, the bits of the full OID that differ
     *            between the various entries of this array.
     *          This value is appended to the common prefix (defined later)
     *            to obtain the full OID of each entry.
     */
struct variable2 example_variables[] = {
    {EXAMPLESTRING, ASN_OCTET_STR, RONLY, var_example, 1, {1}},
    {EXAMPLEINTEGER, ASN_INTEGER, RWRITE, var_example, 2, {2, 1}},
    {EXAMPLEOBJECTID, ASN_OBJECT_ID, RONLY, var_example, 2, {2, 2}},
    {EXAMPLETIMETICKS, ASN_TIMETICKS, RONLY, var_example, 1, {3}},
    {EXAMPLEIPADDRESS, ASN_IPADDRESS, RONLY, var_example, 1, {4}},
    {EXAMPLECOUNTER, ASN_COUNTER, RONLY, var_example, 1, {5}},
    {EXAMPLEGAUGE, ASN_GAUGE, RONLY, var_example, 1, {6}},
    {EXAMPLETRIGGERTRAP, ASN_INTEGER, RWRITE, var_example, 1, {7}},
    {EXAMPLETRIGGERTRAP2, ASN_INTEGER, RWRITE, var_example, 1, {8}}
};

2. snmptranslate -IR -Tp netSnmpExamples

3. border@debian:~/work/USI/snmp/foxmail/mibs/iterator$ snmptranslate -Tp -IR foxmail
+--foxmail(310)
   |
   +-- -RW- Integer32 SecondCounter(1)
   +-- -R-- TimeTicks WeekTime(2)
   |
   +--ExampleTable(3)
      |
      +--ExampleEntry(1)
         |  Index: UserIndex
         |
         +-- -R-- Integer32 UserIndex(1)
         |        Textual Convention: InterfaceIndex
         |        Range: 1..2147483647
         +-- -R-- String    UserStatus(2)
         |        Textual Convention: DisplayString
         |        Size: 0..255
         +-- -R-- TimeTicks CheckTime(3)
         +-- -RW- Integer32 MonSet(4)

4.
mib2c -c mib2c.scalar.conf foxmail
mib2c -c mib2c.iterate.conf foxmail
mib2c -c mib2c.iterate_access.conf foxmail


5.
border@debian:~/work/USI/snmp/foxmail/mibs/iterator_access$ mib2c -c mib2c.iterate_access.conf ExampleTable
writing to ExampleTable.h
writing to ExampleTable_columns.h
writing to ExampleTable_enums.h
writing to ExampleTable.c
writing to ExampleTable_checkfns_local.h
writing to ExampleTable_checkfns_local.c
writing to ExampleTable_checkfns.h
writing to ExampleTable_checkfns.c
writing to ExampleTable_access.h
writing to ExampleTable_access.c
writing to -

**********************************************************************
NOTE:  The only files you MUST modify should be the following:
  ExampleTable_access.c
  ExampleTable_access.h
  ExampleTable_checkfns_local.h
  ExampleTable_checkfns_local.c
**********************************************************************

running indent on ExampleTable.h
running indent on ExampleTable_checkfns.h
running indent on ExampleTable_checkfns_local.c
running indent on ExampleTable_checkfns_local.h
running indent on ExampleTable_columns.h
running indent on ExampleTable_access.c
running indent on ExampleTable_access.h
running indent on ExampleTable.c
running indent on ExampleTable_enums.h
running indent on ExampleTable_checkfns.c

border@debian:~/work/USI/snmp/foxmail/mibs/iterator_access$ tree
.
|-- ExampleTable.c
|-- ExampleTable.h
|-- ExampleTable_access.c
|-- ExampleTable_access.h
|-- ExampleTable_checkfns.c
|-- ExampleTable_checkfns.h
|-- ExampleTable_checkfns_local.c
|-- ExampleTable_checkfns_local.h
|-- ExampleTable_columns.h
`-- ExampleTable_enums.h

0 directories, 10 files


6.