Apache ServiceMix NMR #usernavbar() #printableicon() #pdficon() #feedicon()  
When you contribute content to this Wiki, you grant a license to the ASF for inclusion in ASF works (as per the Apache Software License).
  11. Audit

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Wiki Markup
{scrollbar}

Anchor
top
top

11. Audit

File auditor

First install the audit feature:

Code Block
smx@root:/> features/install nmr-audit

Then create a file named deploy/servicemix-file-audit.xml with the following content:

Code Block
langxml
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
    
    <bean id="file-auditor" class="org.apache.servicemix.nmr.audit.file.FileAuditor">
        <property name="directory" value="${servicemix.base}/data/audit/file" />
    </bean>
    
    <osgi:service ref="file-auditor">
        <osgi:interfaces>
            <value>org.apache.servicemix.nmr.api.event.Listener</value>
            <value>org.apache.servicemix.nmr.api.event.ExchangeListener</value>
        </osgi:interfaces>
    </osgi:service>

    <osgi:service ref="file-auditor">
        <osgi:interfaces>
            <value>org.apache.servicemix.nmr.audit.AuditorMBean</value>
        </osgi:interfaces>
    </osgi:service>

</beans>

Here you go, all exchanges will be logged into the data/audit/file directory.

Note that the file auditor is quite limited and only support counting the number of exchanges, but the exchanges are written in plain text so you can view those easily.

JDBC auditor

First install the audit feature:

Code Block
smx@root:/> features/install nmr-audit

Then, install the required database (we use HSQLDB here). As there is no OSGi bundle for this database, we use the wrap url handler to create one on the fly.

Code Block
smx@root:/> osgi/install -s wrap:mvn:hsqldb/hsqldb/1.8.0.7

Then create a file named deploy/servicemix-jdbc-audit.xml with the following content. This example uses the HSQLDB database, but you can configure any DataSource.

Code Block
langxml
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <manifest>
        DynamicImport-Package = *
    </manifest>

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
    
    <bean id="jdbc-auditor" class="org.apache.servicemix.nmr.audit.jdbc.JdbcAuditor">
        <property name="dataSource" ref="dataSource" />
    </bean>
    
    <bean id="dataSource" class="org.hsqldb.jdbc.jdbcDataSource">
        <property name="database" value="jdbc:hsqldb:file:${servicemix.base}/data/audit/jdbc/hsqldb" />
        <property name="user" value="sa" />
    </bean>
    
    <osgi:service ref="jdbc-auditor">
        <osgi:interfaces>
            <value>org.apache.servicemix.nmr.api.event.Listener</value>
            <value>org.apache.servicemix.nmr.api.event.ExchangeListener</value>
        </osgi:interfaces>
    </osgi:service>

    <osgi:service ref="jdbc-auditor">
        <osgi:interfaces>
            <value>org.apache.servicemix.nmr.audit.AuditorMBean</value>
        </osgi:interfaces>
    </osgi:service>

</beans>

Lucene indexation

Any auditor can be wrapped in a lucene auditor to provide indexation and search in audited exchanges.

Note that prior to installing the nmr-audit feature, you need to install lucene bundle:

Code Block
smx@root:/> osgi/install -s wrap:mvn:org.apache.lucene/lucene-core/2.4.1

If the feature has already been installed, you need to use the osgi/refresh command.

Code Block
smx@root:/> osgi/refresh

See the configuration below:

Code Block
langxml
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <manifest>
        DynamicImport-Package = *
    </manifest>

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
    
    <bean id="jdbc-auditor" class="org.apache.servicemix.nmr.audit.jdbc.JdbcAuditor">
        <property name="dataSource" ref="dataSource" />
    </bean>
    
    <bean id="lucene-auditor" class="org.apache.servicemix.nmr.audit.lucene.LuceneAuditor">
        <property name="delegatedAuditor" ref="jdbc-auditor" />
        <property name="luceneIndexer">
            <bean class="org.apache.servicemix.nmr.audit.lucene.LuceneIndexer">
                <property name="directoryName" value="${servicemix.base}/data/audit/lucene/" />
            </bean>
        </property>
    </bean>
    
    <bean id="dataSource" class="org.hsqldb.jdbc.jdbcDataSource">
        <property name="database" value="jdbc:hsqldb:file:${servicemix.base}/data/audit/jdbc/hsqldb" />
        <property name="user" value="sa" />
    </bean>
    
    <osgi:service ref="lucene-auditor">
        <osgi:interfaces>
            <value>org.apache.servicemix.nmr.api.event.Listener</value>
            <value>org.apache.servicemix.nmr.api.event.ExchangeListener</value>
        </osgi:interfaces>
    </osgi:service>
    
    <osgi:service ref="lucene-auditor">
        <osgi:interfaces>
            <value>org.apache.servicemix.nmr.audit.AuditorMBean</value>
        </osgi:interfaces>
    </osgi:service>

</beans>

Query fields

  • id
  • mep
  • status
  • role
  • properties.*
  • in.content
  • in.properties.*
  • out.content
  • out.properties.*
  • fault.content
  • fault.properties.*

Commands

A few commands are available to access the audited exchnanges:

Code Block
audit/count
audit/ids
audit/exchanges
audit/delete
audit/find

For example, to find all the exchanges with an ERROR status, try:

Code Block
smx@root:/> audit/find "status: error"

The last command audit/find only works if lucene has been set up as shown above.

#top