[master] analog, a generator of rsyslog config files to monitor remote installs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 scripts/analog |  142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 142 insertions(+), 0 deletions(-)
 create mode 100755 scripts/analog

diff --git a/scripts/analog b/scripts/analog
new file mode 100755
index 0000000..1ce7b78
--- /dev/null
+++ b/scripts/analog
@@ -0,0 +1,142 @@
+#! /usr/bin/python 
+#
+# analog: Remote logging manager for the Red Hat Installer
+#
+# Copyright (C) 2010
+# Red Hat, Inc.  All rights reserved.
+#
+# 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, or
+# (at your option) any later version.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+#
+# Author: Ales Kozumplik <akozumpl@xxxxxxxxxx>
+#
+
+import errno
+import optparse
+import os
+import os.path
+import signal
+import sys
+
+DEFAULT_PORT = 6080
+DEFAULT_ANALOG_DIR = '.analog'
+USAGE = "%prog [options] <log directory root>"
+HINT = """You can start the rsyslog daemon like this now:
+/sbin/rsyslogd -c 4 -f %s -i <a new pid file>"""
+
+RSYSLOG_TEMPLATE ="""
+#### MODULES ####
+# Provides TCP syslog reception
+$ModLoad imtcp.so  
+$InputTCPServerRun %(port)s
+
+#### GLOBAL DIRECTIVES ####
+
+# Use default timestamp format
+$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
+
+# File syncing capability is disabled by default. This feature is usually not required, 
+# not useful and an extreme performance hit
+#$ActionFileEnableSync on
+
+
+#### RULES ####
+
+$template anaconda_tty4, "%%timestamp:8:$:date-rfc3164%%,%%timestamp:1:3:date-subseconds%% %%syslogseverity-text:::uppercase%% %%programname%%:%%msg%%\\n"
+$template anaconda_debug, "%%syslogfacility-text%%|%%hostname%%|%%syslogseverity-text%%|%%syslogtag%%|%%msg%%\\n"
+$template anaconda_syslog, "%%timestamp:8:$:date-rfc3164%%,%%timestamp:1:3:date-subseconds%% %%syslogseverity-text:::uppercase%% %%programname%%:%%msg%%\\n"
+
+$template path_syslog, "%(directory)s/%%FROMHOST-IP%%/syslog
+$template path_anaconda, "%(directory)s/%%FROMHOST-IP%%/anaconda.log"
+$template path_program, "%(directory)s/%%FROMHOST-IP%%/program.log"
+$template path_storage, "%(directory)s/%%FROMHOST-IP%%/storage.log"
+$template path_sysimage, "%(directory)s/%%FROMHOST-IP%%/install.log.syslog"
+
+*.*                                                  %(directory)s/debug_all.log;anaconda_debug
+
+kern.*;\\
+daemon.*                                             ?path_syslog;anaconda_syslog
+
+:programname, contains, "loader"                     ?path_anaconda;anaconda_syslog
+:programname, contains, "anaconda"                   ?path_anaconda;anaconda_syslog
+:programname, contains, "program"                    ?path_program;anaconda_syslog
+:programname, contains, "storage"                    ?path_storage;anaconda_syslog
+:hostname, contains, "sysimage"                      ?path_sysimage;anaconda_syslog
+
+# discard those that we logged
+:programname, contains, "rsyslogd"                   ~
+:programname, contains, "loader"                     ~
+:programname, contains, "anaconda"                   ~
+:programname, contains, "program"                    ~
+:programname, contains, "storage"                    ~
+:hostname, contains, "sysimage"                      ~
+kern.*                                               ~
+daemon.*                                             ~
+# dump the rest
+*.*                                                  %(directory)s/debug_unknown_source.log;anaconda_debug
+
+"""
+
+# option parsing
+class OptParserError(Exception):
+    def __str__(self):
+        return self.args[0]
+
+    @property
+    def parser(self):
+        return self.args[1]
+    
+def get_opts():
+    parser = optparse.OptionParser(usage=USAGE,
+                                   add_help_option=False)
+    parser.add_option ('-h', '--help', action="callback", callback=help_and_exit,
+                       help="Display this help")
+    parser.add_option ('-p', type="int", dest="port", 
+                       default=DEFAULT_PORT, 
+                       help="TCP port the rsyslog daemon will listen on")
+    parser.add_option ('-o', type="string", dest="output", 
+                       default=None, 
+                       help="Output file")
+    (options, args) = parser.parse_args()
+    if len(args) < 1:
+        raise OptParserError("no log root directory given", parser)
+    options.log_root = args[0]
+    args = args[1:]
+    return (options, args)
+
+def help_and_exit(option, opt, value, parser):
+    parser.print_help()
+    sys.exit(0)
+
+def generate_rsyslog_config(port, directory):
+    values = {
+        "directory" : directory,
+        "port"      : port
+        }
+    config = RSYSLOG_TEMPLATE % values
+    return config
+
+if __name__ == "__main__":
+    try:
+        (options, args) = get_opts()
+    except OptParserError as exc:
+        exc.parser.error(str(exc))
+        sys.exit(1)
+    directory = os.path.join(os.getcwd(), options.log_root)
+    config = generate_rsyslog_config(options.port, directory)
+    if options.output:
+        with open(options.output, 'w') as file:
+            file.write(config)
+        print HINT % options.output
+    else:
+        print config
-- 
1.6.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux