Skip to content
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
141 changes: 141 additions & 0 deletions examples/THREADING-CB-MIB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
THREADING-CB-MIB DEFINITIONS ::= BEGIN

------------------------------------------------------------------------
-- MIB for python-netsnmpagent's example threading_agent.py
-- Copyright (c) 2012-2016 Pieter Hollants <pieter@hollants.com>
-- Licensed under the GNU Lesser Public License (LGPL) version 3
------------------------------------------------------------------------

-- Imports
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE,
Integer32, Unsigned32, Counter32, Counter64, TimeTicks, IpAddress,
enterprises
FROM SNMPv2-SMI
TEXTUAL-CONVENTION, DisplayString
FROM SNMPv2-TC
MODULE-COMPLIANCE, OBJECT-GROUP, NOTIFICATION-GROUP
FROM SNMPv2-CONF
agentxObjects
FROM AGENTX-MIB;

-- Description and update information
threadingCBMIB MODULE-IDENTITY
LAST-UPDATED "201710230412Z"
ORGANIZATION "N/A"
CONTACT-INFO
"Editor:
Pieter Hollants
EMail: <pieter@hollants.com>"
DESCRIPTION
"A MIB for python-netsnmpagent's example threading_cb_agent.py"

REVISION "201710230412Z"
DESCRIPTION
"First version."

::= { agentxObjects 101 }

-- Definition of a generic ThreadingNotificationStatus type
ThreadingNotificationStatus ::= TEXTUAL-CONVENTION
STATUS current
DESCRIPTION
"Indicates the enabling or disabling of a particular class of
notifications."
SYNTAX INTEGER {
disabled (0), -- This class of notifications is disabled
enabled (1) -- This class of notifications is enabled
}

-- Definition of MIB's root nodes

threadingCBMIBObjects OBJECT IDENTIFIER ::= { threadingCBMIB 1 }
threadingCBMIBNotifications OBJECT IDENTIFIER ::= { threadingCBMIB 2 }
threadingCBMIBConformance OBJECT IDENTIFIER ::= { threadingCBMIB 3 }

threadingScalars OBJECT IDENTIFIER ::= { threadingCBMIBObjects 1 }

------------------------------------------------------------------------
-- Scalars
------------------------------------------------------------------------

threadingString OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"A string. Curious about its contents?"
::= { threadingScalars 1 }

threadingCBInteger OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"A read-write, 32-bits integer value."
::= { threadingScalars 2 }

threadingCBString OBJECT-TYPE
SYNTAX OctetString
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"A read-write string."
::= { threadingScalars 3 }


------------------------------------------------------------------------
-- Notifications
------------------------------------------------------------------------

events OBJECT IDENTIFIER ::= { threadingCBMIBNotifications 0 }
operation OBJECT IDENTIFIER ::= { threadingCBMIBNotifications 1 }

threadingStringChange NOTIFICATION-TYPE
OBJECTS {
threadingString
}
STATUS current
DESCRIPTION
"A threadingStringChange notification signifies that there has
been a change to the value of threadingString."
::= { events 1 }

threadingStringChangeNotificationsEnabled OBJECT-TYPE
SYNTAX ThreadingNotificationStatus
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Controls whether threadingStringChange notifications are
enabled or disabled."
::= { operation 1 }

------------------------------------------------------------------------
-- Conformance
------------------------------------------------------------------------

threadingMIBGroups OBJECT IDENTIFIER ::= { threadingCBMIBConformance 1 }

threadingMIBScalarsGroup OBJECT-GROUP
OBJECTS {
threadingString,
threadingCBInteger,
threadingCBString,
threadingStringChangeNotificationsEnabled
}
STATUS current
DESCRIPTION
"A collection of objects related to threadingScalars."
::= { threadingMIBGroups 1 }

threadingMIBScalarsNotificationsGroup NOTIFICATION-GROUP
NOTIFICATIONS {
threadingStringChange
}
STATUS current
DESCRIPTION
"The notifications which indicate specific changes in
threadingScalars."
::= { threadingMIBGroups 2 }

