NAME

Log::Munger::WhichRuleFile - Resolves a Log::Munger rule file name to a path.

VERSION

Version 0.0.1

SYNOPSIS

use Log::Munger::WhichRuleFile;

my $file_location = Log::Munger::WhichRuleFile->rule_file_location( 'file' => 'postfix' );
if ( !defined($file_location) ) {
    print "Not found.\n";
} else {
    print 'File Location: ' . $file_location . "\n";
}

Rule files are looked for in a handful of places, and whichever is found first wins. That ordering is what lets a local file shadow one shipped with the distribution: drop your own sshd.yaml in /etc/log_munger/rules/ and every reference to sshd picks it up instead, with nothing else needing to change.

log_munger which_rule_file -f <name> is this method on the command line, and log_munger list -p shows what every discoverable name currently resolves to.

METHODS

rule_file_location

Returns the path a rule file name resolves to.

A name beginning with /, ./, or ../ is treated as a path and used as given. Anything else is searched for in the directories "search_dirs" returns, in that order.

Each location is tried twice, first for the name as given and then with .yaml appended, so sshd and sshd.yaml both find the same file.

- file :: The name or path to locate. Required.
    Default :: undef

Returns the resolved path, or undef if the name turned up nothing anywhere. Dies only if file is undef.

my $file_location = Log::Munger::WhichRuleFile->rule_file_location( 'file' => 'postfix' );

search_dirs

Returns the directories rule files are searched for in, highest precedence first:

1. the directory named by the LOG_MUNGER_RULES_DIR environment variable, when set
2. /etc/log_munger/rules
3. /usr/local/etc/log_munger/rules
4. the distribution share directory, File::ShareDir::dist_dir('Log-Munger') (skipped when the distribution is not installed, e.g. running out of a checkout)

Takes no arguments. The directories are not checked for existence, so a caller walking them needs to skip any that are missing.

my @search_dirs = Log::Munger::WhichRuleFile->search_dirs;

available_rule_files

Returns every rule file discoverable across the search path, as a hash ref of name to resolved path. The name is the file name with the .yaml suffix stripped, so what comes back is what "rule_file_location" takes.

A name found in more than one directory appears once, resolved to the copy in the earliest directory, since that is the one "rule_file_location" would return for it.

Takes no arguments.

my $available = Log::Munger::WhichRuleFile->available_rule_files;
# $available = { 'base' => '/etc/log_munger/rules/base.yaml', ... }