NAME

OmniPITR::Program::Monitor::Parser - base for omnipitr-monitor parsers

SYNOPSIS

package OmniPITR::Program::Monitor::Parser::Whatever;
use base qw( OmniPITR::Program::Monitor::Parser );
sub handle_line { ... }

DESCRIPTION

This is base class for parsers of lines from particular omnipitr programs.

CONTROL FLOW

When omnipitr-monitor creates parser object, it doesn't pass any arguments (yet).

Afterwards, it calls ->setup() function, passing (as hash):

  • state - hashref with current state - all modifications will be stored by omnipitr-monitor

  • log - log object

For each line from given program, ->handle_line() method will be called, with single argument, being hashref with keys:

  • timestamp - timestamp, as it was written in the log line

  • epoch - same timestamp, but converted to epoch format

  • line - data logged by actual program, with all prefixes removed

  • pid - process id of the process that logged given line

METHODS

new()

Object constructor. No logic in here. Just makes simple hashref based object.

setup()

Sets check for work - receives state-dir and log object from omnipitr-monitor.

empty_state

This method should be overwritten in parsers that assume that their state is something else then hashref.

log()

Shortcut to make code a bit nicer.

Returns logger object.

state()

Helper function, accessor, to state hash. Or, to be exact, to subhash in state that relates to current parser.

Has 1, or two arguments. In case of one argument - returns value, from state, for given key.

If it has two arguments, then - if 2nd argument is undef - it removes the key from state, and returns.

If the 2nd argument is defined, it sets value for given key to given value, and returns it.

split_xlog_filename()

Splits given xlog filename (24 hex characters) into a pair of timeline and xlog offset.

Both are trimmed of leading 0s to save space on state saving.