aboutsummaryrefslogtreecommitdiffstats
path: root/src/extras
diff options
context:
space:
mode:
authornavid <navid@ef72aa8b-4018-0410-8976-d6e080ef94d8>2007-08-17 13:42:51 +0000
committernavid <navid@ef72aa8b-4018-0410-8976-d6e080ef94d8>2007-08-17 13:42:51 +0000
commit8092e9862adb06e6cec8f02e0dfe3d8a50030949 (patch)
treea764e897e8e571914346f29e8e2123647505cacc /src/extras
parentb451a9da5eedbacd9216409cf8e21b19a0d848c6 (diff)
downloadsos-8092e9862adb06e6cec8f02e0dfe3d8a50030949.tar.gz
merged navid-dev -r r350:r364 into trunk/rhel-5-startr1.7-8
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@368 ef72aa8b-4018-0410-8976-d6e080ef94d8
Diffstat (limited to 'src/extras')
-rwxr-xr-xsrc/extras/htmlog55
-rwxr-xr-xsrc/extras/rh-upload-core324
2 files changed, 366 insertions, 13 deletions
diff --git a/src/extras/htmlog b/src/extras/htmlog
index d4680eea..387a5d90 100755
--- a/src/extras/htmlog
+++ b/src/extras/htmlog
@@ -1,16 +1,17 @@
#!/usr/bin/env python
-from optparse import OptionParser, Option
-import time, sys, os
-
-__cmdParser__ = OptionParser()
-__cmdParser__.add_option("-i", "--input", action="append", \
- dest="logfiles", type="string", \
- help="system log to parse")
-__cmdParser__.add_option("-v", "--verbose", action="count", \
- dest="verbosity", \
- help="How obnoxious we're being about telling the user what we're doing.")
-(__cmdLineOpts__, __cmdLineArgs__)=__cmdParser__.parse_args()
+#from optparse import OptionParser, Option
+import time, sys, os, glob
+import getopt
+
+#__cmdParser__ = OptionParser()
+#__cmdParser__.add_option("-i", "--input", action="append",
+# dest="logfiles", type="string", metavar = "FILE",
+# help="system log to parse")
+#__cmdParser__.add_option("-v", "--verbose", action="count",
+# dest="verbosity",
+# help="How obnoxious we're being about telling the user what we're doing.")
+#(__cmdLineOpts__, __cmdLineArgs__)=__cmdParser__.parse_args()
class host_class:
@@ -96,7 +97,6 @@ class host_class:
self.fp().seek(0)
continue
else:
- sys.exit("HOST IS EOF")
return ""
if self.validate_line(toret) or toret == "":
@@ -139,6 +139,7 @@ class logfile_class:
def time_end(self):
pos = self.fp.tell()
bs = 1024
+ if self.size() < bs: bs = self.size()
self.fp.seek(-bs, 2)
line = self.fp.read(bs)
toret = time.strptime(line[line.rfind("\n", 0, bs - 1) + 1:][0:15], "%b %d %H:%M:%S")
@@ -201,15 +202,43 @@ class logfile_class:
print "could not parse time", self.curline
return False
+def usage():
+ print "ciao"
+
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "hi:v", ["help", "input="])
+except getopt.GetoptError:
+ # print help information and exit:
+ usage()
+ sys.exit(2)
+
+cmdline = {}
+cmdline["logfiles"] = []
+
+for o, a in opts:
+ if o == "-v":
+ verbose = True
+ if o in ("-h", "--help"):
+ usage()
+ sys.exit()
+ if o in ("-i", "--input"):
+ print o,a
+ for fname in sys.argv[2:]:
+ cmdline["logfiles"].append(fname)
+ sys.stderr.write("adding log %s\n" % fname)
+
hosts = {}
-for logname in __cmdLineOpts__.logfiles:
+for logname in cmdline["logfiles"]:
log = logfile_class(logname)
hostname = log.hostname()
+ sys.stderr.write("log %s for host %s\n" % (logname, hostname))
if not hosts.has_key(hostname):
hosts[hostname] = host_class()
hosts[hostname].add_log(log)
+sys.stderr.write("finished adding logs\n")
+
#print hosts["moka"].readline()
#print hosts["moka"].readline()
#print "DIRECT", hosts["moka"].fp().fp.tell()
diff --git a/src/extras/rh-upload-core b/src/extras/rh-upload-core
new file mode 100755
index 00000000..8240dd96
--- /dev/null
+++ b/src/extras/rh-upload-core
@@ -0,0 +1,324 @@
+#!/bin/bash
+
+#################################################################################
+# #
+# upload-core #
+# Version - 0.2 #
+# Copyright (c) 2007 Red Hat, Inc. All rights reserved. #
+# #
+# #
+# Written by David Mair #
+# Idea stolen from Chris Snook :-) #
+# #
+# Purpose - To help in the automation and encryption of kernel vmcore files. #
+# Specifically, this script will compress, encrypt, md5sum, #
+# and upload the core file automatically when invoked. #
+# Items are optional and specified by command line switch. #
+# ###############################################################################
+
+## Global directives
+umask 0077
+
+## Declare some variables
+date=`/bin/date -u +%G%m%d%k%M%S | /usr/bin/tr -d ' '`
+destination="dropbox.redhat.com"
+NOUPLOAD=NO
+SPLIT=0
+
+
+## Let's explain the usage
+
+function usage {
+ echo
+ echo
+ echo "Upload-core is a shell script for automating the handling of kernel vmcore files"
+ echo "for system administrators when working with support technicians."
+ echo "The script allows echo the user to compress, checksum, encrypt and upload a core"
+ echo "file with one command."
+ echo
+ echo "Usage: upload-core [-cehnNq] [-s size of hunks in MB] -f filename"
+ echo
+ echo "-c|--checksum : perform an md5 checksum on the file"
+ echo "-e|--encrypt : encrypt the core file"
+ echo "-f|--file : file to act on (required)"
+ echo "-h|--help : show this usage help"
+ echo "-n|--nocompress: do not compress the file (otherwise the file will be gzipped)"
+ echo "-N|--noupload : Do NOT upload to an ftp drop box"
+ echo "-q|--quiet : Do everything I ask and do it quietly"
+ echo "-s|--split : split file into small hunks"
+ echo
+ echo
+ exit 0
+}
+
+if [ $# == 0 ]; then usage
+fi
+
+TEMP=`getopt -o heucnqs:f:N --long help,encrypt,quiet,noupload,checksum,nocompress,split:,file: -n 'upload-core.sh' -- "$@"`
+
+if [ $? != 0 ]; then echo "Options error -- Terminating..." >&2; exit 1; fi
+
+eval set -- "$TEMP"
+
+while true ; do
+ case "$1" in
+ -h|--help) usage;;
+ -e|--encrypt) ENCRYPT=yes; shift;;
+ -N|--noupload) NOUPLOAD=yes; shift;;
+ -c|--checksum) CHECKSUM=yes; shift;;
+ -q|--quiet) QUIET=yes; shift;;
+ -n|--nocompress) NOCOMPRESS=yes; shift;;
+ -s|--split)
+ case $2 in
+ "") echo "You must specify a hunk size." >&2; exit 1 ;;
+ *) SPLIT=$2; shift 2;;
+ esac ;;
+ -F|--force) FORCE=yes; shift;;
+ -f|--file)
+ case "$2" in
+ "") echo "You must specify a file name." >&2; exit 1 ;;
+ *) FILE=$2; shift 2;;
+ esac ;;
+ --) shift; break ;;
+ *) echo "Wrong options or flag specified"; usage;;
+ esac
+done
+
+
+# Okay, let's do some work!
+
+# Ensure the -f||--file flag was passed or die
+
+if test -z $FILE; then echo; echo "The -f or --file flag is required! Terminating."; echo; exit 1; fi
+
+# Validate the file exists or die
+
+if [ ! -f $FILE ]; then echo "Invalid filename or file not found. Terminating."; exit 1; fi
+
+function repeat {
+
+if [ "$QUIET" = "yes" ]; then return
+else
+
+# Let's repeat back to the user what we're doing and make sure this is what they really wanted.
+echo
+if [ "$ENCRYPT" = "yes" ] ; then echo " ## Will encrypt the file.";echo; fi
+
+if [ "$NOUPLOAD" = "yes" ] ; then echo " ## Will NOT upload the file.";echo; fi
+
+if [ "$CHECKSUM" = "yes" ] ; then echo " ## Will checksum the file.";echo; fi
+
+if [ "$SPLIT" != "FALSE" ] ; then echo " ## Will split the file.";echo; fi
+
+if [ "$NOCOMPRESS" = "yes" ] ; then echo -e " ## Will \E[41;30m\033[5mNOT\033[0m compress the file. Are you sure?";echo; else echo "Compressing $FILE"; echo; fi
+fi
+}
+
+
+function warn {
+
+if [ "$QUIET" = "yes" ]; then return
+else
+echo "Please note that depending upon the size of your vmcore file this could take"
+echo "quite some time to run. If the options listed above are correct please"
+echo "press enter. Otherwise press <ctrl>-<c> to exit the program and start again."
+echo
+read IGNORE
+echo
+fi
+}
+
+function ticket {
+echo
+echo "We'll need to use your trouble ticket number for a couple of things. Please"
+echo "enter your trouble ticket number:"
+read ticket_number
+echo
+return
+}
+
+function file_ops {
+# Need to rename the core file before we compress it
+if [ "$QUIET" != "yes" ]; then echo "Renaming core file $ticket_number-$date-vmcore"; fi
+
+new_file=$ticket_number-$date-vmcore
+
+/bin/mv $FILE $new_file
+}
+
+# Compress the file
+function compress {
+
+if [ "$NOCOMPRESS" = "yes" ]
+ then
+ if [ "$QUIET" != "yes"]; then echo "Skipping compression step.";echo; fi
+
+ else
+ if [ "$QUIET" != "yes" ]; then echo "Starting file compression. This will take some time.";echo; fi
+ # Begin compression of file
+ if [ ! /usr/bin/gzip ]; then
+ echo "Cannot find gzip in /usr/bin/. Terminating."; exit 1
+ else
+ /usr/bin/gzip --fast $new_file
+ fi
+
+fi
+
+new_file="$new_file.gz"
+
+}
+
+# Encrypt the file
+function encrypt {
+
+if [ "$ENCRYPT" = "yes" ]
+ then
+ if [ "$QUIET" != "yes" ]; then echo "Beginning file encryption. This should only take a few minutes.";echo; fi
+ # Use the ticket number as the ssl keyfile name
+ if [ ! /usr/bin/openssl ]; then
+ echo "Cannot find openssl in /usr/bin. Terminating."; exit 1
+ fi
+ /usr/bin/openssl rand -out $ticket_number-$date.key -base64 48
+ if [ "$QUIET" != "yes" ]; then
+ echo "You have chosen to encrypt your core file. Your passkey file is"
+ echo "$ticket_number-$date.key. Please attach this key to your ticket."
+ echo
+ fi
+ /usr/bin/openssl aes-128-cbc -in $new_file -out $new_file.aes -pass file:$ticket_number-$date.key
+
+new_file="$new_file.aes"
+
+fi
+}
+
+function checksum {
+
+if [ "$CHECKSUM" = "yes" ]
+ then
+
+ if [ "$QUIET" != "yes" ]; then echo "Beginning $new_file checksum. This should only take a few minutes.";echo; fi
+ if [ ! /usr/bin/md5sum ]; then
+ echo "Cannot find md5sum in /usr/bin. Terminating."; exit 1
+ fi
+ md5result=`/usr/bin/md5sum $new_file|awk '{print $1}'`
+ echo $md5result > $ticket_number-$date-checksum.out
+
+fi
+
+}
+
+function split {
+
+if [ "$SPLIT" = "0" ]; then return; fi
+
+ hunk_size=$SPLIT
+ if (( $hunk_size > 0 )) && (( $hunk_size < 1001 ))
+ then
+ if [ ! /usr/bin/split ]; then
+ echo "Cannot find split in /usr/bin. Terminating."; exit 1
+ fi
+ # We need to make a directory to keep things sane
+ if [ "$QUIET" != "yes" ]; then echo "Creating directory $ticket_number-$date to house file hunks"; fi
+ /bin/mkdir $ticket_number-$date
+ /usr/bin/split -b "$hunk_size"m -d $new_file $ticket_number-$date/$new_file
+ else
+ echo "Invalid hunk size argument. Please enter a number greater than 0 and less than 1001."
+ echo "Terminating."; exit 1
+ fi
+
+
+}
+
+function upload {
+
+if [ "$NOUPLOAD" = "yes" ]; then
+ echo "All file operations are complete. The file(s) is ready to upload at your convenience."; return
+ else
+ echo "All file operation are complete. The file(s) is now ready to be uploaded."
+ echo "Please enter the destination host (default is dropbox.redhat.com)"
+ read destination_input
+ if [ "$destination_input" != "" ]; then destination=$destination_input; fi
+ if [ "$QUIET" != "yes" ]; then
+ echo
+ echo "Okay, uploading to $destination. Depending upon the file size and link throughput"
+ echo "this could take quite a while. When the upload completes this script will provide"
+ echo "additional information such as the md5sum, ssl key file, etc. and then exit."
+ echo "Unless you do not have lftp installed you should be able to monitor upload status."
+ echo "If lftp is not available then this script will exit and the core file(s) will need"
+ echo "to be uploaded to your target system manually. The information indicated above"
+ echo "will still be provided."
+ echo
+ else
+ if [ ! /usr/bin/lftp ]; then
+ # No lftp installed
+ echo "lftp could not be found in /usr/bin. The file(s) will need to be uploaded manually."
+
+ else
+ # Make the lftp script first
+ echo "lftp $destination <<EOF" > lftp_scripts
+ if [ "$SPLIT" = "yes" ]; then
+ echo "lcd $ticket_number" >> lftp_scripts
+ echo "mirror -R" >> lftp_scripts
+ else
+ echo "put $new_file" >> lftp_scripts
+ fi
+ echo "quit 0" >> lftp_scripts
+ echo "EOF" >> lftp_scripts
+ /usr/bin/lftp -f lftp_scripts
+ fi
+ fi
+fi
+}
+
+function closure {
+
+if [ "$ENCRYPT" = "yes" ] ; then
+ echo
+ echo " ## File was encrypted with $ticket_number-$date.key. Please upload the key"
+ echo "to Issue Tracker or send it to your support representative for decryption"
+ echo "after upload.";echo;
+fi
+
+
+if [ "$CHECKSUM" = "yes" ] ; then
+ echo
+ echo "## A checksum was performed on your core file (prior to splitting if you chose"
+ echo "to do so)."
+ echo
+ echo "The checksum results are in:"
+ echo "$ticket_number-$date-checksum.out."
+ echo
+ echo "Please include this when updating your trouble ticket so your support"
+ echo "representative can verify the copy uploaded.";echo
+fi
+
+if [ "$SPLIT" != 0 ]; then
+ echo
+ echo "## Your core file was split and the hunks are in $ticket_number."
+ echo
+fi
+
+echo "This script has completed successfully. If you performed file encryption and/or file"
+echo "splitting you may want to consider removing those files once your support representative"
+echo "confirms receipt. This will reduce the amount of space being utilised on your system."
+echo "It is NOT recommended to remove the gzipped copy of the core file."
+echo
+echo -en "\E[40;31m\033[3mThis would be the only remaining copy of the core file on your system.\033[0m"
+echo
+echo
+echo "It is recommended to retain the core file until your support representative indicates"
+echo "that the problem has been identified and/or resolved."
+
+}
+
+# Run through the functions
+repeat
+warn
+ticket
+file_ops
+compress
+encrypt
+checksum
+split
+upload
+closure