The following sections describe how to use the Oracle Communications Converged Application Server SipServletSnmpTrapRuntimeMBean
to generate SNMP traps from within a SIP Servlet:
See Configuring SNMP in the Operations Guide for information about configuring SNMP in a Oracle Communications Converged Application Server domain.
Oracle Communications Converged Application Server includes a runtime MBean, SipServletSnmpTrapRuntimeMBean,
that enables applications to easily generate SNMP traps. The Oracle Communications Converged Application Server MIB contains seven new OIDs that are reserved for traps generated by an application. Each OID corresponds to a severity level that the application can assign to a trap, in order from the least severe to the most severe:
To generate a trap, an application simply obtains an instance of the SipServletSnmpTrapRuntimeMBean
and then executes a method that corresponds to the desired trap severity level (sendInfoTrap()
, sendWarningTrap()
, sendErrorTrap()
, sendNoticeTrap()
, sendCriticalTrap()
, sendAlertTrap()
, and sendEmergencyTrap()
). Each method takes a single parameter—the String value of the trap message to generate.
For each SNMP trap generated in this manner, Oracle Communications Converged Application Server also automatically transmits the Servlet name, application name, and Oracle Communications Converged Application Server instance name associated with the calling Servlet.
In order to obtain a SipServletSnmpTrapRuntimeMBean
, the calling SIP Servlet must be able to perform MBean lookups from the Servlet context. To enable this functionality, you must assign a Oracle Communications Converged Application Server administrator role-name
entry to the security-role
and run-as
role elements in the sip.xml
deployment descriptor. Listing 12-1 shows a sample sip.xml
file with the required role elements highlighted.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sip-app
PUBLIC "-//Java Community Process//DTD SIP Application 1.0//EN"
"http://www.jcp.org/dtd/sip-app_1_0.dtd">
<sip-app>
<display-name>My SIP Servlet</display-name>
<distributable/>
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>com.mycompany.MyServlet</servlet-class>
<run-as>
<role-name>weblogic</role-name>
</run-as>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<pattern>
<equal>
<var>request.method</var>
<value>INVITE</value>
</equal>
</pattern>
</servlet-mapping>
<security-role>
<role-name>weblogic</role-name>
</security-role>
</sip-app>
Any SIP Servlet that generates SNMP traps must first obtain a reference to the SipServletSnmpTrapRuntimeMBean
. Listing 12-2 shows the sample code for a method to obtain the MBean.
public SipServletSnmpTrapRuntimeMBean getServletSnmpTrapRuntimeMBean() {
MBeanHome localHomeB = null;
SipServletSnmpTrapRuntimeMBean ssTrapMB = null;
try
{
Context ctx = new InitialContext();
localHomeB = (MBeanHome)ctx.lookup(MBeanHome.LOCAL_JNDI_NAME);
ctx.close();
} catch (NamingException ne){
ne.printStackTrace();
}
Set set = localHomeB.getMBeansByType("SipServletSnmpTrapRuntime");
if (set == null || set.isEmpty()) {
try {
throw new ServletException("Unable to lookup type 'SipServletSnmpTrapRuntime'");
} catch (ServletException e) {
e.printStackTrace();
}
}
ssTrapMB = (SipServletSnmpTrapRuntimeMBean) set.iterator().next();
return ssTrapMB;
}
In combination with the method shown in Listing 12-2, Listing 12-3 demonstrates how a SIP Servlet would use the MBean instance to generate an SNMP trap in response to a SIP INVITE.
public class MyServlet extends SipServlet {
private SipServletSnmpTrapRuntimeMBean sipServletSnmpTrapMb = null;
public MyServlet () {
}
public void init (ServletConfig sc) throws ServletException {
super.init (sc);
sipServletSnmpTrapMb = getServletSnmpTrapRuntimeMBean();
}
protected void doInvite(SipServletRequest req) throws IOException {
sipServletSnmpTrapMb.sendInfoTrap("Rx Invite from " + req.getRemoteAddr() + "with call id" + req.getCallId());
}
}