END
100 changes: 100 additions & 0 deletions examples/run_threading_cb_agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#
# python-netsnmpagent example agent with threading and callback
#
# Copyright (c) 2013-2016 Pieter Hollants <pieter@hollants.com>
# Licensed under the GNU Lesser Public License (LGPL) version 3
#

#
# This script makes running threading_agent.py easier for you because it takes
# care of setting everything up so that the example agent can be run
# successfully.
#

set -u
set -e

# Find path to snmpd executable
SNMPD_BIN=""
for DIR in /usr/local/sbin /usr/sbin
do
if [ -x $DIR/snmpd ] ; then
SNMPD_BIN=$DIR/snmpd
break
fi
done
if [ -z "$SNMPD_BIN" ] ; then
echo "snmpd executable not found -- net-snmp not installed?"
exit 1
fi

# Make sure we leave a clean system upon exit
cleanup() {
if [ -n "$TMPDIR" -a -d "$TMPDIR" ] ; then
# Terminate snmpd, if running
if [ -n "$SNMPD_PIDFILE" -a -e "$SNMPD_PIDFILE" ] ; then
PID="$(cat $SNMPD_PIDFILE)"
if [ -n "$PID" ] ; then
kill -TERM "$PID"
fi
fi

echo "* Cleaning up..."

# Clean up temporary directory
rm -rf "$TMPDIR"
fi

# Make sure echo is back on
stty echo
}
trap cleanup EXIT QUIT TERM INT HUP

echo "* Preparing snmpd environment..."

# Create a temporary directory
TMPDIR="$(mktemp --directory --tmpdir threading_agent.XXXXXXXXXX)"
SNMPD_CONFFILE=$TMPDIR/snmpd.conf
SNMPD_PIDFILE=$TMPDIR/snmpd.pid

# Create a minimal snmpd configuration for our purposes
cat <<EOF >>$SNMPD_CONFFILE
[snmpd]
rocommunity public 127.0.0.1
rwcommunity simple 127.0.0.1
agentaddress localhost:5555
informsink localhost:5556
smuxsocket localhost:5557
master agentx
agentXSocket $TMPDIR/snmpd-agentx.sock

[snmp]
persistentDir $TMPDIR/state
EOF
touch $TMPDIR/mib_indexes

# Start a snmpd instance for testing purposes, run as the current user and
# and independent from any other running snmpd instance
$SNMPD_BIN -r -LE warning -C -c$SNMPD_CONFFILE -p$SNMPD_PIDFILE

# Give the user guidance
echo "* Our snmpd instance is now listening on localhost, port 5555."
echo " From a second console, use the net-snmp command line utilities like this:"
echo ""
echo " cd `pwd`"
echo " snmpwalk -v 2c -c public -M+. localhost:5555 THREADING-CB-MIB::threadingMIB"
echo " snmpget -v 2c -c public -M+. localhost:5555 THREADING-CB-MIB::threadingString.0"
echo " To test the callbacks, read and write them:"
echo " snmpget -v 2c -c public -M+. localhost:5555 THREADING-CB-MIB::threadingCBString.0"
echo " snmpset -v 2c -c simple -M+. localhost:5555 THREADING-CB-MIB::threadingCBString.0 s \"test string\""
echo " snmpget -v 2c -c public -M+. localhost:5555 THREADING-CB-MIB::threadingCBInteger.0"
echo " snmpset -v 2c -c simple -M+. localhost:5555 THREADING-CB-MIB::threadingCBInteger.0 i 123456"
echo ""

# Workaround to have CTRL-C not generate any visual feedback (we don't do any
# input anyway)
stty -echo

# Now start the threading agent
echo "* Starting the threading agent..."
python threading_cb_agent.py -m $TMPDIR/snmpd-agentx.sock -p $TMPDIR/
Loading