New SNMP Component

One Star

New SNMP Component

I've been trying to develop a new component for sending simple SNMP messages from Talend. Think of it as an alternative to a tWarn. However, my java skills are lacking, and I'm kind of stuck.
Basically, I keep getting a NullPointer exception and I'm not sure why. My component uses the SNMP4J library. This component isn't finished yet, but if someone could have a look and maybe point me in the right direction I would be most grateful.
Here are the files to create the component. You can find it under the "Internet" heading. It's called tSNMP.
tSNMP_main.javajet
<%@ jet 
imports="
org.talend.core.model.process.INode
org.talend.core.model.process.ElementParameterParser
org.talend.core.model.metadata.IMetadataTable
org.talend.core.model.metadata.IMetadataColumn
org.talend.core.model.process.IConnection
org.talend.core.model.process.IConnectionCategory
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.core.model.metadata.types.JavaTypesManager
org.talend.core.model.metadata.types.JavaType
java.util.List
java.util.Map
java.util.StringTokenizer
java.net.InetAddress

"
%>
<%
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
INode node = (INode)codeGenArgument.getArgument();
String cid = node.getUniqueName();


//InetAddress snmp_server = InetAddress.getByName(ElementParameterParser.getValue(node, "__SNMP_SERVER__"));
//InetAddress snmp_server = InetAddress.getByName("noc1-iis1.uscc.com");
String snmp_server = ElementParameterParser.getValue(node, "__SNMP_SERVER__");
int snmp_port = Integer.parseInt(ElementParameterParser.getValue(node, "__SNMP_SERVER_PORT__"));
String snmp_oid = ElementParameterParser.getValue(node, "__OID__");
String snmp_com = ElementParameterParser.getValue(node, "__COMMUNITY_STRING__");
String snmp_msg = ElementParameterParser.getValue(node, "__SNMP_MSG__");



%>
org.snmp4j.Snmp mSnmp = null;
org.snmp4j.CommunityTarget mCommunityTarget = null;

org.snmp4j.TransportMapping vTransport = new org.snmp4j.transport.DefaultUdpTransportMapping();
mSnmp = new org.snmp4j.Snmp(vTransport);
org.snmp4j.PDUv1 vTrapPdu = new org.snmp4j.PDUv1();
vTransport.listen();

//SETUP FROM USER
mCommunityTarget.setCommunity(new org.snmp4j.smi.OctetString(<%=snmp_com %>));
mCommunityTarget.setAddress(new org.snmp4j.smi.UdpAddress(java.net.InetAddress.getByName(<%=snmp_server %>),<%=snmp_port %>));
mCommunityTarget.setRetries(4);
mCommunityTarget.setTimeout(4096);
mCommunityTarget.setVersion(org.snmp4j.mp.SnmpConstants.version1);
//vTrapPdu.setType(org.snmp4j.PDU.V1TRAP);
vTrapPdu.setGenericTrap(6);
vTrapPdu.setSpecificTrap(org.snmp4j.PDUv1.ENTERPRISE_SPECIFIC);

vTrapPdu.setEnterprise(new org.snmp4j.smi.OID(<%=snmp_oid %>));
vTrapPdu.setTimestamp((long)java.lang.System.currentTimeMillis()/10l);
vTrapPdu.add(new org.snmp4j.smi.VariableBinding(new org.snmp4j.smi.OID(<%=snmp_oid %>), new org.snmp4j.smi.OctetString(<%=snmp_msg %>)));
mSnmp.send(vTrapPdu, mCommunityTarget);

