![]() ![]() ![]() ![]() ![]() ![]() |
The following sections describe how to use the WebLogic SIP 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 WebLogic SIP Server domain.
WebLogic SIP Server 3.0 includes a runtime MBean, SipServletSnmpTrapRuntimeMBean,
that enables applications to easily generate SNMP traps. The WebLogic SIP 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, WebLogic SIP Server also automatically transmits the Servlet name, application name, and WebLogic SIP 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 WebLogic SIP Server administrator role-name
entry to the security-role
and run-as
role elements in the sip.xml
deployment descriptor. Listing 15-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 15-2 shows the sample code for a method to obtain the MBean.
public SipServletSnmpTrapRuntimeMBean getServletSnmpTrapRuntimeMBean() {
MBeanHome localHomeB = null;
try {
Environment env = new Environment();
env.setProviderUrl("t3://localhost:7001");
env.setSecurityPrincipal("weblogic");
env.setSecurityCredentials("weblogic");
Context ctx = env.getInitialContext();
localHomeB = (MBeanHome)ctx.lookup(MBeanHome.JNDI_NAME + "." + "AdminServer");
System.out.println("Got localHomB: " + localHomeB );
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();
return null;
}
}
SipServletSnmpTrapRuntimeMBean ssTrapMB = (SipServletSnmpTrapRuntimeMBean) set.iterator().next();
return ssTrapMB;
}
In combination with the method shown in Listing 15-2, Listing 15-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());
}
}
![]() ![]() ![]() |