Nagios::Interface::CLI::Logfile - CLI interface to Logfile module


Nagios-Interface documentation Contained in the Nagios-Interface distribution.

Index


Code Index:

NAME

Top

Nagios::Interface::CLI::Logfile - CLI interface to Logfile module

SYNOPSIS

Top

 read-nagios-log [ /path/to/nagios.log ]

DESCRIPTION

Top

This is a program which reads in nagios log files and outputs interpreted versions of them. It is currently only really useful for testing that all logged nagios messages are parsed by the Nagios::Interface::LogMessage-doing classes in this distribution.

The default path to the nagios log is /var/log/nagios3/nagios.log

SEE ALSO

Top

Nagios::Interface, Nagios::Interface::Logfile, Nagios::Interface::LogMessage


Nagios-Interface documentation Contained in the Nagios-Interface distribution.

package Nagios::Interface::CLI::Logfile;

use Moose;
use Nagios::Interface::Logfile;
use IO::Handle;

with 'MooseX::Getopt';

has 'path' =>
	is => "rw",
	isa => "Str",
	default => '/var/log/nagios3/nagios.log',
	;

sub run {
	my $self = shift;

	my @filenames = @{ $self->extra_argv };
	if ( !@filenames ) {
		@filenames = $self->path;
	}

	for my $file ( @filenames ) {
		my $logfile = Nagios::Interface::Logfile->new(
			($file eq "-"
			 ? (fh => IO::Handle->new_from_fd(fileno(STDIN), "r"))
			 : (filename => $file)
			 ),
			);
		while ( my $message = $logfile->get_message ) {
			print $message->as_string, "\n";
		}
	}
}

1;

__END__