Capture sudo log on builders 65/61665/7
authorTim Johnson <tijohnson@linuxfoundation.org>
Mon, 9 Sep 2019 17:51:54 +0000 (10:51 -0700)
committerTim Johnson <tijohnson@linuxfoundation.org>
Wed, 25 Sep 2019 16:42:58 +0000 (09:42 -0700)
Created new script sudo-logs.sh to archive the sudo logs

Issue: RELENG-1994
Change-Id: I86a44e6abf18e35c7dc0e1840797e0dde5c764fb
Signed-off-by: Tim Johnson <tijohnson@linuxfoundation.org>
jjb/lf-macros.yaml
releasenotes/notes/archive-sudo-logs-a9af4aff811feec5.yaml [new file with mode: 0644]
shell/sudo-logs.sh [new file with mode: 0755]

index 6a2ea52..c06f0ce 100644 (file)
@@ -76,6 +76,8 @@
           # Ensure python-tools are installed in case job template does not
           # call the lf-infra-pre-build macro.
           - ../shell/python-tools-install.sh
+      - shell: !include-raw:
+          - ../shell/sudo-logs.sh
       - shell: !include-raw:
           - ../shell/logs-deploy.sh
       - shell: !include-raw:
diff --git a/releasenotes/notes/archive-sudo-logs-a9af4aff811feec5.yaml b/releasenotes/notes/archive-sudo-logs-a9af4aff811feec5.yaml
new file mode 100644 (file)
index 0000000..d0be097
--- /dev/null
@@ -0,0 +1,7 @@
+---
+features:
+  - |
+
+    Archive 'sudo' logs. The log will be located in the 'sudo' sub-directory of
+    the archive. The actual name of the log-file depends on the OS of the
+    builder.
diff --git a/shell/sudo-logs.sh b/shell/sudo-logs.sh
new file mode 100755 (executable)
index 0000000..d925434
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> sudo-logs.sh"
+
+set -eu -o pipefail -o noglob
+
+# Copy/Generate 'sudo' log and copy to archive directory
+function copy_log()
+{
+    case $os in
+        fedora|centos|redhat|ubuntu|debian)
+            if ! sudo cp $sudo_log /tmp; then
+                echo "Unable to archive 'sudo' logs ($sudo_log)"
+                return
+            fi
+            ;;
+        suse)
+            # Do I need 'sudo' to run 'journalctl'?
+            journalctl | grep sudo > $sudo_log
+            ;;
+        *)  echo "Unexpected 'operatingsystem': $os"
+            exit 1
+            ;;
+    esac
+    sudo_log=$(basename $sudo_log)
+    sudo chown jenkins:jenkins /tmp/$sudo_log
+    chmod 0644 /tmp/$sudo_log
+    mkdir -p $WORKSPACE/archives/sudo
+    mv /tmp/$sudo_log $WORKSPACE/archives/sudo/$sudo_log
+
+}    # End copy_log()
+
+echo "Archiving 'sudo' log.."
+os=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
+case $os in
+    fedora|centos|redhat) sudo_log=/var/log/secure   ;;
+    ubuntu|debian)        sudo_log=/var/log/auth.log ;;
+    suse)                 sudo_log=/tmp/sudo.log     ;;
+    *)  echo "Unexpected 'operatingsystem': $os"
+        exit 1
+        ;;
+esac
+
+copy_log