.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Parse::Syslog 3pm" .TH Parse::Syslog 3pm "2022-12-04" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Parse::Syslog \- Parse Unix syslog files .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& my $parser = Parse::Syslog\->new( \*(Aq/var/log/syslog\*(Aq, year => 2001); \& while(my $sl = $parser\->next) { \& ... access $sl\->{timestamp|host|program|pid|text} ... \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Unix syslogs are convenient to read for humans but because of small differences between operating systems and things like 'last message repeated xx times' not very easy to parse by a script. .PP Parse::Syslog presents a simple interface to parse syslog files: you create a parser on a file (with \fBnew\fR) and call \fBnext\fR to get one line at a time with Unix-timestamp, host, program, pid and text returned in a hash-reference. .SS "Constructing a Parser" .IX Subsection "Constructing a Parser" \&\fBnew\fR requires as first argument a source from where to get the syslog lines. It can be: .IP "\(bu" 4 a file-name for the syslog-file to be parsed. .IP "\(bu" 4 an IO::Handle object. .IP "\(bu" 4 a File::Tail object as first argument, in which case the \fIread\fR method will be called to get lines to process. .PP After the file-name (or File::Tail object), you can specify options as a hash. The following options are defined: .IP "\fBtype\fR" 8 .IX Item "type" Format of the \*(L"syslog\*(R" file. Can be one of: .RS 8 .IP "\fIsyslog\fR" 8 .IX Item "syslog" Traditional \*(L"syslog\*(R" (default) .IP "\fImetalog\fR" 8 .IX Item "metalog" Metalog (see http://metalog.sourceforge.net/) .RE .RS 8 .RE .IP "\fByear\fR" 8 .IX Item "year" Syslog files usually do store the time of the event without year. With this option you can specify the start-year of this log. If not specified, it will be set to the current year. .IP "\fB\s-1GMT\s0\fR" 8 .IX Item "GMT" If this option is set, the time in the syslog will be converted assuming it is \&\s-1GMT\s0 time instead of local time. .IP "\fBrepeat\fR" 8 .IX Item "repeat" Parse::Syslog will by default repeat xx times events that are followed by messages like 'last message repeated xx times'. If you set this option to false, it won't do that. .IP "\fBarrayref\fR" 8 .IX Item "arrayref" If this option is true, \fInext\fR will return an array-ref instead of a hash-ref (and is thus a bit faster), with the following contents: .RS 8 .IP "0:" 4 .IX Item "0:" timestamp .IP "1:" 4 .IX Item "1:" host .IP "2:" 4 .IX Item "2:" program .IP "3:" 4 .IX Item "3:" pid .IP "4:" 4 .IX Item "4:" text .RE .RS 8 .RE .IP "\fBlocale\fR" 8 .IX Item "locale" Optional. Specifies an additional locale name or the array of locale names for the parsing of log files with national characters. .IP "\fBallow_future\fR" 8 .IX Item "allow_future" If true will allow for timestamps in the future. Otherwise timestamps of one day in the future and more will not be returned (as a safety measure against wrong configurations, bogus \-\-year arguments, etc.) .SS "Parsing the file" .IX Subsection "Parsing the file" The file is parse one line at a time by calling the \fBnext\fR method, which returns a hash-reference containing the following keys: .IP "\fBtimestamp\fR" 10 .IX Item "timestamp" Unix timestamp for the event. .IP "\fBhost\fR" 10 .IX Item "host" Host-name where the event did happen. .IP "\fBprogram\fR" 10 .IX Item "program" Program-name of the program that generated the event. .IP "\fBpid\fR" 10 .IX Item "pid" \&\s-1PID\s0 of the Program that generated the event. This information is not always available for every operating system. .IP "\fBtext\fR" 10 .IX Item "text" Text description of the event. .IP "\fBmsgid\fR" 10 .IX Item "msgid" Message numeric identifier, available only on Solaris >= 8 with \*(L"message \s-1ID\s0 generation\*(R" enabled". .IP "\fBfacility\fR" 10 .IX Item "facility" Log facility name, available only on Solaris >= 8 with \*(L"message \s-1ID\s0 generation\*(R" enabled". .IP "\fBlevel\fR" 10 .IX Item "level" Log level, available only on Solaris >= 8 with \*(L"message \s-1ID\s0 generation\*(R" enabled". .SS "\s-1BUGS\s0" .IX Subsection "BUGS" There are many small differences in the syslog syntax between operating systems. This module has been tested for syslog files produced by the following operating systems: .PP .Vb 3 \& Debian GNU/Linux 2.4 (sid) \& Solaris 2.6 \& Solaris 8 .Ve .PP Report problems for these and other operating systems to the author. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2001, Swiss Federal Institute of Technology, Zurich. All Rights Reserved. .SH "LICENSE" .IX Header "LICENSE" This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "AUTHOR" .IX Header "AUTHOR" David Schweikert .SH "HISTORY" .IX Header "HISTORY" .Vb 11 \& 2001\-08\-12 ds 0.01 first version \& 2001\-08\-19 ds 0.02 fix \*(Aqlast message repeated xx times\*(Aq, Solaris 8 problems \& 2001\-08\-20 ds 0.03 implemented GMT option, year specification, File::Tail \& 2001\-10\-31 ds 0.04 faster time parsing, implemented \*(Aqarrayref\*(Aq option, better time\-increment algorithm \& 2002\-01\-29 ds 0.05 ignore \-\- MARK \-\- lines, low\-case months, space in program names \& 2002\-05\-02 ds 1.00 HP\-UX fixes, parse \*(Aqabove message repeats xx times\*(Aq \& 2002\-05\-25 ds 1.01 added support for localized month names (uchum@mail.ru) \& 2002\-10\-28 ds 1.02 fix off\-by\-one\-hour error when running during daylight saving time switch \& 2004\-01\-19 ds 1.03 do not allow future dates (if allow_future is not true) \& 2004\-07\-11 ds 1.04 added support for type \*(Aqmetalog\*(Aq \& 2005\-12\-24 ds 1.05 allow passing of a IO::Handle object to new .Ve