Skip to content

Commit

Permalink
First draft of the Splunk-TA-journald.
Browse files Browse the repository at this point in the history
A very simple solution to onboard journald logs into Splunk.
  • Loading branch information
jmaas committed Sep 22, 2020
1 parent db7899e commit 6e56c5b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2020, Jörgen
Copyright (c) 2020, Jörgen Maas
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
38 changes: 38 additions & 0 deletions bin/get-journald-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#
# Simple script to fetch journald logs while keeping state.
# 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}"

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

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

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

if [ -f ${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}
fi

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

# EOF

11 changes: 11 additions & 0 deletions default/inputs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
#
#

[script://./bin/get-journald-logs.sh]
interval = 30
sourcetype = linux:journald
disabled = False
index = linux

# EOF
9 changes: 9 additions & 0 deletions default/props.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[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
1 change: 1 addition & 0 deletions state/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory holds the state file.

0 comments on commit 6e56c5b

Please sign in to comment.