Need help on How to send trap directly from a MIB

Bruno Vétel <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <1209947078.27519.25.camel@localhost>
Hello

I'm very new to snmp.
I just want to write a very simple MIB.

I want to send a trap when the integer ier600LedStatus is updated by a
snmpset command

The traps when I start the snmpd daemon are send correctly than I 
believe that my configuration should work.

I generate the module ierMIB.so in three phase
	- ierMIB.c
	- ier600Trap.c
	- Compile both and link them

I inline the source of the mib and the configuration file with the two
c-files in attachment . Could anybody tell me where I'm wrong


	Thanks

	Bruno

IER-MIB DEFINITIONS ::= BEGIN

-- A Comment!

-- IMPORTS: Include definitions from other mibs here, which is always
-- the first item in a MIB file.
IMPORTS
	INTEGER, OBJECT-TYPE, MODULE-IDENTITY,	NOTIFICATION-TYPE, enterprises
  	FROM SNMPv2-SMI;
--	MODULE-COMPLIANCE, OBJECT-GROUP       FROM SNMPv2-CONF;

--
-- A brief description and update information about this mib.
--
ierMIB MODULE-IDENTITY
    LAST-UPDATED "200804021710Z"            -- 02 avril 2008 17h10
    ORGANIZATION "ier"
    CONTACT-INFO "ier.fr:   Jean Michel Bichoux

		  email:    [email protected]
                 "
    DESCRIPTION  "A simple mib for ier600
    		  This MIB module defines an integer maintained
		  used to display the status of the Ier600 printer.
		  It is located under IER leaf in the MIB tree.
		  iso.org.dod.internet.private.enterprises.ier.ier600
		  1   3   6   1        4       1           9233       1    "

    REVISION    "200611230000Z"
    DESCRIPTION
    "Initial version"
    ::=  {  iso(1) org(3) dod(6) internet(1) private(4) enterprises(1)
ier(9233) 1  } 

ier600Status OBJECT IDENTIFIER ::= { ierMIB 1 }
ier600Trap OBJECT IDENTIFIER ::= { ierMIB 2 }
-- 
ier600LedStatus OBJECT-TYPE
    SYNTAX      INTEGER
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION
	"This object reflects the status of the IER 600."
    ::= { ier600Status 1 }
 

ier600StatusChange NOTIFICATION-TYPE
   OBJECTS {
	   ier600LedStatus
   }	
   MAX-ACCESS	notify
   STATUS      current
   DESCRIPTION
	"This SNMP trap should be  generated when the status change."
    ::= { ier600Trap 1 }

-- 
END

###########################################################################
#
# snmpd.conf
#
#   - created by the snmpconf configuration program
#
###########################################################################
# SECTION: Access Control Setup
#
#   This section defines who is allowed to talk to your running
#   snmp agent.

# rwuser: a SNMPv3 read-write user
#   arguments:  user [noauth|auth|priv] [restriction_oid]

#rwuser  root auth 
#rwuser  SNMPV3 noauth 

# rocommunity: a SNMPv1/SNMPv2c read-only access community name
#   arguments:  community [default|hostname|network/bits] [oid]

rocommunity  public 10.0.20.0/24

# rwcommunity: a SNMPv1/SNMPv2c read-write access community name
#   arguments:  community [default|hostname|network/bits] [oid]

rwcommunity  private 10.0.20.0/24



###########################################################################
# SECTION: Trap Destinations
#
#   Here we define who the agent will send traps to.

# trap2sink: A SNMPv2c trap receiver
#   arguments: host [community] [portnum]

trap2sink   10.0.20.130 private
#
# informsink: A SNMPv2c inform (acknowledged trap) receiver
#   arguments: host [community] [portnum]

#informsink  localhost  

# trapcommunity: Default trap sink community to use
#   arguments: community-string


# authtrapenable: Should we send traps when authentication failures
occur
#   arguments: 1 | 2   (1 = yes, 2 = no)

#authtrapenable  1
#authtrapenable  1



###########################################################################
# SECTION: System Information Setup
#
#   This section defines some of the information reported in
#   the "system" mib group in the mibII tree.

# syslocation: The [typically physical] location of the system.
#   Note that setting this value here means that when trying to
#   perform an snmp SET operation to the sysLocation.0 variable will
make
#   the agent return the "notWritable" error code.  IE, including
#   this token in the snmpd.conf file will disable write access to
#   the variable.
#   arguments:  location_string

syslocation   maison

# syscontact: The contact information for the administrator
#   Note that setting this value here means that when trying to
#   perform an snmp SET operation to the sysContact.0 variable will make
#   the agent return the "notWritable" error code.  IE, including
#   this token in the snmpd.conf file will disable write access to
#   the variable.
#   arguments:  contact_string

syscontact  [email protected]

# sysservices: The proper value for the sysServices object.
#   arguments:  sysservices_number

sysservices 79
sysservices 12


dlmod ierMIB  /lib/ier/ierMIB.so

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
ierMIB.c (text/x-csrc, 3.4 KB)
/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.int_watch.conf 13957 2005-12-20 15:33:08Z tanders $
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "ierMIB.h"
#include "ier600Trap.h"

/*
 * The variables we want to tie the relevant OIDs to.
 * The agent will handle all GET and (if applicable) SET requests
 * to these variables automatically, changing the values as needed.
 */

long    ier600LedStatus = 0;  /* XXX: set default value */
/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.notify.conf 10110 2004-04-15 12:29:19Z dts12 $
 */


static oid snmptrap_oid[] = {1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0};
static oid ier600LedStatus_oid[] = { 1,3,6,1,4,1,9233,1,1,1 };


/*
 * Our initialization routine, called automatically by the agent 
 * (Note that the function name must match init_FILENAME()) 
 */
void
init_ierMIB(void)
{
  netsnmp_handler_registration *reg;
  netsnmp_watcher_info         *winfo;

  /*
   * a debugging statement.  Run the agent with -DierMIB to see
   * the output of this debugging statement. 
   */
  DEBUGMSGTL(("ierMIB", "Initializing the ierMIB module\n"));


    /*
     * Register scalar watchers for each of the MIB objects.
     * The ASN type and RO/RW status are taken from the MIB definition,
     * but can be adjusted if needed.
     *
     * In most circumstances, the scalar watcher will handle all
     * of the necessary processing.  But the NULL parameter in the
     * netsnmp_create_handler_registration() call can be used to
     * supply a user-provided handler if necessary.
     *
     * This approach can also be used to handle Counter64, string-
     * and OID-based watched scalars (although variable-sized writeable
     * objects will need some more specialised initialisation).
     */
    DEBUGMSGTL(("ierMIB",
                "Initializing ier600LedStatus scalar integer.  Default value = %d\n",
                ier600LedStatus));
    reg = netsnmp_create_handler_registration(
             "ier600LedStatus", NULL,
              ier600LedStatus_oid, OID_LENGTH(ier600LedStatus_oid),
              HANDLER_CAN_RWRITE);
    winfo = netsnmp_create_watcher_info(
                &ier600LedStatus, sizeof(long),
                 ASN_INTEGER, WATCHER_FIXED_SIZE);
    if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched ier600LedStatus" );
    }


  DEBUGMSGTL(("ierMIB",
              "Done initalizing ierMIB module\n"));
}

int
send_ier600StatusChange_trap( void )
{
    netsnmp_variable_list  *var_list = NULL;
    oid ier600StatusChange_oid[] = { 1,3,6,1,4,1,9233,1,2,1 };

    /*
     * Set the snmpTrapOid.0 value
     */
    snmp_varlist_add_variable(&var_list,
        snmptrap_oid, OID_LENGTH(snmptrap_oid),
        ASN_OBJECT_ID,
        ier600StatusChange_oid, sizeof(ier600StatusChange_oid));
    
    /*
     * Add any objects from the trap definition
     */
    snmp_varlist_add_variable(&var_list,
        ier600LedStatus_oid, OID_LENGTH(ier600LedStatus_oid),
        ASN_INTEGER,
        /* Set an appropriate value for ier600LedStatus */
        NULL, 0);

    /*
     * Add any extra (optional) objects here
     */

    /*
     * Send the trap to the list of configured destinations
     *  and clean up
     */
    send_v2trap( var_list );
    snmp_free_varbind( var_list );

    return SNMP_ERR_NOERROR;
}
ier600Trap.c (text/x-csrc, 1.3 KB)
/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.notify.conf 10110 2004-04-15 12:29:19Z dts12 $
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "ier600Trap.h"

static oid snmptrap_oid[] = {1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0};

int
send_ier600StatusChange_trap( void )
{
    netsnmp_variable_list  *var_list = NULL;
    oid ier600StatusChange_oid[] = { 1,3,6,1,4,1,9233,1,2,1 };
    oid ier600LedStatus_oid[] = { 1,3,6,1,4,1,9233,1,1,1, 0 };

    /*
     * Set the snmpTrapOid.0 value
     */
    snmp_varlist_add_variable(&var_list,
        snmptrap_oid, OID_LENGTH(snmptrap_oid),
        ASN_OBJECT_ID,
        ier600StatusChange_oid, sizeof(ier600StatusChange_oid));
    
    /*
     * Add any objects from the trap definition
     */
    snmp_varlist_add_variable(&var_list,
        ier600LedStatus_oid, OID_LENGTH(ier600LedStatus_oid),
        ASN_INTEGER,
        /* Set an appropriate value for ier600LedStatus */
        NULL, 0);

    /*
     * Add any extra (optional) objects here
     */

    /*
     * Send the trap to the list of configured destinations
     *  and clean up
     */
    send_v2trap( var_list );
    snmp_free_varbind( var_list );

    return SNMP_ERR_NOERROR;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.