From 08b0e407bb0edebebab03132a64d2b58de3b7ec8 Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Fri, 20 Dec 2019 12:31:40 +0100 Subject: [PATCH] ADD: module documentation --- lib/OSSEC/Log.pm | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/OSSEC/Log.pm b/lib/OSSEC/Log.pm index a0234f7..299f958 100644 --- a/lib/OSSEC/Log.pm +++ b/lib/OSSEC/Log.pm @@ -1,21 +1,37 @@ package OSSEC::Log; -# ABSTRACT: OSSEC::Log - Module for logging OSSEC log messages +# ABSTRACT: Module/class for simplifying logging of OSSEC log messages use strict; use warnings; use Moose; use DateTime; +use File::Basename; + + +=head1 DESCRIPTION + +This Module/Class is part of the OSSEC distribution. +It simplifies logging to files, e.g. for active response. You are able +to use different logging types (info,error,fatal,debug) and select the file to log +to. See the methods below. + +=cut =attr ossecPath - base path to the ossec installation B /var/ossec +base path to the ossec installation B /var/ossec + +Type: String =cut has 'ossecPath' => (is => 'rw', isa => 'Str' , default => "/var/ossec" ); =attr file - in which file to log the messages +In which file to log the messages. The file should be given as the path relative to the +OSSEC configuration file. + +Type: String =cut has 'file' => (is => 'rw', isa => 'Str'); @@ -33,7 +49,7 @@ log error message =back - log->error("OSSEC-Jabber","alert not found"); +log->error("OSSEC-Jabber","alert not found"); =cut sub error @@ -57,7 +73,7 @@ log fatal message and die =back - log->fatal("OSSEC-Jabber","could not connect to mysql server"); +log->fatal("OSSEC-Jabber","could not connect to mysql server"); =cut sub fatal @@ -82,7 +98,7 @@ log info message =back - log->info("OSSEC-Jabber","alert send"); +log->info("OSSEC-Jabber","alert send"); =cut sub info @@ -106,7 +122,7 @@ log debug message =back - log->error("OSSEC-Jabber","found alert in database"); +log->error("OSSEC-Jabber","found alert in database"); =cut sub debug @@ -146,13 +162,9 @@ sub log # create the full path to the file my $file = $self->ossecPath() . "/" . $self->file(); + my $dir = dirname($file); - # open the logfile - open(my $fh1, ">>", "/tmp/log"); - - print $fh1 $file . "\n"; - - close $fh1; + readpipe("mkdir -p $dir"); my $dt = DateTime->now;