Skip to content

Commit

Permalink
Some changes to make it work directly from scripted input.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaas committed Sep 22, 2020
1 parent 6e56c5b commit ae8c354
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# splunk-ta-journald
# Splunk-TA-journald
42 changes: 20 additions & 22 deletions bin/get-journald-logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,33 @@
# Requires the 'jq' package to be installed.
#

#LOG_DATE=$(date +"%Y-%m-%d")
#LOG_NAME="journald-${LOG_DATE}.log"
#LOG_DIR="/var/log/splunk-journald"
#LOG_FILE="${LOG_DIR}/${LOG_NAME}"
CUR_DIR=$(dirname $0)
STATE_DIR="${CUR_DIR}/../state"
STATE_FILE="${STATE_DIR}/journald.state"
STATE_LOGFILE="${STATE_DIR}/journald.log"

STATE_NAME="journald.state"
STATE_DIR="state"
STATE_FILE="${STATE_DIR}/${STATE_NAME}"

#if ! [ -d ${LOG_DIR} ]; then
# mkdir -p ${LOG_DIR}
#fi
update_state () {
if [ -s ${STATE_LOGFILE} ]; then
# only update state if we have a new one
STATE=$(tail -n1 ${STATE_LOGFILE} | jq -j '.__CURSOR')
echo -n ${STATE} > ${STATE_FILE}
fi
}

#if ! [ -d ${STATE_DIR} ]; then
# mkdir -p ${STATE_DIR}
#fi

if [ -f ${STATE_FILE} ]; then
if [ -s ${STATE_FILE} ]; then
# get state and logs
CURSOR=$(cat ${STATE_FILE})
/usr/bin/journalctl --after-cursor="${CURSOR}" --no-tail --no-pager -o json # >> ${LOG_FILE}
else
# no state; get all logs as of today
/usr/bin/journalctl --no-tail --since today --no-pager -o json # >> ${LOG_FILE}
/usr/bin/journalctl --after-cursor="${CURSOR}" --no-tail --no-pager -o json | /usr/bin/tee ${STATE_LOGFILE}
update_state
fi

# update state
STATE=$(tail -n1 ${LOG_FILE} | jq -r '.__CURSOR')
echo ${STATE} > ${STATE_FILE}

# EOF
if ! [ -f ${STATE_FILE} ]; then
# no state (first run?); get logs of today
/usr/bin/journalctl --no-tail --since today --no-pager -o json | /usr/bin/tee ${STATE_LOGFILE}
update_state
fi

# EOF
2 changes: 1 addition & 1 deletion default/inputs.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
#
# Scripted input for on-boarding journald logs into Splunk
#

[script://./bin/get-journald-logs.sh]
Expand Down
7 changes: 6 additions & 1 deletion default/props.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#
# Setup linux:journald sourcetype as JSON input
#

[linux:journald]
KV_MODE = json
#MAX_TIMESTAMP_LOOKAHEAD = 10
NO_BINARY_CHECK = 1
SHOULD_LINEMERGE = false
TIME_FORMAT = %s
TIME_PREFIX = \"__REALTIME_TIMESTAMP\" : \"
pulldown_type = 1
TZ=UTC

# EOF
3 changes: 2 additions & 1 deletion state/README
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
This directory holds the state file.
This directory holds the journald state as well as the last log file.
If you ever need to reset this input just delete the journald.* files.

0 comments on commit ae8c354

Please sign in to comment.