summaryrefslogtreecommitdiffstats
path: root/logactio
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2012-09-16 01:00:21 +0200
committerDavid Sommerseth <davids@redhat.com>2012-09-16 14:48:55 +0200
commita6893e56c1926c1365b5c217972b76c5491d51ae (patch)
tree7159202724bc3fe8913266a939efe320beb5386b /logactio
downloadlogactio-a6893e56c1926c1365b5c217972b76c5491d51ae.tar.gz
logactio-a6893e56c1926c1365b5c217972b76c5491d51ae.tar.xz
logactio-a6893e56c1926c1365b5c217972b76c5491d51ae.zip
Initial import of logactio
This is the first step of the logactio framework Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'logactio')
-rwxr-xr-xlogactio80
1 files changed, 80 insertions, 0 deletions
diff --git a/logactio b/logactio
new file mode 100755
index 0000000..d56bf70
--- /dev/null
+++ b/logactio
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+#
+# logactio - simple framework for doing configured action on certain
+# log file events
+#
+# Copyright 2012 David Sommerseth <dazo@users.sourceforge.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# For the avoidance of doubt the "preferred form" of this code is one which
+# is in an open unpatent encumbered format. Where cryptographic key signing
+# forms part of the process of creating an executable the information
+# including keys needed to generate an equivalently functional executable
+# are deemed to be part of the source code.
+#
+
+import sys, optparse
+from LogActio import LogActio, Logger
+
+
+if __name__ == '__main__':
+ parser = optparse.OptionParser()
+
+ parser.add_option("-d", "--daemon", action="store_true", default=False,
+ dest="daemon",
+ help="Run as a daemon")
+ parser.add_option("-p", "--pid-file",
+ dest="pidfile", metavar="PID-FILE", default=None,
+ help="Put pid file of logactio in this file")
+ parser.add_option("--stdout-redir",
+ dest="stdoutredir", metavar="FILE", default="/dev/null",
+ help="Redirect all stdout data to this file (only active when running as daemon)")
+ parser.add_option("-c", "--config",
+ dest="cfg", metavar="FILE", default="/etc/logactio.cfg",
+ help="Configuration file for logactio (Default: %default)")
+ parser.add_option("-v", "--verbose", action="count", default=0,
+ dest="verb",
+ help="Increase the log verbosity")
+ parser.add_option("-L", "--log-type", type="choice", choices=["syslog","file"],
+ dest="logtype", default="syslog",
+ help="Should logging go to file or syslog? (default: %default)")
+ parser.add_option("-l", "--log-file",
+ dest="logfile", metavar="LOG-FILE",
+ help="Filename of the log file to use")
+ parser.add_option("-s", "--syslog-id",
+ dest="syslogid", metavar="SYSLOG-NAME", default="logactio",
+ help="syslog ident to use for syslog events")
+ parser.add_option("--trace", action="store_true",
+ dest="trace", default=False,
+ help="On errors, show a backtrace")
+ (opts, args) = parser.parse_args()
+
+ try:
+ if opts.logtype == "syslog":
+ logger = Logger.Logger(Logger.LOGTYPE_SYSLOG, opts.syslogid, opts.verb)
+ elif opts.logtype == "file":
+ logger = Logger.Logger(Logger.LOGTYPE_FILE, opts.logfile, opts.verb)
+ else:
+ raise Exception("Unknown log type '%s'" % opts.logtype)
+
+ main = LogActio(opts.cfg, opts.daemon, opts.pidfile, logger.Log, opts.stdoutredir)
+ main.Run()
+ sys.exit(0)
+ except Exception, e:
+ if opts.trace:
+ import traceback
+ traceback.print_exc(file=sys.stdout)
+ else:
+ print "** ERROR ** %s" % str(e)