log2mail 0.0.1.pre2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,92 @@
1
+ module Log2mail
2
+
3
+ class ReportFactory
4
+
5
+ def initialize( config )
6
+ @config = config
7
+ end
8
+
9
+ def reports_from_hit( hit )
10
+ reps = []
11
+ mailtos = @config.mailtos_for_pattern( hit.file, hit.pattern )
12
+ mailtos.each do |mailto|
13
+ settings = @config.settings_for_mailto( hit.file, hit.pattern, mailto )
14
+ r = Report.new
15
+ r.recipients = mailto
16
+ r.from = settings[:fromaddr] if settings[:fromaddr]
17
+ r.template = settings[:template] if settings[:template]
18
+ r.sendmail_command = settings[:sendmail] if settings[:sendmail]
19
+ r.hit = hit
20
+ reps << r
21
+ end
22
+ reps
23
+ end
24
+
25
+ end
26
+
27
+
28
+ class Report
29
+
30
+ attr_accessor :recipients, :from, :subject, :template
31
+ attr_accessor :hit
32
+
33
+ attr_reader :sendmail_location, :sendmail_arguments
34
+
35
+ def initialize
36
+ @recipients = []
37
+ @from = "log2mail"
38
+ @subject = "[Log2mail]"
39
+ end
40
+
41
+ def deliver
42
+ m = Mail.new
43
+ m.to = Array(@recipients).join(',')
44
+ m.from = @from
45
+ m.subject = @subject
46
+ m.body = body_from_template
47
+ if @sendmail_location
48
+ m.delivery_method :sendmail, :location => @sendmail_location, :arguments => String(@sendmail_arguments)
49
+ end
50
+ m.deliver!
51
+ $logger.info "Delivered report to #{m.to}."
52
+ # FIXME: state message id instead full report
53
+ $logger.debug m.to_s
54
+ rescue
55
+ # FIXME: state message id instead full report
56
+ $logger.warn "Failed to deliver report: #{m}. Reason: #{$!.inspect}"
57
+ end
58
+
59
+ def sendmail_command=(txt)
60
+ return unless txt
61
+ s = txt.split(/^(\S+)\s*(.*)$/)
62
+ @sendmail_location = s[1]
63
+ @sendmail_arguments = s[2]
64
+ self
65
+ end
66
+
67
+ private
68
+
69
+ def body_from_template
70
+ if @template
71
+ template = IO.read(@template)
72
+ else
73
+ template = <<-TEMPLATE
74
+ Hello!
75
+
76
+ We have matched your pattern "%m" in "%F" %n times:
77
+
78
+ %l
79
+
80
+ Yours,
81
+ log2mail.
82
+ TEMPLATE
83
+ end
84
+ template.gsub!('%f', @from)
85
+ template.gsub!('%t', Array(@recipients).join(', '))
86
+ template.gsub!('%m', String(@hit.pattern) )
87
+ template.gsub!('%F', @hit.file)
88
+ template.gsub!('%l', @hit.matched_text.chomp)
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,6 @@
1
+ module Log2mail
2
+ PROGNAME = 'log2mail.rb'
3
+ VERSION = "0.0.1.pre2"
4
+ AUTHOR = "Markus Strauss"
5
+ AUTHOR_MAIL = "log2mail@dev.sieb.mx"
6
+ end
@@ -0,0 +1,61 @@
1
+ require_relative 'file'
2
+
3
+ module Log2mail
4
+ class Watcher
5
+
6
+ # class <<self
7
+ # attr_accessor :logfile, :maxbufsize
8
+ # attr_reader :pattern
9
+ # end
10
+
11
+ def initialize( config, sleeptime )
12
+ fail Error, 'Invalid configuration.' unless config.instance_of?(Log2mail::Config)
13
+ @file_patterns = config.file_patterns
14
+ @files = @file_patterns.keys.map {|f| Log2mail::File.new(f, @file_patterns[f] ) }
15
+ @sleeptime = sleeptime
16
+
17
+ @report_queue = []
18
+ @factory = ReportFactory.new(config)
19
+ end
20
+
21
+ def run
22
+ open_and_seek_files
23
+ loop do
24
+ return unless running?
25
+ @files.each do |file|
26
+ if file.eof?
27
+ file.open if file.rotated?
28
+ end
29
+ hits = file.parse(file.read_to_end)
30
+ report hits unless hits.empty?
31
+ end
32
+ sleep @sleeptime
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def running?
39
+ true
40
+ end
41
+
42
+ def open_and_seek_files
43
+ @files.each do |file|
44
+ file.open and file.seek_to_end
45
+ end
46
+ end
47
+
48
+ def log(msg, sev = ::Logger::DEBUG)
49
+ $logger.log sev, '%s%s [%s]' % [msg, $/, caller.first]
50
+ end
51
+
52
+ def report(hits)
53
+ reports = hits.map { |hit| @factory.reports_from_hit( hit ) }.flatten
54
+ reports.each do |report|
55
+ log("Sending report: #{report.inspect}")
56
+ report.deliver
57
+ end
58
+ end
59
+
60
+ end
61
+ end
data/lib/log2mail.rb ADDED
@@ -0,0 +1,8 @@
1
+ %w{ main mail terminal-table }.each {|r| require r}
2
+ %w{ kernel string main }.each {|r| require_relative "ext/#{r}"}
3
+ begin
4
+ require 'syslog/logger'
5
+ rescue LoadError
6
+ require_relative 'ext/syslog_logger'
7
+ end
8
+ %w{ version error logger_formatter config watcher hit report }.each {|r| require_relative "log2mail/#{r}"}
data/log2mail.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'log2mail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'log2mail'
8
+ spec.version = Log2mail::VERSION
9
+ spec.authors = Log2mail::AUTHOR
10
+ spec.email = Log2mail::AUTHOR_MAIL
11
+ spec.summary = %q{monitors (log) files for patterns and reports hits by mail}
12
+ spec.description = %q{A regular expression based log file monitoring tool.}
13
+ spec.homepage = 'https://github.com/mstrauss/log2mail.rb/'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+ spec.extra_rdoc_files = Dir.glob('man/*.html')
21
+
22
+ spec.required_ruby_version = '>= 1.9.3'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'factory_girl'
28
+ spec.add_development_dependency 'ronn'
29
+ spec.add_development_dependency 'cucumber'
30
+ spec.add_development_dependency 'rake-notes'
31
+ spec.add_runtime_dependency 'mail', '~> 2.6', '>= 2.6.3'
32
+ spec.add_runtime_dependency 'gem-man', '~> 0.3', '>= 0.3.0'
33
+ spec.add_runtime_dependency 'main', '~> 6.1.0'
34
+ spec.add_runtime_dependency 'terminal-table'
35
+ end
data/man/log2mail.1 ADDED
@@ -0,0 +1,121 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "LOG2MAIL\.RB" "1" "December 2014" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBlog2mail\.rb\fR \- monitors (log) files for patterns and reports hits by mail
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBlog2mail\.rb\fR (start|stop|status|configtest) [\fIoptions\fR]:
11
+ .
12
+ .SH "DESCRIPTION"
13
+ \fBlog2mail\.rb\fR helps having an eye on your systems\' log files\. It efficiently monitors multiple files and reports as soon as specified (regular expression) patterns match\.
14
+ .
15
+ .P
16
+ On startup, \fBlog2mail\.rb\fR opens all files on the \'watch list\' and seeks to EOF\. All new data are parsed about once a minute (see \fB\-\-sleeptime\fR)\. Matched patterns are reported to the configured mail address(es) (see \fBmailto\fR configuration option)\.
17
+ .
18
+ .P
19
+ Log files are reopened automatically when rotated\.
20
+ .
21
+ .P
22
+ \fBlog2mail\.rb\fR is a pure ruby clone of log2mail \fIhttps://packages\.debian\.org/squeeze/log2mail\fR which supports most of the original\'s features and configuration syntax and adds multiline regular expression matching\. Actually it should be possible to use \fBlog2mail\.rb\fR with your existing configuration you may have for log2mail(8)\.
23
+ .
24
+ .SH "OPTIONS"
25
+ .
26
+ .TP
27
+ \fB\-\-config\fR=\fIpath\fR, \fB\-c\fR \fIpath\fR
28
+ Specifies the configuration file or directory path\. If \fIpath\fR is a directory, all files (except such ending in \fB~\fR or \fB#\fR) are parsed in sorted order\. Sorting is by character code, i\.e\. 0\-9 before A\-Z followed by a\-z\. Default value: \fB/etc/log2mail/conf\fR\. This can also be set by environment variable \fBLOG2MAIL_CONF\fR\.
29
+ .
30
+ .TP
31
+ \fB\-\-sleeptime\fR=\fIseconds\fR
32
+ Specifies at which interval (in seconds) the log files are parsed\. Default value: 60\.
33
+ .
34
+ .SH "ENVIRONMENT"
35
+ \fBlog2mail\.rb\fR uses the environment variable \fBLOG2MAIL_CONF\fR, if present (see option \fB\-\-config\fR)\. The value supplied by option takes precedence\.
36
+ .
37
+ .SH "CONFIGURATION (OLD\-STYLE)"
38
+ The old\-style configuration syntax is directly cloned from log2mail(8)\'s behavior and should be mostly compatible\. It may seem a bit awkward first, but this is how it works: There are two possible top\-level \'sections\', \fBdefaults\fR and \fBfile=\fR\fIpath\-to\-log\-file\fR sections\. The only statement allowed after a \fBfile=\.\.\.\fR section are one or more \fBpattern=\fR\fIpattern\fR entries\. After the \fBpattern=\.\.\.\fR there may be one or more \fBmailto=\fR\fIsingle\-mail\-recipient\fR entries\. After each \fBmailto=\.\.\.\fR there may be options for that recipient\. Also, these options are set from the special \fBdefaults\fR section, if present (usually it is)\.
39
+ .
40
+ .P
41
+ The basic layout looks like follows:
42
+ .
43
+ .IP "" 4
44
+ .
45
+ .nf
46
+
47
+ # comments start with pound sign (aka hash or number sign)
48
+
49
+ defaults
50
+ fromaddr = DEFAULT FROMADDR
51
+ sendtime = DEFAULT SENDTIME # seconds
52
+ resendtime = DEFAULT RESENDTIME # seconds
53
+ maxlines = DEFAULT MAXLINES # number of lines
54
+ template = DEFAULT TEMPLATE # filename or path
55
+ sendmail = DEFAULT SENDMAIL # path to executable with arguments
56
+ mailto = DEFAULT RECIPIENT # new to log2mail\.rb
57
+ # awkward, not recommended, but possible:
58
+ pattern = DEFAULT PATTERN # this pattern would be applied to every file
59
+ mailto = DEFAULT RECIPIENT for previous DEFAULT PATTERN
60
+
61
+ # one or more file sections follow
62
+ file = FILENAME
63
+
64
+ # each file can have one or more patterns
65
+ pattern = PATTERN
66
+
67
+ # each pattern can have one or more mailto recipients
68
+ # each recipient gets its own mailto=\.\.\. statement
69
+ mailto = MAIL
70
+
71
+ # every option NOT stated here is supplied from defaults
72
+ fromaddr = \.\.\.
73
+ sendtime = \.\.\.
74
+ resendtime = \.\.\.
75
+ maxlines = \.\.\.
76
+ template = \.\.\.
77
+ sendmail = \.\.\.
78
+
79
+ # "include" includes the contents of file at the exact place of the
80
+ # include statement
81
+ include = PATH TO FILE
82
+ .
83
+ .fi
84
+ .
85
+ .IP "" 0
86
+ .
87
+ .P
88
+ Note that indentation is done for readability purposes only\. It serves no role syntactically\.
89
+ .
90
+ .P
91
+ Splitting the configuration into multiple files is possible, and convenient when using automation tools to distribute settings\. In opposition to classic log2mail, with \fBlog2mail\.rb\fR it does not matter at which place the \fBdefaults\fR section is parsed\. Keep in mind though, that later definitions may override earlier ones\. In that case a warning is logged\.
92
+ .
93
+ .SH "CONFIGURATION (NEW\-STYLE)"
94
+ None (yet)\. More features might warrant a new configuration syntax\.
95
+ .
96
+ .SH "SECURITY CONSIDERATIONS"
97
+ It is neither necessary nor recommended to run this software as root\.
98
+ .
99
+ .SH "BUGS"
100
+ Configuration options \fBsendtime\fR, \fBresendtime\fR, \fBmaxlines\fR not implemented yet\. Every match produces a single mail which is sent out immediately \- which could produce a lot of mails\.
101
+ .
102
+ .SH "HISTORY"
103
+ December 2014: This software is not feature\-complete and in pre\-release testing\.
104
+ .
105
+ .SH "AUTHOR"
106
+ Markus Strauss <\fIlog2mail@dev\.sieb\.mx\fR>
107
+ .
108
+ .SH "THANKS"
109
+ Many thanks to Michael Krax for writing the classic \fBlog2mail\fR in the first place\.
110
+ .
111
+ .SH "SEE ALSO"
112
+ Documentation for the classic log2mail software by Michael Krax:
113
+ .
114
+ .IP "\(bu" 4
115
+ log2mail(8), log2mail\.conf(5)
116
+ .
117
+ .IP "\(bu" 4
118
+ Configuration notice from the Debian project \fIhttps://raw\.githubusercontent\.com/lordlamer/log2mail/e6beb36644ce74639cbc453e664a08ed15f138b9/Configuration\fR
119
+ .
120
+ .IP "" 0
121
+
@@ -0,0 +1,207 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
+ <meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
6
+ <title>log2mail.rb(1) - monitors (log) files for patterns and reports hits by mail</title>
7
+ <style type='text/css' media='all'>
8
+ /* style: man */
9
+ body#manpage {margin:0}
10
+ .mp {max-width:100ex;padding:0 9ex 1ex 4ex}
11
+ .mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
12
+ .mp h2 {margin:10px 0 0 0}
13
+ .mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
14
+ .mp h3 {margin:0 0 0 4ex}
15
+ .mp dt {margin:0;clear:left}
16
+ .mp dt.flush {float:left;width:8ex}
17
+ .mp dd {margin:0 0 0 9ex}
18
+ .mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
19
+ .mp pre {margin-bottom:20px}
20
+ .mp pre+h2,.mp pre+h3 {margin-top:22px}
21
+ .mp h2+pre,.mp h3+pre {margin-top:5px}
22
+ .mp img {display:block;margin:auto}
23
+ .mp h1.man-title {display:none}
24
+ .mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
25
+ .mp h2 {font-size:16px;line-height:1.25}
26
+ .mp h1 {font-size:20px;line-height:2}
27
+ .mp {text-align:justify;background:#fff}
28
+ .mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
29
+ .mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
30
+ .mp u {text-decoration:underline}
31
+ .mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
32
+ .mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
33
+ .mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
34
+ .mp b.man-ref {font-weight:normal;color:#434241}
35
+ .mp pre {padding:0 4ex}
36
+ .mp pre code {font-weight:normal;color:#434241}
37
+ .mp h2+pre,h3+pre {padding-left:0}
38
+ ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
39
+ ol.man-decor {width:100%}
40
+ ol.man-decor li.tl {text-align:left}
41
+ ol.man-decor li.tc {text-align:center;letter-spacing:4px}
42
+ ol.man-decor li.tr {text-align:right;float:right}
43
+ </style>
44
+ <style type='text/css' media='all'>
45
+ /* style: toc */
46
+ .man-navigation {display:block !important;position:fixed;top:0;left:113ex;height:100%;width:100%;padding:48px 0 0 0;border-left:1px solid #dbdbdb;background:#eee}
47
+ .man-navigation a,.man-navigation a:hover,.man-navigation a:link,.man-navigation a:visited {display:block;margin:0;padding:5px 2px 5px 30px;color:#999;text-decoration:none}
48
+ .man-navigation a:hover {color:#111;text-decoration:underline}
49
+ </style>
50
+ </head>
51
+ <!--
52
+ The following styles are deprecated and will be removed at some point:
53
+ div#man, div#man ol.man, div#man ol.head, div#man ol.man.
54
+
55
+ The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
56
+ .man-navigation should be used instead.
57
+ -->
58
+ <body id='manpage'>
59
+ <div class='mp' id='man'>
60
+
61
+ <div class='man-navigation' style='display:none'>
62
+ <a href="#NAME">NAME</a>
63
+ <a href="#SYNOPSIS">SYNOPSIS</a>
64
+ <a href="#DESCRIPTION">DESCRIPTION</a>
65
+ <a href="#OPTIONS">OPTIONS</a>
66
+ <a href="#ENVIRONMENT">ENVIRONMENT</a>
67
+ <a href="#CONFIGURATION-OLD-STYLE-">CONFIGURATION (OLD-STYLE)</a>
68
+ <a href="#CONFIGURATION-NEW-STYLE-">CONFIGURATION (NEW-STYLE)</a>
69
+ <a href="#SECURITY-CONSIDERATIONS">SECURITY CONSIDERATIONS</a>
70
+ <a href="#BUGS">BUGS</a>
71
+ <a href="#HISTORY">HISTORY</a>
72
+ <a href="#AUTHOR">AUTHOR</a>
73
+ <a href="#THANKS">THANKS</a>
74
+ <a href="#SEE-ALSO">SEE ALSO</a>
75
+ </div>
76
+
77
+ <ol class='man-decor man-head man head'>
78
+ <li class='tl'>log2mail.rb(1)</li>
79
+ <li class='tc'></li>
80
+ <li class='tr'>log2mail.rb(1)</li>
81
+ </ol>
82
+
83
+ <h2 id="NAME">NAME</h2>
84
+ <p class="man-name">
85
+ <code>log2mail.rb</code> - <span class="man-whatis">monitors (log) files for patterns and reports hits by mail</span>
86
+ </p>
87
+
88
+ <h2 id="SYNOPSIS">SYNOPSIS</h2>
89
+
90
+ <p><code>log2mail.rb</code> (start|stop|status|configtest) [<var>options</var>]:</p>
91
+
92
+ <h2 id="DESCRIPTION">DESCRIPTION</h2>
93
+
94
+ <p><code>log2mail.rb</code> helps having an eye on your systems' log files. It efficiently monitors multiple files and reports as soon as specified (regular expression) patterns match.</p>
95
+
96
+ <p>On startup, <code>log2mail.rb</code> opens all files on the 'watch list' and seeks to EOF. All new data are parsed about once a minute (see <code>--sleeptime</code>). <!-- If necessary, i.e. when multiline patterns are set for the file, every new data is put into a fixed-size buffer. The buffer is rolled over when it gets full. --> Matched patterns are reported to the configured mail address(es) (see <code>mailto</code> configuration option).</p>
97
+
98
+ <p>Log files are reopened automatically when rotated.</p>
99
+
100
+ <p><code>log2mail.rb</code> is a pure ruby clone of <a href="https://packages.debian.org/squeeze/log2mail">log2mail</a> which supports most of the original's features and configuration syntax and adds multiline regular expression matching. Actually it should be possible to use <code>log2mail.rb</code> with your existing configuration you may have for <span class="man-ref">log2mail<span class="s">(8)</span></span>.</p>
101
+
102
+ <h2 id="OPTIONS">OPTIONS</h2>
103
+
104
+ <dl>
105
+ <dt><code>--config</code>=<var>path</var>, <code>-c</code> <var>path</var></dt><dd><p>Specifies the configuration file or directory path. If <var>path</var> is a directory, all files (except such ending in <code>~</code> or <code>#</code>) are parsed in sorted order. Sorting is by character code, i.e. 0-9 before A-Z followed by a-z.
106
+ Default value: <code>/etc/log2mail/conf</code>.
107
+ This can also be set by environment variable <code>LOG2MAIL_CONF</code>.</p></dd>
108
+ <dt><code>--sleeptime</code>=<var>seconds</var></dt><dd><p>Specifies at which interval (in seconds) the log files are parsed. Default value: 60.</p></dd>
109
+ </dl>
110
+
111
+
112
+ <h2 id="ENVIRONMENT">ENVIRONMENT</h2>
113
+
114
+ <p><code>log2mail.rb</code> uses the environment variable <code>LOG2MAIL_CONF</code>, if present (see option <code>--config</code>). The value supplied by option takes precedence.</p>
115
+
116
+ <h2 id="CONFIGURATION-OLD-STYLE-">CONFIGURATION (OLD-STYLE)</h2>
117
+
118
+ <p>The old-style configuration syntax is directly cloned from <span class="man-ref">log2mail<span class="s">(8)</span></span>'s behavior and should be mostly compatible. It may seem a bit awkward first, but this is how it works: There are two possible top-level 'sections', <code>defaults</code> and <code>file=</code><var>path-to-log-file</var> sections. The only statement allowed after a <code>file=...</code> section are one or more <code>pattern=</code><var>pattern</var> entries. After the <code>pattern=...</code> there may be one or more <code>mailto=</code><var>single-mail-recipient</var> entries. After each <code>mailto=...</code> there may be options for that recipient. Also, these options are set from the special <code>defaults</code> section, if present (usually it is).</p>
119
+
120
+ <p>The basic layout looks like follows:</p>
121
+
122
+ <pre><code># comments start with pound sign (aka hash or number sign)
123
+
124
+ defaults
125
+ fromaddr = DEFAULT FROMADDR
126
+ sendtime = DEFAULT SENDTIME # seconds
127
+ resendtime = DEFAULT RESENDTIME # seconds
128
+ maxlines = DEFAULT MAXLINES # number of lines
129
+ template = DEFAULT TEMPLATE # filename or path
130
+ sendmail = DEFAULT SENDMAIL # path to executable with arguments
131
+ mailto = DEFAULT RECIPIENT # new to log2mail.rb
132
+ # awkward, not recommended, but possible:
133
+ pattern = DEFAULT PATTERN # this pattern would be applied to every file
134
+ mailto = DEFAULT RECIPIENT for previous DEFAULT PATTERN
135
+
136
+ # one or more file sections follow
137
+ file = FILENAME
138
+
139
+ # each file can have one or more patterns
140
+ pattern = PATTERN
141
+
142
+ # each pattern can have one or more mailto recipients
143
+ # each recipient gets its own mailto=... statement
144
+ mailto = MAIL
145
+
146
+ # every option NOT stated here is supplied from defaults
147
+ fromaddr = ...
148
+ sendtime = ...
149
+ resendtime = ...
150
+ maxlines = ...
151
+ template = ...
152
+ sendmail = ...
153
+
154
+ # "include" includes the contents of file at the exact place of the
155
+ # include statement
156
+ include = PATH TO FILE
157
+ </code></pre>
158
+
159
+ <p>Note that indentation is done for readability purposes only. It serves no role syntactically.</p>
160
+
161
+ <p>Splitting the configuration into multiple files is possible, and convenient when using automation tools to distribute settings. In opposition to classic log2mail, with <code>log2mail.rb</code> it does not matter at which place the <code>defaults</code> section is parsed. Keep in mind though, that later definitions may override earlier ones. In that case a warning is logged.</p>
162
+
163
+ <h2 id="CONFIGURATION-NEW-STYLE-">CONFIGURATION (NEW-STYLE)</h2>
164
+
165
+ <p>None (yet). More features might warrant a new configuration syntax.</p>
166
+
167
+ <h2 id="SECURITY-CONSIDERATIONS">SECURITY CONSIDERATIONS</h2>
168
+
169
+ <p>It is neither necessary nor recommended to run this software as root.</p>
170
+
171
+ <h2 id="BUGS">BUGS</h2>
172
+
173
+ <p>Configuration options <code>sendtime</code>, <code>resendtime</code>, <code>maxlines</code> not implemented yet. Every match produces a single mail which is sent out immediately - which could produce a lot of mails.</p>
174
+
175
+ <h2 id="HISTORY">HISTORY</h2>
176
+
177
+ <p>December 2014:
178
+ This software is not feature-complete and in pre-release testing.</p>
179
+
180
+ <h2 id="AUTHOR">AUTHOR</h2>
181
+
182
+ <p>Markus Strauss &lt;<a href="&#109;&#97;&#x69;&#108;&#116;&#111;&#x3a;&#108;&#111;&#x67;&#x32;&#x6d;&#x61;&#105;&#x6c;&#x40;&#x64;&#101;&#118;&#x2e;&#115;&#x69;&#x65;&#x62;&#46;&#x6d;&#120;" data-bare-link="true">&#108;&#111;&#103;&#50;&#109;&#x61;&#x69;&#108;&#x40;&#100;&#x65;&#118;&#46;&#x73;&#x69;&#101;&#98;&#x2e;&#x6d;&#x78;</a>></p>
183
+
184
+ <h2 id="THANKS">THANKS</h2>
185
+
186
+ <p>Many thanks to Michael Krax for writing the classic <strong>log2mail</strong> in the first place.</p>
187
+
188
+ <h2 id="SEE-ALSO">SEE ALSO</h2>
189
+
190
+ <p>Documentation for the classic log2mail software by Michael Krax:</p>
191
+
192
+ <ul>
193
+ <li><span class="man-ref">log2mail<span class="s">(8)</span></span>, <span class="man-ref">log2mail.conf<span class="s">(5)</span></span></li>
194
+ <li><a href="https://raw.githubusercontent.com/lordlamer/log2mail/e6beb36644ce74639cbc453e664a08ed15f138b9/Configuration">Configuration notice from the Debian project</a></li>
195
+ </ul>
196
+
197
+
198
+
199
+ <ol class='man-decor man-foot man foot'>
200
+ <li class='tl'></li>
201
+ <li class='tc'>December 2014</li>
202
+ <li class='tr'>log2mail.rb(1)</li>
203
+ </ol>
204
+
205
+ </div>
206
+ </body>
207
+ </html>
@@ -0,0 +1,108 @@
1
+ log2mail.rb(1) -- monitors (log) files for patterns and reports hits by mail
2
+ ============================================================================
3
+
4
+ ## SYNOPSIS
5
+
6
+ `log2mail.rb` (start|stop|status|configtest) [<options>]:
7
+
8
+ ## DESCRIPTION
9
+
10
+ `log2mail.rb` helps having an eye on your systems' log files. It efficiently monitors multiple files and reports as soon as specified (regular expression) patterns match.
11
+
12
+ On startup, `log2mail.rb` opens all files on the 'watch list' and seeks to EOF. All new data are parsed about once a minute (see `--sleeptime`). <!-- If necessary, i.e. when multiline patterns are set for the file, every new data is put into a fixed-size buffer. The buffer is rolled over when it gets full. --> Matched patterns are reported to the configured mail address(es) (see `mailto` configuration option).
13
+
14
+ Log files are reopened automatically when rotated.
15
+
16
+ `log2mail.rb` is a pure ruby clone of [log2mail](https://packages.debian.org/squeeze/log2mail) which supports most of the original's features and configuration syntax and adds multiline regular expression matching. Actually it should be possible to use `log2mail.rb` with your existing configuration you may have for log2mail(8).
17
+
18
+ ## OPTIONS
19
+
20
+ * `--config`=<path>, `-c` <path>:
21
+ Specifies the configuration file or directory path. If <path> is a directory, all files (except such ending in `~` or `#`) are parsed in sorted order. Sorting is by character code, i.e. 0-9 before A-Z followed by a-z.
22
+ Default value: `/etc/log2mail/conf`.
23
+ This can also be set by environment variable `LOG2MAIL_CONF`.
24
+
25
+ * `--sleeptime`=<seconds>:
26
+ Specifies at which interval (in seconds) the log files are parsed. Default value: 60.
27
+
28
+ ## ENVIRONMENT
29
+
30
+ `log2mail.rb` uses the environment variable `LOG2MAIL_CONF`, if present (see option `--config`). The value supplied by option takes precedence.
31
+
32
+ ## CONFIGURATION (OLD-STYLE)
33
+
34
+ The old-style configuration syntax is directly cloned from log2mail(8)'s behavior and should be mostly compatible. It may seem a bit awkward first, but this is how it works: There are two possible top-level 'sections', `defaults` and `file=`<path-to-log-file> sections. The only statement allowed after a `file=...` section are one or more `pattern=`<pattern> entries. After the `pattern=...` there may be one or more `mailto=`<single-mail-recipient> entries. After each `mailto=...` there may be options for that recipient. Also, these options are set from the special `defaults` section, if present (usually it is).
35
+
36
+ The basic layout looks like follows:
37
+
38
+ # comments start with pound sign (aka hash or number sign)
39
+
40
+ defaults
41
+ fromaddr = DEFAULT FROMADDR
42
+ sendtime = DEFAULT SENDTIME # seconds
43
+ resendtime = DEFAULT RESENDTIME # seconds
44
+ maxlines = DEFAULT MAXLINES # number of lines
45
+ template = DEFAULT TEMPLATE # filename or path
46
+ sendmail = DEFAULT SENDMAIL # path to executable with arguments
47
+ mailto = DEFAULT RECIPIENT # new to log2mail.rb
48
+ # awkward, not recommended, but possible:
49
+ pattern = DEFAULT PATTERN # this pattern would be applied to every file
50
+ mailto = DEFAULT RECIPIENT for previous DEFAULT PATTERN
51
+
52
+ # one or more file sections follow
53
+ file = FILENAME
54
+
55
+ # each file can have one or more patterns
56
+ pattern = PATTERN
57
+
58
+ # each pattern can have one or more mailto recipients
59
+ # each recipient gets its own mailto=... statement
60
+ mailto = MAIL
61
+
62
+ # every option NOT stated here is supplied from defaults
63
+ fromaddr = ...
64
+ sendtime = ...
65
+ resendtime = ...
66
+ maxlines = ...
67
+ template = ...
68
+ sendmail = ...
69
+
70
+ # "include" includes the contents of file at the exact place of the
71
+ # include statement
72
+ include = PATH TO FILE
73
+
74
+ Note that indentation is done for readability purposes only. It serves no role syntactically.
75
+
76
+ Splitting the configuration into multiple files is possible, and convenient when using automation tools to distribute settings. In opposition to classic log2mail, with `log2mail.rb` it does not matter at which place the `defaults` section is parsed. Keep in mind though, that later definitions may override earlier ones. In that case a warning is logged.
77
+
78
+ ## CONFIGURATION (NEW-STYLE)
79
+
80
+ None (yet). More features might warrant a new configuration syntax.
81
+
82
+ ## SECURITY CONSIDERATIONS
83
+
84
+ It is neither necessary nor recommended to run this software as root.
85
+
86
+ ## BUGS
87
+
88
+ Configuration options `sendtime`, `resendtime`, `maxlines` not implemented yet. Every match produces a single mail which is sent out immediately - which could produce a lot of mails.
89
+
90
+ ## HISTORY
91
+
92
+ December 2014:
93
+ This software is not feature-complete and in pre-release testing.
94
+
95
+ ## AUTHOR
96
+
97
+ Markus Strauss <<log2mail@dev.sieb.mx>>
98
+
99
+ ## THANKS
100
+
101
+ Many thanks to Michael Krax for writing the classic **log2mail** in the first place.
102
+
103
+ ## SEE ALSO
104
+
105
+ Documentation for the classic log2mail software by Michael Krax:
106
+
107
+ * log2mail(8), log2mail.conf(5)
108
+ * [Configuration notice from the Debian project]( https://raw.githubusercontent.com/lordlamer/log2mail/e6beb36644ce74639cbc453e664a08ed15f138b9/Configuration)