tSNMP_java.xml
<?xml version="1.0" encoding="UTF-8"?>
<COMPONENT>
<HEADER AUTHOR="Dustin W" COMPATIBILITY="ALL" DATA_AUTO_PROPAGATE="false" PLATEFORM="ALL" RELEASE_DATE="20080229A" SERIAL="" STARTABLE="true" STATUS="ALPHA" VERSION="0.1">
<SIGNATURE/>
</HEADER>
<DOCUMENTATION>
<URL/>
</DOCUMENTATION>
<CONNECTORS>
<CONNECTOR CTYPE="SUBJOB_OK" MAX_INPUT="1" />
<CONNECTOR CTYPE="SUBJOB_ERROR" MAX_INPUT="1" />
<CONNECTOR CTYPE="COMPONENT_OK"/>
<CONNECTOR CTYPE="COMPONENT_ERROR"/>
<CONNECTOR CTYPE="RUN_IF"/>
</CONNECTORS>
<PARAMETERS>
<PARAMETER FIELD="TEXT" NAME="SNMP_SERVER" REQUIRED="true" NB_LINES="1" NUM_ROW="10"> <DEFAULT>"127.0.0.1"</DEFAULT> </PARAMETER>
<PARAMETER FIELD="TEXT" NAME="SNMP_SERVER_PORT" REQUIRED="true" NB_LINES="1" NUM_ROW="10"> <DEFAULT>162</DEFAULT> </PARAMETER>
<PARAMETER FIELD="TEXT" NAME="OID" NB_LINES="1" REQUIRED="true" NUM_ROW="30"> <DEFAULT>".1.3.6.1.4.1.99998"</DEFAULT> </PARAMETER>
<PARAMETER FIELD="TEXT" NAME="COMMUNITY_STRING" REQUIRED="true" NB_LINES="1" NUM_ROW="40"> <DEFAULT>"public"</DEFAULT> </PARAMETER>
<PARAMETER FIELD="TEXT" NAME="SNMP_MSG" REQUIRED="true" NB_LINES="1" NUM_ROW="50"> <DEFAULT>"Your custom error message goes here"</DEFAULT> </PARAMETER>

</PARAMETERS>
<CODEGENERATION>
<IMPORTS>
<IMPORT NAME="SNMP4J" MODULE="SNMP4J.jar" REQUIRED="true"/>
</IMPORTS>
</CODEGENERATION>
<RETURNS></RETURNS>
</COMPONENT>

tSNMP_messages.properties
#
#Tue Nov 25 18:13:37 CST 2008
PROPERTY.NAME=PROPERTY
OID.NAME=OID
NB_LINE.NAME=NB_LINE
FAMILY=Internet
HELP=org.talend.help.tSNMP
LONG_NAME=Send SNMP trap message
SNMP_SERVER.NAME=SNMP Server
COMMUNITY_STRING.NAME=Community String
SNMP_MSG.NAME=SNMP Message
NAME=tSNMP
SNMP_SERVER_PORT.NAME=SNMP Server Port
Employee

Re: New SNMP Component

org.snmp4j.CommunityTarget mCommunityTarget = null;

mCommunityTarget is initialized as null and just after you try to use a set method on it.
So it's logical to have a null pointer problem.
HTH,
One Star

Re: New SNMP Component

That was it! Thank you so much! Ok, just some more clean up and testing and I will release this into the wild.
One Star

Re: New SNMP Component

Ok, this is up in beta form on the ecosystem! Thanks again for your help.
Employee

Re: New SNMP Component

Great, Congratulations !
One Star

Re: New SNMP Component

Hi dweaver,
I added this component in my Talend palette. Can you give your inputs on configuring tSNMP component in Talend Job. I am using TOS v 3.2 r3300. Any PDF or image on this component is appreciable.
Thanks in Advance
Naju
One Star

Re: New SNMP Component

I don't have a PDF or image, but it's really simple. Just create a link from your subjob to the component using the "On Subjob Error" link. In the "SNMP Message" part, just hit Ctl+Space to bring up the list of variables in Talend. From this list, you can choose the subjob.error from the list.
Make sure you change the IP,port, and community string to match your environment.
One Star

Re: New SNMP Component

Hi dweaver ,
i have done all that you said to make tsnmp to work but it is not working i am unable to see the message.
can you help me how to display the message infront of user
Thanks in advance
hari
One Star

Re: New SNMP Component

Do you have your SNMP settings correct? I would start out by installing a trap receiver on your local machine:
http://www.trapreceiver.com/
Then you can see how the messages look.
Also, if you'll post a screen shot of your job, I can get a better idea of what you're doing.
One Star

Re: New SNMP Component

I have updated this component to allow you to set trap types.
We are using this component in our environment 3 ways:
1. Send a heartbeat message to our fault management system to check if ANY jobs run (Complete Talend failure)
2. Send a heartbeat message to our fault management system if a single job server runs (Jobserver failure)
3. Send a specific trap if a failure in the job (tWarn, tDie replacement).
Using these 3 ways, we now have a complete monitoring picture of our Talend environment.
You can find it here: http://www.talendforge.org/exchange/tos/extension_view.php?eid=95
One Star mpa
One Star

Re: New SNMP Component

dweaver,
Thank you so much for creating this component!
It took me some time to figure out how it works ( as I didn't know anything about SNMP myself) and now that it's working it fits the needs.
So once again thanks for creating and sharing this component with the community!!
Regards,
Mario De Pauw