From cef6d1959e6c66caef7abc3d133934c343ac6f3e Mon Sep 17 00:00:00 2001 From: Hassan Pouralijan Date: Fri, 20 Dec 2019 23:44:10 +0330 Subject: [PATCH 1/3] Add EnumVal example for scalars. --- examples/SIMPLE-MIB.txt | 14 ++++++++++++++ examples/simple_agent.py | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/examples/SIMPLE-MIB.txt b/examples/SIMPLE-MIB.txt index a3c1045..aee7f3c 100644 --- a/examples/SIMPLE-MIB.txt +++ b/examples/SIMPLE-MIB.txt @@ -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(3), Stable(4) } + +simpleEnumVal OBJECT-TYPE + SYNTAX SimpleEnumVal + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "An ASCII string value." + ::= { simpleScalars 12 } + ------------------------------------------------------------------------ -- Tables ------------------------------------------------------------------------ diff --git a/examples/simple_agent.py b/examples/simple_agent.py index d29210c..32cb7a6 100755 --- a/examples/simple_agent.py +++ b/examples/simple_agent.py @@ -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", From afefb41432dfceed98342331865575624034d3c3 Mon Sep 17 00:00:00 2001 From: Hassan Pouralijan Date: Fri, 20 Dec 2019 23:57:11 +0330 Subject: [PATCH 2/3] Add EnumVal example for tables. --- examples/SIMPLE-MIB.txt | 8 ++++++++ examples/run_simple_agent.sh | 2 ++ examples/simple_agent.py | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/SIMPLE-MIB.txt b/examples/SIMPLE-MIB.txt index aee7f3c..5fbb9d8 100644 --- a/examples/SIMPLE-MIB.txt +++ b/examples/SIMPLE-MIB.txt @@ -230,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 diff --git a/examples/run_simple_agent.sh b/examples/run_simple_agent.sh index 61f0e95..3112c27 100755 --- a/examples/run_simple_agent.sh +++ b/examples/run_simple_agent.sh @@ -86,6 +86,8 @@ 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 "" # Workaround to have CTRL-C not generate any visual feedback (we don't do any diff --git a/examples/simple_agent.py b/examples/simple_agent.py index 32cb7a6..b04d081 100755 --- a/examples/simple_agent.py +++ b/examples/simple_agent.py @@ -156,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" @@ -169,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")]) From a2a830f747f26a6b162ea3c1f4a72e4465e8bca0 Mon Sep 17 00:00:00 2001 From: Hassan Pouralijan Date: Sat, 21 Dec 2019 01:02:19 +0330 Subject: [PATCH 3/3] Add EnumVal example for tables index. --- examples/SIMPLE-MIB.txt | 58 +++++++++++++++++++++++++++++++++++- examples/run_simple_agent.sh | 2 ++ examples/simple_agent.py | 32 ++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/examples/SIMPLE-MIB.txt b/examples/SIMPLE-MIB.txt index 5fbb9d8..3573fce 100644 --- a/examples/SIMPLE-MIB.txt +++ b/examples/SIMPLE-MIB.txt @@ -159,7 +159,7 @@ SimpleEnumVal ::= TEXTUAL-CONVENTION STATUS current DESCRIPTION "A EnumValue" - SYNTAX Integer32 { Release(0), Debue(1), Testing(3), Stable(4) } + SYNTAX Integer32 { Release(0), Debue(1), Testing(2), Stable(3) } simpleEnumVal OBJECT-TYPE SYNTAX SimpleEnumVal @@ -352,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 ------------------------------------------------------------------------ diff --git a/examples/run_simple_agent.sh b/examples/run_simple_agent.sh index 3112c27..20dafe5 100755 --- a/examples/run_simple_agent.sh +++ b/examples/run_simple_agent.sh @@ -88,6 +88,8 @@ echo " snmpget -v 2c -c public -M+. localhost:5555 SIMPLE-MIB::simpleInteger. 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 diff --git a/examples/simple_agent.py b/examples/simple_agent.py index b04d081..4acd3ff 100755 --- a/examples/simple_agent.py +++ b/examples/simple_agent.py @@ -234,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: