Quick Start – Sending Notifications
In this lesson we will learn how to send a notification/trap using the generated code. To demonstrate this, we will send a notification every time we get a Get/GetNext command on GarageCOLevel. This is being done just to demonstrate the mechanism of sending a notification. On a typical system, a background thread is probably monitoring the CO level and if it exceeds the rising threshold, a notification is sent out.
The code generated is given below,
SNMP_ERRSTAT DGarageObjects::OnGet_GarageCOLevel(tUint32 transactionId, tASN_INT& nVal)
{
NDRANDOMIZE_INT(m_nGarageCOLevel);
nVal = m_nGarageCOLevel;
return eSNMP_ERRSTAT_NO_ERROR;
}
All the notifications are defined in one file. In this case, it is TutorialTraps.h.
This is a pointer to the Trap Sending interface that is defined in the classes for standalone agent / extension agent. The next step is to instantiate the notification that we want to send. After that is done, all we have to do is to call the SendTrap method of ITrapSender and pass in the notification that we want to send. That will send the notification. The code with modifications is given below.
//————————————————–
garageCOLevel ::= garageObjects.4 [ND-GARAGE-MIB]
//
SNMP_ERRSTAT DGarageObjects::OnGet_GarageCOLevel(tUint32 transactionId, tASN_INT& nVal)
{
NDRANDOMIZE_INT(m_nGarageCOLevel);
nVal = m_nGarageCOLevel;
// instantiate the notification
NCoLevelRisingAlarm alarmRising;
// set the value of the objects sent in the notification
alarmRising.SetValue (m_nGarageCOLevel);
// send the notification
DGarage::SendTrap (alarmRising);
return eSNMP_ERRSTAT_NO_ERROR;
}
For a detailed discussion of this topic, please see the Tutorials.
Please proceed to Quick Start – Initializing/Saving Objects on Startup/Shutdown.