Skip to content

EnumVal example #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions examples/SIMPLE-MIB.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ simpleDisplayString OBJECT-TYPE
"An ASCII string value."
::= { simpleScalars 11 }

SimpleEnumVal ::= TEXTUAL-CONVENTION
STATUS current
DESCRIPTION
"A EnumValue"
SYNTAX Integer32 { Release(0), Debue(1), Testing(2), Stable(3) }

simpleEnumVal OBJECT-TYPE
SYNTAX SimpleEnumVal
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"An ASCII string value."
::= { simpleScalars 12 }

------------------------------------------------------------------------
-- Tables
------------------------------------------------------------------------
Expand Down Expand Up @@ -216,6 +230,14 @@ firstTableRowValue OBJECT-TYPE
"A firstTableRow's value."
::= { firstTableRow 3 }

firstTableEnumVale OBJECT-TYPE
SYNTAX SimpleEnumVal
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"A firstTableEnumVale's value."
::= { firstTableRow 4 }

secondTableNumber OBJECT-TYPE
SYNTAX Unsigned32
MAX-ACCESS read-only
Expand Down Expand Up @@ -330,6 +352,62 @@ thirdTableRowValue OBJECT-TYPE
"A thirdTableRow's value."
::= { thirdTableRow 3 }

fourthTableNumber OBJECT-TYPE
SYNTAX Unsigned32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The number of rows in fourthTable."
::= { simpleTables 7 }

fourthTable OBJECT-TYPE
SYNTAX SEQUENCE OF FourthTableRow
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"The fourth simple table"
::= { simpleTables 8 }

fourthTableRow OBJECT-TYPE
SYNTAX FourthTableRow
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"A particular fourthTable row."
INDEX { fourthTableRowIndex }
::= { fourthTable 1 }

FourthTableRow ::=
SEQUENCE {
fourthTableRowIndex SimpleEnumVal,
fourthTableRowDesc DisplayString,
fourthTableRowValue IpAddress
}

fourthTableRowIndex OBJECT-TYPE
SYNTAX SimpleEnumVal
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"The index column used to generate IpAddress indices into
fourthTable."
::= { fourthTableRow 1 }

fourthTableRowDesc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"A fourthTableRow's description."
::= { fourthTableRow 2 }

fourthTableRowValue OBJECT-TYPE
SYNTAX IpAddress
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"A fourthTableRow's value."
::= { fourthTableRow 3 }
------------------------------------------------------------------------
-- Notifications
------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions examples/run_simple_agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ echo " snmpwalk -v 2c -c public -M+. localhost:5555 SIMPLE-MIB::simpleMIB"
echo " snmptable -v 2c -c public -M+. -Ci localhost:5555 SIMPLE-MIB::firstTable"
echo " snmpget -v 2c -c public -M+. localhost:5555 SIMPLE-MIB::simpleInteger.0"
echo " snmpset -v 2c -c simple -M+. localhost:5555 SIMPLE-MIB::simpleInteger.0 i 123"
echo " snmpset -v 2c -c simple -M+. localhost:5555 SIMPLE-MIB::simpleEnumVal.0 = Testing"
echo " snmpset -v 2c -c simple -M+. localhost:5555 SIMPLE-MIB::firstTableEnumVale.\\\"bb\\\" = Testing"
echo " snmpset -v 2c -c simple -M+. localhost:5555 SIMPLE-MIB::fourthTableRowValue.Testing = 192.168.1.118"

echo ""

# Workaround to have CTRL-C not generate any visual feedback (we don't do any
Expand Down
41 changes: 40 additions & 1 deletion examples/simple_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
initval = "Nice to meet you"
)

simpleEnumVal = agent.Integer32(
oidstr = "SIMPLE-MIB::simpleEnumVal",
initval = 1
)

# Create the first table
firstTable = agent.Table(
oidstr = "SIMPLE-MIB::firstTable",
Expand All @@ -151,7 +156,8 @@
# used for the single index column above.
# We must explicitly specify that the columns should be SNMPSETable.
(2, agent.DisplayString("Unknown place"), True),
(3, agent.Integer32(0), True)
(3, agent.Integer32(0), True),
(4, agent.Integer32(0), True)
],
counterobj = agent.Unsigned32(
oidstr = "SIMPLE-MIB::firstTableNumber"
Expand All @@ -164,6 +170,7 @@
firstTableRow1 = firstTable.addRow([agent.DisplayString("aa")])
firstTableRow1.setRowCell(2, agent.DisplayString("Prague"))
firstTableRow1.setRowCell(3, agent.Integer32(20))
firstTableRow1.setRowCell(4, agent.Integer32(0))

# Add the second table row
firstTableRow2 = firstTable.addRow([agent.DisplayString("ab")])
Expand Down Expand Up @@ -227,6 +234,38 @@
# Add the third table row
thirdTableRow3 = thirdTable.addRow([agent.IpAddress("192.168.0.3")])

# Create the fourth table
fourthTable = agent.Table(
oidstr = "SIMPLE-MIB::fourthTable",
indexes = [
agent.Integer32()
],
columns = [
(2, agent.DisplayString("Broadcast"), True),
(3, agent.IpAddress("192.168.0.255"), True)
],
counterobj = agent.Unsigned32(
oidstr = "SIMPLE-MIB::fourthTableNumber"
),
# Allow adding new records
extendable = True
)

# Add the first table row
fourthTableRow1 = fourthTable.addRow([agent.Integer32(0)])
fourthTableRow1.setRowCell(2, agent.DisplayString("Host 1"))
fourthTableRow1.setRowCell(3, agent.IpAddress("192.168.0.1"))

# Add the second table row
fourthTableRow2 = fourthTable.addRow([agent.Integer32(1)])
fourthTableRow2.setRowCell(2, agent.DisplayString("Host 2"))
fourthTableRow2.setRowCell(3, agent.IpAddress("192.168.0.2"))

# Add the second table row
fourthTableRow3 = fourthTable.addRow([agent.Integer32(2)])
fourthTableRow3.setRowCell(2, agent.DisplayString("Host 3"))
fourthTableRow3.setRowCell(3, agent.IpAddress("192.168.0.3"))

# Finally, we tell the agent to "start". This actually connects the
# agent to the master agent.
try:
Expand Down