OpenNMS API 1.2.3

org.opennms.netmgt.archive
Class EventsArchiver

java.lang.Object
  extended byorg.opennms.netmgt.archive.EventsArchiver

public class EventsArchiver
extends java.lang.Object

 
  The EventsArchiver is responsible for archiving and removing events
  from the 'events' table. 
 
  The archival/deletion depends on the 'eventLog' and the 'eventDisplay'
  values for the event -
 
  If the 'eventLog == N and the eventDisplay == N',
  the event is simply deleted from the events table
 
  If the 'eventLog == N and the eventDisplay == Y',
  the event is deleted ONLY if the event has been acknowledged
 
  If the 'eventLog == Y and the eventDisplay == N',
  the event is sent to the archive file and deleted from the table
 
  If the 'eventLog == Y and the eventDisplay == Y',
  the event is sent to the archive file and deleted from the table
  ONLY if the event has been acknowledged
 
  An event is considered acknowledged if the 'eventAckUser' column has
  a non-null value
 
  An EventsArchiver run depends on attributes in the events archiver
  configuration file. The following are the properties that govern a run -
 
  - archiveAge
    This determines which events are to be removed - i.e events older
    than current time minus this time are removed
 
  - separator
    This is the separator used in between event table column values when an
    event is written to the archive file
 
  The EventsArchiver uses Apache's log4j both for its output logs and for
  the actual archiving itself - the set up for the log4j appenders for
  this archiver are all doneexclusively in the 'events.archiver.properties'
  property file
 
  A RollingFileAppender is used
  for the archive file with the defaults for this being to roll when the
  size is 100KB with the number of backups set to 4.

Author:
<A HREF="mailto:sowmya@opennms.org">Sowmya Nataraj</A>, <A HREF="http://www.opennms.org">OpenNMS</A>

Field Summary
private static java.lang.String DB_DELETE_EVENT
          The SQL statement to delete events based on their eventID
private static java.lang.String DB_SELECT_EVENTS_TO_ARCHIVE
          The SQL statement to select events that have their eventCreateTime earlier than a specified age
private static java.lang.String EVENT_ACK_USER
          The column name for 'eventAckUser' in the events table
private static java.lang.String EVENT_DISPLAY
          The column name for 'eventDisplay' in the events table
private static java.lang.String EVENT_ID
          The column name for eventID in the events table
private static java.lang.String EVENT_LOG
          The column name for 'eventLog' in the events table
private  long m_archAge
          The archive age in milliseconds.
private  org.apache.log4j.Category m_archCat
          The log4j category for the archive file
private  java.lang.String m_archSeparator
          The separator to be used when writing events into the archive
private  java.sql.Connection m_dbConn
          The database connection
private  java.sql.PreparedStatement m_eventDeleteStmt
          The prepared statement to delete the events
private  java.sql.PreparedStatement m_eventsGetStmt
          The prepared statement to select the events
private  org.apache.log4j.Category m_logCat
          The log4j category for this class' output logs
private static java.lang.String MSG_NO
          The value for the event log or display field if set to false
private static java.lang.String MSG_YES
          The value for the event log or display field if set to true
 
Constructor Summary
EventsArchiver()
          The events archiver constructor - reads required properties, initializes the database connection and the prepared statements to select and delete events
 
Method Summary
private  void archiveEvents()
          Select the events created before 'age', log them to the archive file if required and delete these events.
private  void close()
          Close the database statements and the connection and close log4j Appenders and categories
private  void init()
          Read the required properties and set up the logs, the archive etc.
static void main(java.lang.String[] args)
           
private  boolean removeEvent(java.lang.String eventID)
          Remove event with eventID from events table.
private  void sendToArchive(java.sql.ResultSet eventsRS, int colCount)
          Archive the current row of the result set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DB_SELECT_EVENTS_TO_ARCHIVE

private static final java.lang.String DB_SELECT_EVENTS_TO_ARCHIVE
The SQL statement to select events that have their eventCreateTime earlier than a specified age

See Also:
Constant Field Values

DB_DELETE_EVENT

private static final java.lang.String DB_DELETE_EVENT
The SQL statement to delete events based on their eventID

See Also:
Constant Field Values

EVENT_ID

private static final java.lang.String EVENT_ID
The column name for eventID in the events table

See Also:
Constant Field Values

EVENT_LOG

private static final java.lang.String EVENT_LOG
The column name for 'eventLog' in the events table

See Also:
Constant Field Values

EVENT_DISPLAY

private static final java.lang.String EVENT_DISPLAY
The column name for 'eventDisplay' in the events table

See Also:
Constant Field Values

EVENT_ACK_USER

private static final java.lang.String EVENT_ACK_USER
The column name for 'eventAckUser' in the events table

See Also:
Constant Field Values

MSG_YES

private static final java.lang.String MSG_YES
The value for the event log or display field if set to true

See Also:
Constant Field Values

MSG_NO

private static final java.lang.String MSG_NO
The value for the event log or display field if set to false

See Also:
Constant Field Values

m_logCat

private org.apache.log4j.Category m_logCat
The log4j category for this class' output logs


m_archCat

private org.apache.log4j.Category m_archCat
The log4j category for the archive file


m_archAge

private long m_archAge
The archive age in milliseconds. Events created before this are archived/deleted.


m_archSeparator

private java.lang.String m_archSeparator
The separator to be used when writing events into the archive


m_dbConn

private java.sql.Connection m_dbConn
The database connection


m_eventsGetStmt

private java.sql.PreparedStatement m_eventsGetStmt
The prepared statement to select the events


m_eventDeleteStmt

private java.sql.PreparedStatement m_eventDeleteStmt
The prepared statement to delete the events

Constructor Detail

EventsArchiver

public EventsArchiver()
               throws ArchiverException
The events archiver constructor - reads required properties, initializes the database connection and the prepared statements to select and delete events

Method Detail

init

private void init()
           throws ArchiverException
Read the required properties and set up the logs, the archive etc.

Throws:
ArchiverException - thrown if a required property is not specified or is incorrect

removeEvent

private boolean removeEvent(java.lang.String eventID)
Remove event with eventID from events table. NOTE: Postgres does not have the ResultSet.deleteRow() implemented! - so use the eventID to delete!


archiveEvents

private void archiveEvents()
Select the events created before 'age', log them to the archive file if required and delete these events. NOTE: Postgres does not have the ResultSet.deleteRow() implemented! - so use the eventID to delete!


sendToArchive

private void sendToArchive(java.sql.ResultSet eventsRS,
                           int colCount)
                    throws java.sql.SQLException
Archive the current row of the result set

Throws:
java.sql.SQLException - thrown if there is an error getting column values from the result set

close

private void close()
Close the database statements and the connection and close log4j Appenders and categories


main

public static void main(java.lang.String[] args)

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.