jainvishal / agentx-tutorial

12 stars 8 forks source link

Warning: Failed to connect to the agentx master agent ([NIL]) #3

Open bernardoaraujor opened 7 years ago

bernardoaraujor commented 7 years ago

Hey Jain, it's me again. I hope I'm not annoying you too much.

I can't connect the subagent to the agent. What am I doing wrong?

bernardo@bernardo-ThinkCentre-Edge72:~$ git clone https://github.com/jainvishal/agentx-tutorial
Cloning into 'agentx-tutorial'...
remote: Counting objects: 89, done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 89 (delta 41), reused 89 (delta 41), pack-reused 0
Unpacking objects: 100% (89/89), done.
Checking connectivity... done.
bernardo@bernardo-ThinkCentre-Edge72:~$ cd agentx-tutorial/
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ git checkout step1_scalars_implement
Note: checking out 'step1_scalars_implement'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 0dcfcda... implement simple scalars
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ make -f agentxTutorial_makefile
make: agentxTutorial_makefile: No such file or directory
make: *** No rule to make target `agentxTutorial_makefile'.  Stop.
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ make -f agentxTutorial_Makefile
gcc -I. `net-snmp-config --base-cflags` -Wall -Wstrict-prototypes   -c -o agentxTutorial.o agentxTutorial.c
gcc -I. `net-snmp-config --base-cflags` -Wall -Wstrict-prototypes   -c -o agentxTutorial_subagent.o agentxTutorial_subagent.c
gcc -o agentxTutorial agentxTutorial.o agentxTutorial_subagent.o `net-snmp-config --agent-libs`
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ ps aux | grep snmpd
snmp      1253  0.0  0.0  45788  6452 ?        S    10:39   0:00 /usr/sbin/snmpd -Lsd -Lf /dev/null -u snmp -g snmp -I -smux mteTrigger mteTriggerConf -p /var/run/snmpd.pid
bernardo  3394  0.0  0.0  15964  2204 pts/1    S+   10:43   0:00 grep --color=auto snmpd
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ cat /etc/snmp/snmpd.conf 
cat: /etc/snmp/snmpd.conf: Permission denied
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ sudo cat /etc/snmp/snmpd.conf 
[sudo] password for bernardo: 
###############################################################################
#
# EXAMPLE.conf:
#   An example configuration file for configuring the Net-SNMP agent ('snmpd')
#   See the 'snmpd.conf(5)' man page for details
#
#  Some entries are deliberately commented out, and will need to be explicitly activated
#
###############################################################################
#
#  AGENT BEHAVIOUR
#

#  Listen for connections from the local system only
agentAddress  udp:127.0.0.1:161
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
#agentAddress udp:161,udp6:[::1]:161

###############################################################################
#
#  SNMPv3 AUTHENTICATION
#
#  Note that these particular settings don't actually belong here.
#  They should be copied to the file /var/lib/snmp/snmpd.conf
#     and the passwords changed, before being uncommented in that file *only*.
#  Then restart the agent

#  createUser authOnlyUser  MD5 "remember to change this password"
#  createUser authPrivUser  SHA "remember to change this one too"  DES
#  createUser internalUser  MD5 "this is only ever used internally, but still change the password"

#  If you also change the usernames (which might be sensible),
#  then remember to update the other occurances in this example config file to match.

###############################################################################
#
#  ACCESS CONTROL
#

                                                 #  system + hrSystem groups only
view   systemonly  included   .1.3.6.1.2.1.1
view   systemonly  included   .1.3.6.1.2.1.25.1

                                                 #  Full access from the local host
#rocommunity public  localhost
                                                 #  Default access to basic system info
 rocommunity public  default    -V systemonly

                                                 #  Full access from an example network
                                                 #     Adjust this network address to match your local
                                                 #     settings, change the community string,
                                                 #     and check the 'agentAddress' setting above
#rocommunity secret  10.0.0.0/16

                                                 #  Full read-only access for SNMPv3
 rouser   authOnlyUser
                                                 #  Full write access for encrypted requests
                                                 #     Remember to activate the 'createUser' lines above
#rwuser   authPrivUser   priv

#  It's no longer typically necessary to use the full 'com2sec/group/access' configuration
#  r[ow]user and r[ow]community, together with suitable views, should cover most requirements

###############################################################################
#
#  SYSTEM INFORMATION
#

#  Note that setting these values here, results in the corresponding MIB objects being 'read-only'
#  See snmpd.conf(5) for more details
sysLocation    Sitting on the Dock of the Bay
sysContact     Me <me@example.org>
                                                 # Application + End-to-End layers
sysServices    72

#
#  Process Monitoring
#
                               # At least one  'mountd' process
proc  mountd
                               # No more than 4 'ntalkd' processes - 0 is OK
proc  ntalkd    4
                               # At least one 'sendmail' process, but no more than 10
proc  sendmail 10 1

#  Walk the UCD-SNMP-MIB::prTable to see the resulting output
#  Note that this table will be empty if there are no "proc" entries in the snmpd.conf file

#
#  Disk Monitoring
#
                               # 10MBs required on root disk, 5% free on /var, 10% free on all other disks
disk       /     10000
disk       /var  5%
includeAllDisks  10%

#  Walk the UCD-SNMP-MIB::dskTable to see the resulting output
#  Note that this table will be empty if there are no "disk" entries in the snmpd.conf file

#
#  System Load
#
                               # Unacceptable 1-, 5-, and 15-minute load averages
load   12 10 5

#  Walk the UCD-SNMP-MIB::laTable to see the resulting output
#  Note that this table *will* be populated, even without a "load" entry in the snmpd.conf file

###############################################################################
#
#  ACTIVE MONITORING
#

                                    #   send SNMPv1  traps
 trapsink     localhost public
                                    #   send SNMPv2c traps
#trap2sink    localhost public
                                    #   send SNMPv2c INFORMs
#informsink   localhost public

#  Note that you typically only want *one* of these three lines
#  Uncommenting two (or all three) will result in multiple copies of each notification.

#
#  Event MIB - automatically generate alerts
#
                                   # Remember to activate the 'createUser' lines above
iquerySecName   internalUser       
rouser          internalUser
                                   # generate traps on UCD error conditions
defaultMonitors          yes
                                   # generate traps on linkUp/Down
linkUpDownNotifications  yes

###############################################################################
#
#  EXTENDING THE AGENT
#

#
#  Arbitrary extension commands
#
 extend    test1   /bin/echo  Hello, world!
 extend-sh test2   echo Hello, world! ; echo Hi there ; exit 35
#extend-sh test3   /bin/sh /tmp/shtest

#  Note that this last entry requires the script '/tmp/shtest' to be created first,
#    containing the same three shell commands, before the line is uncommented

#  Walk the NET-SNMP-EXTEND-MIB tables (nsExtendConfigTable, nsExtendOutput1Table
#     and nsExtendOutput2Table) to see the resulting output

#  Note that the "extend" directive supercedes the previous "exec" and "sh" directives
#  However, walking the UCD-SNMP-MIB::extTable should still returns the same output,
#     as well as the fuller results in the above tables.

#
#  "Pass-through" MIB extension command
#
#pass .1.3.6.1.4.1.8072.2.255  /bin/sh       PREFIX/local/passtest
#pass .1.3.6.1.4.1.8072.2.255  /usr/bin/perl PREFIX/local/passtest.pl

# Note that this requires one of the two 'passtest' scripts to be installed first,
#    before the appropriate line is uncommented.
# These scripts can be found in the 'local' directory of the source distribution,
#     and are not installed automatically.

#  Walk the NET-SNMP-PASS-MIB::netSnmpPassExamples subtree to see the resulting output

#
#  AgentX Sub-agents
#
                                           #  Run as an AgentX master agent
 master          agentx
                                           #  Listen for network connections (from localhost)
                                           #    rather than the default named socket /var/agentx/master
#agentXSocket    tcp:localhost:705
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ ls
agentxTutorial  agentxTutorial.c  agentxTutorial.h  agentxTutorial_Makefile  AGENTX-TUTORIAL-MIB  agentxTutorial.o  agentxTutorial_subagent.c  agentxTutorial_subagent.o  CMakeLists.txt  README.md
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ ./agentxTutorial 
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 
Warning: Failed to connect to the agentx master agent ([NIL]): 

In another terminal:

bernardo@bernardo-ThinkCentre-Edge72:~$ snmpwalk -On localhost agentxTutorial
agentxTutorial: Unknown Object Identifier (Sub-id not found: (top) -> agentxTutorial)
bernardoaraujor commented 7 years ago

In fact, I'm trying to compile a subagent to an Embedded Linux environment. The logs above were generated in my host machine (the one I'm using for the development).

When I try this in the Embedded Linux environment, the only difference is that I can connect the subagent to the agent. However, the OID is not recognized as well.

root@sama5d2-xplained:~# cat /etc/snmp/snmpd.conf 
###############################################################################
#
# EXAMPLE.conf:
#   An example configuration file for configuring the ucd-snmp snmpd agent.
#
###############################################################################
#
# This file is intended to only be an example.  If, however, you want
# to use it, it should be placed in /etc/snmp/snmpd.conf.
# When the snmpd agent starts up, this is where it will look for it.
#
# You might be interested in generating your own snmpd.conf file using
# the "snmpconf" program (perl script) instead.  It's a nice menu
# based interface to writing well commented configuration files.  Try it!
#
# Note: This file is automatically generated from EXAMPLE.conf.def.
# Do NOT read the EXAMPLE.conf.def file! Instead, after you have run
# configure & make, and then make sure you read the EXAMPLE.conf file
# instead, as it will tailor itself to your configuration.

# All lines beginning with a '#' are comments and are intended for you
# to read.  All other lines are configuration commands for the agent.

#
# PLEASE: read the snmpd.conf(5) manual page as well!
#

###############################################################################
# Access Control
###############################################################################

# YOU SHOULD CHANGE THE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY
# KNOWN AT YOUR SITE.  YOU *MUST* CHANGE THE NETWORK TOKEN BELOW TO
# SOMETHING REFLECTING YOUR LOCAL NETWORK ADDRESS SPACE.

# By far, the most common question I get about the agent is "why won't
# it work?", when really it should be "how do I configure the agent to
# allow me to access it?"
#
# By default, the agent responds to the "public" community for read
# only access, if run out of the box without any configuration file in
# place.  The following examples show you other ways of configuring
# the agent so that you can change the community names, and give
# yourself write access as well.
#
# The following lines change the access permissions of the agent so
# that the COMMUNITY string provides read-only access to your entire
# NETWORK (EG: 10.10.10.0/24), and read/write access to only the
# localhost (127.0.0.1, not its real ipaddress).
#
# For more information, read the FAQ as well as the snmpd.conf(5)
# manual page.

####
# First, map the community name (COMMUNITY) into a security name
# (local and mynetwork, depending on where the request is coming
# from):

#       sec.name  source          community
com2sec paranoid  default         public
#com2sec readonly  default         public
#com2sec readwrite default         private

####
# Second, map the security names into group names:

#               sec.model  sec.name
group MyROSystem v1        paranoid
group MyROSystem v2c       paranoid
group MyROSystem usm       paranoid
group MyROGroup v1         readonly
group MyROGroup v2c        readonly
group MyROGroup usm        readonly
group MyRWGroup v1         readwrite
group MyRWGroup v2c        readwrite
group MyRWGroup usm        readwrite

####
# Third, create a view for us to let the groups have rights to:

#           incl/excl subtree                          mask
view all    included  .1                               80
view system included  .iso.org.dod.internet.mgmt.mib-2.system

####
# Finally, grant the 2 groups access to the 1 view with different
# write permissions:

#                context sec.model sec.level match  read   write  notif
access MyROSystem ""     any       noauth    exact  system none   none
access MyROGroup ""      any       noauth    exact  all    none   none
access MyRWGroup ""      any       noauth    exact  all    all    none

# -----------------------------------------------------------------------------

###############################################################################
# System contact information
#

# It is also possible to set the sysContact and sysLocation system
# variables through the snmpd.conf file.  **PLEASE NOTE** that setting
# the value of these objects here makes these objects READ-ONLY
# (regardless of any access control settings).  Any attempt to set the
# value of an object whose value is given here will fail with an error
# status of notWritable.

syslocation Unknown (configure /etc/snmp/snmpd.local.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmpd.local.conf)

# Example output of snmpwalk:
#   % snmpwalk -v 1 -c public localhost system
#   system.sysDescr.0 = "SunOS name sun4c"
#   system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.sunos4
#   system.sysUpTime.0 = Timeticks: (595637548) 68 days, 22:32:55
#   system.sysContact.0 = "Me <me@somewhere.org>"
#   system.sysName.0 = "name"
#   system.sysLocation.0 = "Right here, right now."
#   system.sysServices.0 = 72

# -----------------------------------------------------------------------------

###############################################################################
# Process checks.
#
#  The following are examples of how to use the agent to check for
#  processes running on the host.  The syntax looks something like:
#
#  proc NAME [MAX=0] [MIN=0]
#
#  NAME:  the name of the process to check for.  It must match
#         exactly (ie, http will not find httpd processes).
#  MAX:   the maximum number allowed to be running.  Defaults to 0.
#  MIN:   the minimum number to be running.  Defaults to 0.

#
#  Examples:
#

#  Make sure mountd is running
#proc mountd

#  Make sure there are no more than 4 ntalkds running, but 0 is ok too.
#proc ntalkd 4

#  Make sure at least one sendmail, but less than or equal to 10 are running.
#proc sendmail 10 1

#  A snmpwalk of the prTable would look something like this:
#
# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.2
# enterprises.ucdavis.procTable.prEntry.prIndex.1 = 1
# enterprises.ucdavis.procTable.prEntry.prIndex.2 = 2
# enterprises.ucdavis.procTable.prEntry.prIndex.3 = 3
# enterprises.ucdavis.procTable.prEntry.prNames.1 = "mountd"
# enterprises.ucdavis.procTable.prEntry.prNames.2 = "ntalkd"
# enterprises.ucdavis.procTable.prEntry.prNames.3 = "sendmail"
# enterprises.ucdavis.procTable.prEntry.prMin.1 = 0
# enterprises.ucdavis.procTable.prEntry.prMin.2 = 0
# enterprises.ucdavis.procTable.prEntry.prMin.3 = 1
# enterprises.ucdavis.procTable.prEntry.prMax.1 = 0
# enterprises.ucdavis.procTable.prEntry.prMax.2 = 4
# enterprises.ucdavis.procTable.prEntry.prMax.3 = 10
# enterprises.ucdavis.procTable.prEntry.prCount.1 = 0
# enterprises.ucdavis.procTable.prEntry.prCount.2 = 0
# enterprises.ucdavis.procTable.prEntry.prCount.3 = 1
# enterprises.ucdavis.procTable.prEntry.prErrorFlag.1 = 1
# enterprises.ucdavis.procTable.prEntry.prErrorFlag.2 = 0
# enterprises.ucdavis.procTable.prEntry.prErrorFlag.3 = 0
# enterprises.ucdavis.procTable.prEntry.prErrMessage.1 = "No mountd process running."
# enterprises.ucdavis.procTable.prEntry.prErrMessage.2 = ""
# enterprises.ucdavis.procTable.prEntry.prErrMessage.3 = ""
# enterprises.ucdavis.procTable.prEntry.prErrFix.1 = 0
# enterprises.ucdavis.procTable.prEntry.prErrFix.2 = 0
# enterprises.ucdavis.procTable.prEntry.prErrFix.3 = 0
#
#  Note that the errorFlag for mountd is set to 1 because one is not
#  running (in this case an rpc.mountd is, but thats not good enough),
#  and the ErrMessage tells you what's wrong.  The configuration
#  imposed in the snmpd.conf file is also shown.
#
#  Special Case:  When the min and max numbers are both 0, it assumes
#  you want a max of infinity and a min of 1.
#

# -----------------------------------------------------------------------------

###############################################################################
# Executables/scripts
#

#
#  You can also have programs run by the agent that return a single
#  line of output and an exit code.  Here are two examples.
#
#  exec NAME PROGRAM [ARGS ...]
#
#  NAME:     A generic name.
#  PROGRAM:  The program to run.  Include the path!
#  ARGS:     optional arguments to be passed to the program

# a simple hello world
#exec echotest /bin/echo hello world

# Run a shell script containing:
#
# #!/bin/sh
# echo hello world
# echo hi there
# exit 35
#
# Note:  this has been specifically commented out to prevent
# accidental security holes due to someone else on your system writing
# a /tmp/shtest before you do.  Uncomment to use it.
#
#exec shelltest /bin/sh /tmp/shtest

# Then,
# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.8
# enterprises.ucdavis.extTable.extEntry.extIndex.1 = 1
# enterprises.ucdavis.extTable.extEntry.extIndex.2 = 2
# enterprises.ucdavis.extTable.extEntry.extNames.1 = "echotest"
# enterprises.ucdavis.extTable.extEntry.extNames.2 = "shelltest"
# enterprises.ucdavis.extTable.extEntry.extCommand.1 = "/bin/echo hello world"
# enterprises.ucdavis.extTable.extEntry.extCommand.2 = "/bin/sh /tmp/shtest"
# enterprises.ucdavis.extTable.extEntry.extResult.1 = 0
# enterprises.ucdavis.extTable.extEntry.extResult.2 = 35
# enterprises.ucdavis.extTable.extEntry.extOutput.1 = "hello world."
# enterprises.ucdavis.extTable.extEntry.extOutput.2 = "hello world."
# enterprises.ucdavis.extTable.extEntry.extErrFix.1 = 0
# enterprises.ucdavis.extTable.extEntry.extErrFix.2 = 0

# Note that the second line of the /tmp/shtest shell script is cut
# off.  Also note that the exit status of 35 was returned.

# -----------------------------------------------------------------------------

###############################################################################
# disk checks
#

# The agent can check the amount of available disk space, and make
# sure it is above a set limit.

# disk PATH [MIN=DEFDISKMINIMUMSPACE]
#
# PATH:  mount path to the disk in question.
# MIN:   Disks with space below this value will have the Mib's errorFlag set.
#        Default value = DEFDISKMINIMUMSPACE.

# Check the / partition and make sure it contains at least 10 megs.

#disk / 10000

# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.9
# enterprises.ucdavis.diskTable.dskEntry.diskIndex.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskPath.1 = "/" Hex: 2F
# enterprises.ucdavis.diskTable.dskEntry.diskDevice.1 = "/dev/dsk/c201d6s0"
# enterprises.ucdavis.diskTable.dskEntry.diskMinimum.1 = 10000
# enterprises.ucdavis.diskTable.dskEntry.diskTotal.1 = 837130
# enterprises.ucdavis.diskTable.dskEntry.diskAvail.1 = 316325
# enterprises.ucdavis.diskTable.dskEntry.diskUsed.1 = 437092
# enterprises.ucdavis.diskTable.dskEntry.diskPercent.1 = 58
# enterprises.ucdavis.diskTable.dskEntry.diskErrorFlag.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskErrorMsg.1 = ""

# -----------------------------------------------------------------------------

###############################################################################
# load average checks
#

# load [1MAX=DEFMAXLOADAVE] [5MAX=DEFMAXLOADAVE] [15MAX=DEFMAXLOADAVE]
#
# 1MAX:   If the 1 minute load average is above this limit at query
#         time, the errorFlag will be set.
# 5MAX:   Similar, but for 5 min average.
# 15MAX:  Similar, but for 15 min average.

# Check for loads:
#load 12 14 14

# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.10
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.1 = 1
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.2 = 2
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.3 = 3
# enterprises.ucdavis.loadTable.laEntry.loadaveNames.1 = "Load-1"
# enterprises.ucdavis.loadTable.laEntry.loadaveNames.2 = "Load-5"
# enterprises.ucdavis.loadTable.laEntry.loadaveNames.3 = "Load-15"
# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.1 = "0.49" Hex: 30 2E 34 39
# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.2 = "0.31" Hex: 30 2E 33 31
# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.3 = "0.26" Hex: 30 2E 32 36
# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.1 = "12.00"
# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.2 = "14.00"
# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.3 = "14.00"
# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.1 = 0
# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.2 = 0
# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.3 = 0
# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.1 = ""
# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.2 = ""
# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.3 = ""

# -----------------------------------------------------------------------------

###############################################################################
# Extensible sections.
#

# This alleviates the multiple line output problem found in the
# previous executable mib by placing each mib in its own mib table:

# Run a shell script containing:
#
# #!/bin/sh
# echo hello world
# echo hi there
# exit 35
#
# Note:  this has been specifically commented out to prevent
# accidental security holes due to someone else on your system writing
# a /tmp/shtest before you do.  Uncomment to use it.
#
# exec .1.3.6.1.4.1.2021.50 shelltest /bin/sh /tmp/shtest

# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.50
# enterprises.ucdavis.50.1.1 = 1
# enterprises.ucdavis.50.2.1 = "shelltest"
# enterprises.ucdavis.50.3.1 = "/bin/sh /tmp/shtest"
# enterprises.ucdavis.50.100.1 = 35
# enterprises.ucdavis.50.101.1 = "hello world."
# enterprises.ucdavis.50.101.2 = "hi there."
# enterprises.ucdavis.50.102.1 = 0

# Now the Output has grown to two lines, and we can see the 'hi
# there.' output as the second line from our shell script.
#
# Note that you must alter the mib.txt file to be correct if you want
# the .50.* outputs above to change to reasonable text descriptions.

# Other ideas:
#
# exec .1.3.6.1.4.1.2021.51 ps /bin/ps
# exec .1.3.6.1.4.1.2021.52 top /usr/local/bin/top
# exec .1.3.6.1.4.1.2021.53 mailq /usr/bin/mailq

# -----------------------------------------------------------------------------

###############################################################################
# Pass through control.
#

# Usage:
#   pass MIBOID EXEC-COMMAND
#
# This will pass total control of the mib underneath the MIBOID
# portion of the mib to the EXEC-COMMAND.
#
# Note:  You'll have to change the path of the passtest script to your
# source directory or install it in the given location.
#
# Example:  (see the script for details)
#           (commented out here since it requires that you place the
#           script in the right location. (its not installed by default))

# pass .1.3.6.1.4.1.2021.255 /bin/sh /usr/local/passtest

# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.255
# enterprises.ucdavis.255.1 = "life the universe and everything"
# enterprises.ucdavis.255.2.1 = 42
# enterprises.ucdavis.255.2.2 = OID: 42.42.42
# enterprises.ucdavis.255.3 = Timeticks: (363136200) 42 days, 0:42:42
# enterprises.ucdavis.255.4 = IpAddress: 127.0.0.1
# enterprises.ucdavis.255.5 = 42
# enterprises.ucdavis.255.6 = Gauge: 42
#
# % snmpget -v 1 -c public localhost .1.3.6.1.4.1.2021.255.5
# enterprises.ucdavis.255.5 = 42
#
# % snmpset -v 1 -c public localhost .1.3.6.1.4.1.2021.255.1 s "New string"
# enterprises.ucdavis.255.1 = "New string"
#

# For specific usage information, see the man/snmpd.conf.5 manual page
# as well as the local/passtest script used in the above example.

###############################################################################
# Subagent control
#

# The agent can support subagents using a number of extension mechanisms.
# From the 4.2.1 release, AgentX support is being compiled in by default.
# However, this is still experimental code, so should not be used on
# critical production systems.
#   Please see the file README.agentx for more details.
#
# If having read, marked, learnt and inwardly digested this information,
# you decide that you do wish to make use of this mechanism, simply
# uncomment the following directive.
#
master  agentx
#
# I repeat - this is *NOT* regarded as suitable for front-line production
# systems, though it is probably stable enough for day-to-day use.
# Probably.
#
# No refunds will be given.

###############################################################################
# Further Information
#
#  See the snmpd.conf manual page, and the output of "snmpd -H".
#  MUCH more can be done with the snmpd.conf than is shown as an
#  example here.
root@sama5d2-xplained:~# 
root@sama5d2-xplained:~# 
root@sama5d2-xplained:~# 
root@sama5d2-xplained:~# agentxTutorial 
root@sama5d2-xplained:~# NET-SNMP version 5.7.3 AgentX subagent connected

root@sama5d2-xplained:~# 
root@sama5d2-xplained:~# 
root@sama5d2-xplained:~# 
root@sama5d2-xplained:~# snmpwalk -On localhost agentxTutorial
agentxTutorial: Unknown Object Identifier (Sub-id not found: (top) -> agentxTutorial)
root@sama5d2-xplained:~# ps | grep snmpd
  310 root      8116 S    /usr/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd.pid
  335 root      2732 S    grep snmpd
root@sama5d2-xplained:~# ps | grep agentxTutorial
  331 root      4872 S    agentxTutorial
  337 root      2732 S    grep agentxTutorial
bernardoaraujor commented 7 years ago

Forgot to mention: the MIB is in /usr/share/snmp/mibs in the Embedded Linux:

root@sama5d2-xplained:~# ps | grep snmpd
  308 root      8120 S    /usr/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd.pid
  341 root      2732 S    grep snmpd
root@sama5d2-xplained:~# ps | grep agentxTutorial
  328 root      4872 S    agentxTutorial
  344 root      2732 S    grep agentxTutorial
root@sama5d2-xplained:~# ls /usr/share/snmp/mibs/
AGENTX-MIB.txt                       IANAifType-MIB.txt                   NET-SNMP-EXAMPLES-MIB.txt            SNMP-COMMUNITY-MIB.txt               SNMPv2-MIB.txt
AGENTX-TUTORIAL-MIB.txt              IF-INVERTED-STACK-MIB.txt            NET-SNMP-EXTEND-MIB.txt              SNMP-FRAMEWORK-MIB.txt               SNMPv2-SMI.txt
BRIDGE-MIB.txt                       IF-MIB.txt                           NET-SNMP-MIB.txt                     SNMP-MPD-MIB.txt                     SNMPv2-TC.txt
DISMAN-EVENT-MIB.txt                 INET-ADDRESS-MIB.txt                 NET-SNMP-PASS-MIB.txt                SNMP-NOTIFICATION-MIB.txt            SNMPv2-TM.txt
DISMAN-SCHEDULE-MIB.txt              IP-FORWARD-MIB.txt                   NET-SNMP-TC.txt                      SNMP-PROXY-MIB.txt                   TCP-MIB.txt
DISMAN-SCRIPT-MIB.txt                IP-MIB.txt                           NET-SNMP-VACM-MIB.txt                SNMP-TARGET-MIB.txt                  TRANSPORT-ADDRESS-MIB.txt
EtherLike-MIB.txt                    IPV6-FLOW-LABEL-MIB.txt              NOTIFICATION-LOG-MIB.txt             SNMP-TLS-TM-MIB.txt                  TUNNEL-MIB.txt
HCNUM-TC.txt                         IPV6-ICMP-MIB.txt                    RFC-1215.txt                         SNMP-TSM-MIB.txt                     UCD-DEMO-MIB.txt
HOST-RESOURCES-MIB.txt               IPV6-MIB.txt                         RFC1155-SMI.txt                      SNMP-USER-BASED-SM-MIB.txt           UCD-DISKIO-MIB.txt
HOST-RESOURCES-TYPES.txt             IPV6-TC.txt                          RFC1213-MIB.txt                      SNMP-USM-AES-MIB.txt                 UCD-DLMOD-MIB.txt
IANA-ADDRESS-FAMILY-NUMBERS-MIB.txt  IPV6-TCP-MIB.txt                     RMON-MIB.txt                         SNMP-USM-DH-OBJECTS-MIB.txt          UCD-IPFWACC-MIB.txt
IANA-LANGUAGE-MIB.txt                IPV6-UDP-MIB.txt                     SCTP-MIB.txt                         SNMP-VIEW-BASED-ACM-MIB.txt          UCD-SNMP-MIB.txt
IANA-RTPROTO-MIB.txt                 NET-SNMP-AGENT-MIB.txt               SMUX-MIB.txt                         SNMPv2-CONF.txt                      UDP-MIB.txt
root@sama5d2-xplained:~# snmpget -On localhost agentxTutorial
agentxTutorial: Unknown Object Identifier (Sub-id not found: (top) -> agentxTutorial)
jainvishal commented 7 years ago

Please try to run your agent as root user. If you want to run your agent as another user, e.g. yourself, you need to configure snmpd to allow a non-root user to connect. By default Net-SNMP uses named socket for AgentX communication which does not allow a non-root user to connect. There are security reasons for not allowing this kind of widely open access so do not set this up in your production environment. Instead you can set this up to use TCP communication. Please see my blog post http://theunixtips.com/net-snmp-configuration-for-non-root-agentx-application/ which describes the changes that you would need. Let me know if this helps.

And don't worry about the questions. As I said before, keep them coming :-). This helps me to keep my memory refreshed as well.

On Thu, Aug 10, 2017 at 10:39 AM bernardo rodrigues < notifications@github.com> wrote:

Forgot to mention: the MIB is in /usr/share/snmp/mibs in the Embedded Linux:

root@sama5d2-xplained:~# ps | grep snmpd 308 root 8120 S /usr/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd.pid 341 root 2732 S grep snmpd root@sama5d2-xplained:~# ps | grep agentxTutorial 328 root 4872 S agentxTutorial 344 root 2732 S grep agentxTutorial root@sama5d2-xplained:~# ls /usr/share/snmp/mibs/ AGENTX-MIB.txt IANAifType-MIB.txt NET-SNMP-EXAMPLES-MIB.txt SNMP-COMMUNITY-MIB.txt SNMPv2-MIB.txt AGENTX-TUTORIAL-MIB.txt IF-INVERTED-STACK-MIB.txt NET-SNMP-EXTEND-MIB.txt SNMP-FRAMEWORK-MIB.txt SNMPv2-SMI.txt BRIDGE-MIB.txt IF-MIB.txt NET-SNMP-MIB.txt SNMP-MPD-MIB.txt SNMPv2-TC.txt DISMAN-EVENT-MIB.txt INET-ADDRESS-MIB.txt NET-SNMP-PASS-MIB.txt SNMP-NOTIFICATION-MIB.txt SNMPv2-TM.txt DISMAN-SCHEDULE-MIB.txt IP-FORWARD-MIB.txt NET-SNMP-TC.txt SNMP-PROXY-MIB.txt TCP-MIB.txt DISMAN-SCRIPT-MIB.txt IP-MIB.txt NET-SNMP-VACM-MIB.txt SNMP-TARGET-MIB.txt TRANSPORT-ADDRESS-MIB.txt EtherLike-MIB.txt IPV6-FLOW-LABEL-MIB.txt NOTIFICATION-LOG-MIB.txt SNMP-TLS-TM-MIB.txt TUNNEL-MIB.txt HCNUM-TC.txt IPV6-ICMP-MIB.txt RFC-1215.txt SNMP-TSM-MIB.txt UCD-DEMO-MIB.txt HOST-RESOURCES-MIB.txt IPV6-MIB.txt RFC1155-SMI.txt SNMP-USER-BASED-SM-MIB.txt UCD-DISKIO-MIB.txt HOST-RESOURCES-TYPES.txt IPV6-TC.txt RFC1213-MIB.txt SNMP-USM-AES-MIB.txt UCD-DLMOD-MIB.txt IANA-ADDRESS-FAMILY-NUMBERS-MIB.txt IPV6-TCP-MIB.txt RMON-MIB.txt SNMP-USM-DH-OBJECTS-MIB.txt UCD-IPFWACC-MIB.txt IANA-LANGUAGE-MIB.txt IPV6-UDP-MIB.txt SCTP-MIB.txt SNMP-VIEW-BASED-ACM-MIB.txt UCD-SNMP-MIB.txt IANA-RTPROTO-MIB.txt NET-SNMP-AGENT-MIB.txt SMUX-MIB.txt SNMPv2-CONF.txt UDP-MIB.txt root@sama5d2-xplained:~# snmpget -On localhost agentxTutorial agentxTutorial: Unknown Object Identifier (Sub-id not found: (top) -> agentxTutorial)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jainvishal/agentx-tutorial/issues/3#issuecomment-321571449, or mute the thread https://github.com/notifications/unsubscribe-auth/AIEQKUUZ-MlQVsSUbnPmXNljZ6h75frqks5sWxYkgaJpZM4Ozc7x .

bernardoaraujor commented 7 years ago

Yesterday I was trying to compile the whole snmpd from source in my host and I screwed up my installation. Now I have to fix it before I can try it again.

jainvishal commented 7 years ago

You would be better to use stock snmpd in the beginning. That will speed up your development.

On Fri, Aug 11, 2017, 8:59 AM bernardo rodrigues notifications@github.com wrote:

Yesterday I was trying to compile the whole snmpd from source in my host and I screwed up my installation. Now I have to fix it before I can try it again.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/jainvishal/agentx-tutorial/issues/3#issuecomment-321805775, or mute the thread https://github.com/notifications/unsubscribe-auth/AIEQKaOIictTpB2uOh_BiO7TapYJvOvJks5sXFAxgaJpZM4Ozc7x .

bernardoaraujor commented 7 years ago

I was trying to compile a MIB Module (following http://net-snmp.sourceforge.net/tutorial/tutorial-5/toolkit/mib_module/index.html). No success as well.

My sysadmin skills are also a bit weak. Do you know how to fix this? Note that I compiled v5.4.5. I've already run sudo make uninstall, but I didn't paste the log here cause it was too big.

bernardo@bernardo-ThinkCentre-Edge72:~/net-snmp-5.4.5.pre2$ sudo dpkg --force-all --purge snmpd
(Reading database ... 507600 files and directories currently installed.)
Removing snmpd (5.7.2~dfsg-8.1ubuntu3.2) ...
 * Stopping network management services:                                                                                                                                                                     Purging configuration files for snmpd (5.7.2~dfsg-8.1ubuntu3.2) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
bernardo@bernardo-ThinkCentre-Edge72:~/net-snmp-5.4.5.pre2$ sudo apt-get purge snmpd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'snmpd' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  libmysqlclient18 mysql-common
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
bernardo@bernardo-ThinkCentre-Edge72:~/net-snmp-5.4.5.pre2$ sudo apt-get install snmpd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  snmpd
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 0 B/73,3 kB of archives.
After this operation, 232 kB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously unselected package snmpd.
(Reading database ... 507569 files and directories currently installed.)
Preparing to unpack .../snmpd_5.7.2~dfsg-8.1ubuntu3.2_amd64.deb ...
Unpacking snmpd (5.7.2~dfsg-8.1ubuntu3.2) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up snmpd (5.7.2~dfsg-8.1ubuntu3.2) ...
update-rc.d: warning:  stop runlevel arguments (1) do not match snmpd Default-Stop values (0 1 6)
 * Starting network management services:                                                                                                                                                                     /usr/sbin/snmpd: error while loading shared libraries: libnetsnmpagent.so.30: cannot open shared object file: No such file or directory
invoke-rc.d: initscript snmpd, action "start" failed.
dpkg: error processing package snmpd (--configure):
 subprocess installed post-installation script returned error exit status 127
Processing triggers for ureadahead (0.100.0-16) ...
Errors were encountered while processing:
 snmpd
E: Sub-process /usr/bin/dpkg returned an error code (1)
bernardoaraujor commented 7 years ago

Anyways, my Embedded Linux environment only has root user... And indeed, the subagent did connect to the master agent. But the snmpwalk command did not work anyways. Perhaps it's a access control issue?

jainvishal commented 7 years ago

My next suggestion is to run tcpdump if you have on your embedded system and capture traffic on the agentx port. That will tell you if it is your agent or snmpd that is having issues. Better approach would still be to sort this out on a different system where you have better access to the tools.

On Fri, Aug 11, 2017, 9:18 AM bernardo rodrigues notifications@github.com wrote:

Anyways, my Embedded Linux environment only has root user... And indeed, the subagent did connect to the master agent. But the snmpwalk command did not work anyways. Perhaps it's a access control issue?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/jainvishal/agentx-tutorial/issues/3#issuecomment-321809656, or mute the thread https://github.com/notifications/unsubscribe-auth/AIEQKVtrAbRrQ4vPaSEBDWKV85CB0zrnks5sXFSYgaJpZM4Ozc7x .

bernardoaraujor commented 7 years ago

I did a fresh install of Ubuntu 14 on my host machine.

bernardo@bernardo-ThinkCentre-Edge72:~$ git clone https://github.com/jainvishal/agentx-tutorial
Cloning into 'agentx-tutorial'...
remote: Counting objects: 89, done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 89 (delta 41), reused 89 (delta 41), pack-reused 0
Unpacking objects: 100% (89/89), done.
Checking connectivity... done.
bernardo@bernardo-ThinkCentre-Edge72:~$ cd agentx-tutorial/
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ git checkout step1_scalars_implement
Note: checking out 'step1_scalars_implement'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 0dcfcda... implement simple scalars
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ make -f agentxTutorial_Makefile 
gcc -I. `net-snmp-config --base-cflags` -Wall -Wstrict-prototypes   -c -o agentxTutorial.o agentxTutorial.c
gcc -I. `net-snmp-config --base-cflags` -Wall -Wstrict-prototypes   -c -o agentxTutorial_subagent.o agentxTutorial_subagent.c
gcc -o agentxTutorial agentxTutorial.o agentxTutorial_subagent.o `net-snmp-config --agent-libs`
bernardo@bernardo-ThinkCentre-Edge72:~/agentx-tutorial$ sudo ./agentxTutorial -f
NET-SNMP version 5.7.2 AgentX subagent connected

Then in another terminal:

bernardo@bernardo-ThinkCentre-Edge72:~$ snmpwalk -v2c -c public -On localhost agentxTutorial
.1.3.6.1.3.9999 = No more variables left in this MIB View (It is past the end of the MIB tree)
bernardo@bernardo-ThinkCentre-Edge72:~$ snmpwalk -v2c -c public -On localhost AGENTX-TUTORIAL-MIB::agentxTutorial
.1.3.6.1.3.9999 = No more variables left in this MIB View (It is past the end of the MIB tree)
bernardo@bernardo-ThinkCentre-Edge72:~$ snmptranslate -Tp -IR agentxTutorial
+--agentxTutorial(9999)
   |
   +--myScalars(1)
   |  |
   |  +-- -R-- String    myROString(1)
   |  |        Textual Convention: DisplayString
   |  |        Size: 0..255
   |  +-- -R-- Integer32 myROInteger(2)
   |           Range: 0..2147483647
   |
   +--myConformenceGroups(99)
      |
      +--myScalarGroup(1)
bernardo@bernardo-ThinkCentre-Edge72:~$ 
jayshankarnair commented 5 years ago

./agentxTutorial -f unknown snmp version 193 NET-SNMP version 5.8 AgentX subagent connected registering pdu failed: 263! registering pdu failed: 263! registering pdu failed: 263! Warning: Failed to connect to the agentx master agent ([NIL]): Warning: Failed to connect to the agentx master agent ([NIL]): Warning: Failed to connect to the agentx master agent ([NIL]):

snmpd -f -Lo -Dagentx registered debug token agentx, 1 agentx_register_app_config_handler: registering .conf token for "agentxsocket" agentx_register_app_config_handler: registering .conf token for "agentxperms" agentx_register_app_config_handler: registering .conf token for "agentxRetries" agentx_register_app_config_handler: registering .conf token for "agentxTimeout" Turning on AgentX master support. agentx/master: initializing... agentx/master: initializing... DONE NET-SNMP version 5.8 agentx/master: transport connect on session 0x1e4cf80 agentx/master: handle pdu (req=0x75fe7027,trans=0x0,sess=0x0) agentx/master: open 0x1e4cf80 agentx/master: opened 0x1e5e7a0 = 6 with flags = a0 agentx/master: send response, stat 0 (req=0x75fe7027,trans=0x0,sess=0x0) agentx_build: packet built okay agentx/master: transport connect on session 0x1e4da10 agentx/master: handle pdu (req=0xbb9ef85,trans=0x0,sess=0x0) agentx/master: open 0x1e4da10 agentx/master: opened 0x1e5ee10 = 8 with flags = a0 agentx/master: send response, stat 0 (req=0xbb9ef85,trans=0x0,sess=0x0) agentx_build: packet built okay agentx/master: transport connect on session 0x1e5e990 agentx/master: handle pdu (req=0x508eb4f4,trans=0x0,sess=0x0) agentx/master: open 0x1e5e990 agentx/master: opened 0x1e5f480 = 10 with flags = a0 agentx/master: send response, stat 0 (req=0x508eb4f4,trans=0x0,sess=0x0) agentx_build: packet built okay agentx/master: handle pdu (req=0x75fe7028,trans=0x0,sess=0x6) agentx/master: in register_agentx_list agentx/master: registered ok agentx/master: send response, stat 0 (req=0x75fe7028,trans=0x0,sess=0x6) agentx_build: packet built okay agentx/master: handle pdu (req=0x508eb4f5,trans=0x0,sess=0xa) agentx/master: in register_agentx_list duplicate registration: MIB modules AgentX subagent 6, session 0x1e4cf80, subsession 0x1e5e7a0 and AgentX subagent 10, session 0x1e5e990, subsession 0x1e5f480 (oid .1.3.6.1.3.9999.1.1). agentx/master: duplicate registration agentx/master: send response, stat 263 (req=0x508eb4f5,trans=0x0,sess=0xa) agentx_build: packet built okay agentx/master: handle pdu (req=0xbb9ef86,trans=0x0,sess=0x8) agentx/master: in register_agentx_list duplicate registration: MIB modules AgentX subagent 6, session 0x1e4cf80, subsession 0x1e5e7a0 and AgentX subagent 8, session 0x1e4da10, subsession 0x1e5ee10 (oid .1.3.6.1.3.9999.1.1). agentx/master: duplicate registration agentx/master: send response, stat 263 (req=0xbb9ef86,trans=0x0,sess=0x8) agentx_build: packet built okay agentx/master: handle pdu (req=0x508eb4f6,trans=0x0,sess=0xa) agentx/master: in register_agentx_list agentx/master: registered ok agentx/master: send response, stat 0 (req=0x508eb4f6,trans=0x0,sess=0xa) agentx_build: packet built okay agentx/master: handle pdu (req=0x75fe7029,trans=0x0,sess=0x6) agentx/master: in register_agentx_list duplicate registration: MIB modules AgentX subagent 10, session 0x1e5e990, subsession 0x1e5f480 and AgentX subagent 6, session 0x1e4cf80, subsession 0x1e5e7a0 (oid .1.3.6.1.3.9999.1.2).