Saturday, July 2, 2011

Extending OpenNMS

The OpenNMS installation directory contains etc/ directory which contains all kind of configuration files which require to run openNMS, it has various configuration files for each daemon module, for example for capability daemon there is capsd.xml for collector daemon it has capsd.xml and for dataCollection definition it has jmx-dataCollection.xml for Mbeans definition, similarity for snmp there is dataCollection.xml for defining what OID’s need to be collected for SNMP services.

Now this etc directory also contains service-configuration.xml which has all module definition plus which method to be invoked for loading the module. These modules can be daemon or non daemon depending upon the requirement. all module follows standard MBean criteria. These modules are started in the sequence they are mention in the file. I mean top most will be executed first and the bottom most ( which is embedded jetty-web server) will be the last.

 

<service-configuration>
  <service>
    <name>:Name=XSLTProcessor</name>
    <class-name>mx4j.tools.adaptor.http.XSLTProcessor</class-name>
  </service>
  <service>
    <name>:Name=HttpAdaptor</name>
    <class-name>mx4j.tools.adaptor.http.HttpAdaptor</class-name>
    <attribute>
      <name>Port</name>
      <value type="java.lang.Integer">8180</value>
    </attribute>
    <attribute>
      <name>Host</name>
…………………………………….

If we add new service definition here, the OpenNMS will load our service ..

for example let say we want to delete all logs or previous data collected on starting up openNMS, we have to add our service in this xml then only openNMS could start our service.

<service-configuration>

<service>
  <name>OurService:Name=CleanupService</name>
  <class-name>org.ourservice.Clean</class-name>
  <invoke at="start" pass="0" method="start"/>

</service>
  <service>
    <name>:Name=XSLTProcessor</name>
    <class-name>mx4j.tools.adaptor.http.XSLTProcessor</class-name>
  </service>
  <service>
    <name>:Name=HttpAdaptor</name>
    <class-name>mx4j.tools.adaptor.http.HttpAdaptor</class-name>
    <attribute>
      <name>Port</name>
      <value type="java.lang.Integer">8180</value>
    </attribute>
    <attribute>
      <name>Host</name>

now CleanupService will be triggered first. for starting this service start method will be invoked of Clean class. The clean Class must implement MBean.
create CleanMBean interface and declare start method signature.

package org.ourservice;

public interface CleanMBean {
    public void start();
}

now create Clean class and implement CleanMBean interface, also implement logic to clean the data.

package org.ourservice;

public class Clean implements CleanMBean {
    public void start(){
       System.out.println(“Cleaned all”);

     }

}

 

 

After compiling the Clean class and other dependant classes. create classes directory inside openNMS installation directory and put all our classes inside. then start openNMS.

No comments:

Post a Comment

Search Ranjeet's Blog