Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 2 of 6 · Lab · 30 min · revision 2

Standing Up a Lab SIEM and Onboarding Sources

Run OpenSearch 2.19 in Docker as a lab SIEM, create an index template with explicit ip, date and keyword mappings, and onboard three sources (RFC 3164 SSH and sudo logs, nginx access logs and JSON sign-in logs) through ingest pipelines that map them to ECS. Test each parser with known lines, including a missing time zone and a malformed line that must land in a failure index.

Contentsand lesson path

What you will learn

  • Deploy a SIEM in a lab (for example Wazuh or Elastic Security), onboard at least three sources and normalise their fields to a common schema.

01. Goal and setup

You will build a small SIEM on your own machine and onboard three log sources from one made-up day, 12 November 2026. A script generates the logs with a fixed seed, so your results match this page. That day an internet address guesses SSH passwords on the web server web01, gets in as deploy, and copies a script into the web root; the later lessons investigate it.

The SIEM is OpenSearch, an open-source search engine. Onboarding a source needs an ingest pipeline that turns each raw line into named fields, an index template that gives those fields the right types, and tests that prove both work. Field names follow ECS, the Elastic Common Schema, so a search for source.ip works on every source.

You need: Docker, Python 3.10 or later, curl, jq 1.6 or later, about 3 GB of disk and 2 GB of free memory. Tested with the opensearchproject/opensearch:2.19.4 image, opensearch-py 3.2.0 and Python 3.12. The lab turns off the OpenSearch security plugin and listens on 127.0.0.1 only; a production cluster keeps the plugin on, with TLS, named users and roles.

Folder layout at the end of the lab
siem-lab/
├── make_logs.py          step 2: writes logs/ (five files)
├── template.json         step 4: index template with field types
├── pipelines/            step 5: one ingest pipeline per source
│   ├── linux-auth.json
│   ├── nginx-access.json
│   └── idp-signin.json
├── load.py               step 8: installs everything and bulk-loads logs
└── osdata/               OpenSearch data (step 3)

02. Step 1: Create the folder and a Python environment

Terminal
mkdir siem-lab && cd siem-lab
python3 -m venv .venv
.venv/bin/pip install -q opensearch-py==3.2.0
.venv/bin/python -c "import opensearchpy; print(opensearchpy.__versionstr__)"
Expected output
3.2.0

03. Step 2: Generate the lab logs

make_logs.py writes five files into logs/. This lesson onboards three of them. auth.log is the SSH and sudo log of web01 in the classic BSD syslog format of RFC 3164: its timestamp, such as Nov 12 10:07:12, is local time with no year and no time zone, and web01 runs on Berlin time (UTC+1 in November). access.log is the nginx access log in the default combined format, whose timestamps carry an offset. idp.jsonl is the sign-in log of the company's single sign-on server, one JSON object per line. The script also plants one damaged line at the end of auth.log, the kind a log shipper writes when it cuts a line at a buffer boundary.

Python · siem-lab/make_logs.py
"""Write five lab log files for Thursday 12 November 2026 (fixed seed)."""
import json
import random
from datetime import datetime, timedelta, timezone
from pathlib import Path

rng = random.Random(20261112)
UTC = timezone.utc
CET = timezone(timedelta(hours=1))  # web01 runs on Berlin time: UTC+1 in November
OUT = Path("logs")
ATTACKER, WEB_USERS = "203.0.113.45", ["jdoe", "asmith"]


def at(hms):
    h, m, s = (int(x) for x in hms.split(":"))
    return datetime(2026, 11, 12, h, m, s, tzinfo=UTC)


def rfc3164(t, prog, msg):  # local time, no year, no zone, day padded to 2
    lt = t.astimezone(CET)
    return t, f"{lt:%b} {lt.day:2d} {lt:%H:%M:%S} web01 {prog}: {msg}"


def nginx(t, ip, req, status, size, ua):
    stamp = t.astimezone(CET).strftime("%d/%b/%Y:%H:%M:%S %z")
    return t, f'{ip} - - [{stamp}] "{req} HTTP/1.1" {status} {size} "-" "{ua}"'


def rfc5424(t, msgid, ip, mac, host):  # UTC with a zone, year included
    sd = f'[lease@32473 ip="{ip}" mac="{mac}" host="{host}"]'
    return t, f"<30>1 {t:%Y-%m-%dT%H:%M:%SZ} dhcp01 dhcpd 811 {msgid} {sd}"


def jsonl(t, **fields):
    return t, json.dumps({"time": f"{t:%Y-%m-%dT%H:%M:%SZ}", **fields})


auth = [rfc3164(at("08:55:40"), "sshd[2101]",
                "Accepted publickey for jdoe from 10.20.1.5 port 53122 ssh2"),
        rfc3164(at("08:55:40"), "sshd[2101]", "pam_unix(sshd:session): "
                "session opened for user jdoe(uid=1000) by (uid=0)"),
        rfc3164(at("09:00:01"), "CRON[2150]", "pam_unix(cron:session): "
                "session opened for user root(uid=0) by (uid=0)")]
names = ["admin", "root", "test", "oracle", "ubuntu", "postgres", "git", "user"]
t, port = at("09:01:00"), 50412
for i in range(30):  # the brute force: 30 failures in about six minutes
    name = names[i % len(names)]
    who = name if name in ("root", "postgres") else f"invalid user {name}"
    auth.append(rfc3164(t, f"sshd[{2200 + i}]",
                        f"Failed password for {who} from {ATTACKER} port {port} ssh2"))
    t += timedelta(seconds=rng.randint(10, 13))
    port += rng.randint(3, 9)
auth += [rfc3164(at("09:07:12"), "sshd[2298]",
                 f"Accepted password for deploy from {ATTACKER} port 51102 ssh2"),
         rfc3164(at("09:07:12"), "sshd[2298]", "pam_unix(sshd:session): "
                 "session opened for user deploy(uid=1001) by (uid=0)"),
         rfc3164(at("09:09:40"), "sudo", "  deploy : TTY=pts/1 ; PWD=/home/deploy ; "
                 "USER=root ; COMMAND=/usr/bin/cp /tmp/invoice.js /var/www/html/js/"),
         rfc3164(at("09:30:05"), "sshd[2391]",
                 "Failed password for asmith from 10.20.1.5 port 49822 ssh2"),
         rfc3164(at("09:30:11"), "sshd[2391]",
                 "Accepted password for asmith from 10.20.1.5 port 49822 ssh2")]
# The log shipper lost the first byte of one line at a buffer boundary.
auth.append((at("09:42:17"), "ov 12 10:42:17 web01 sshd[2410]: Connection closed"))

pages = ["/", "/products", "/products/42", "/static/app.css", "/contact"]
uas = ["Mozilla/5.0 (X11; Linux x86_64)", "Mozilla/5.0 (Macintosh)", "curl/8.5.0"]
access = []
for i in range(40):  # ordinary internet visitors between 09:00 and 10:00
    ip = f"203.0.113.{rng.choice([n for n in range(10, 250) if n != 45])}"
    t = at("09:00:00") + timedelta(seconds=rng.randint(0, 3599))
    page = rng.choice(pages)
    access.append(nginx(t, ip, f"GET {page}", 200, rng.randint(900, 9000),
                        rng.choice(uas)))
for hms in ("09:05:00", "09:25:00", "09:45:00"):  # payment provider callbacks
    access.append(nginx(at(hms), "192.0.2.10", "POST /api/payments/webhook", 204, 0,
                        "PayHook/2.1"))
win = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
access += [nginx(at("09:10:05"), ATTACKER, "GET /js/invoice.js", 200, 1840,
                 "curl/8.5.0"),
           nginx(at("09:14:07"), "10.20.5.31", "GET /js/invoice.js", 200, 1840, win),
           nginx(at("09:19:30"), "10.20.5.44", "GET /js/invoice.js", 200, 1840, win)]

idp = [jsonl(at(hms), user=u, app=app, result=res, mfa=mfa, src_ip=ip, device=dev,
             **({"country": cc} if cc else {}))
       for hms, u, app, res, mfa, ip, dev, cc in [
    ("07:45:03", "CORP\\jdoe", "vpn", "success", "approved", "192.0.2.33", "LT-0412",
     "GB"),
    ("08:31:10", "[email protected]", "mail", "success", "approved", "10.20.5.31",
     "LT-0412", None),
    ("08:40:22", "[email protected]", "mail", "success", "approved", "10.20.5.52",
     "LT-0333", None),
    ("09:12:44", "[email protected]", "wiki", "failure", "none", "10.20.5.60",
     "LT-0391", None),
    ("09:12:58", "[email protected]", "wiki", "success", "approved", "10.20.5.60",
     "LT-0391", None),
    ("09:20:05", "[email protected]", "mail", "success", "approved", "192.0.2.80",
     "LT-0290", "GB"),
    ("09:38:00", "CORP\\bwong", "vpn", "success", "approved", "192.0.2.80", "LT-0290",
     "GB"),
    ("09:41:30", "[email protected]", "mail", "success", "approved",
     "198.51.100.20", "LT-0290", "SG"),
    ("09:50:12", "[email protected]", "mail", "success", "approved", "10.20.5.31",
     "LT-0377", None),
]]

leases = [("08:02:11", "DHCPACK", "10.20.5.31", "02:00:5e:10:04:12", "LT-0412"),
          ("08:05:40", "DHCPACK", "10.20.5.52", "02:00:5e:10:03:33", "LT-0333"),
          ("08:10:02", "DHCPACK", "10.20.5.44", "02:00:5e:10:04:18", "LT-0418"),
          ("08:30:00", "DHCPACK", "10.20.5.60", "02:00:5e:10:03:91", "LT-0391"),
          ("09:02:11", "DHCPACK", "10.20.5.31", "02:00:5e:10:04:12", "LT-0412"),
          ("09:31:05", "DHCPRELEASE", "10.20.5.31", "02:00:5e:10:04:12", "LT-0412"),
          ("09:47:30", "DHCPACK", "10.20.5.31", "02:00:5e:10:03:77", "LT-0377")]
dhcp = [rfc5424(at(h), m, ip, mac, host) for h, m, ip, mac, host in leases]

clients = ["10.20.5.31", "10.20.5.44", "10.20.5.52", "10.20.5.60"]
common = ["mail.corp.example", "wiki.corp.example", "www.example.com"]
dns = []
for i in range(40):  # ordinary lookups by office laptops
    t = at("09:00:00") + timedelta(seconds=rng.randint(0, 3599))
    dns.append(jsonl(t, client=rng.choice(clients), qname=rng.choice(common),
                     qtype="A", rcode="NOERROR", answers=["10.20.0.80"]))
for hms, ip, name, ans in [("09:14:05", "10.20.5.31", "www.shop.example", "10.20.1.10"),
                           ("09:15:02", "10.20.5.31", "cdn-update.example", ATTACKER),
                           ("09:20:11", "10.20.5.44", "cdn-update.example", ATTACKER)]:
    dns.append(jsonl(at(hms), client=ip, qname=name, qtype="A", rcode="NOERROR",
                     answers=[ans]))

OUT.mkdir(exist_ok=True)
for name, rows in [("auth.log", auth), ("access.log", access), ("idp.jsonl", idp),
                   ("dhcp.log", dhcp), ("dns.jsonl", dns)]:
    rows.sort(key=lambda r: r[0])  # stable sort keeps same-second lines in order
    (OUT / name).write_text("".join(line + "\n" for _, line in rows))
    print(f"{name:<11}{len(rows):>4} lines")
Terminal
.venv/bin/python make_logs.py
sha256sum logs/*
Expected output (the same hashes with Python 3.10 and 3.12)
auth.log     39 lines
access.log   46 lines
idp.jsonl     9 lines
dhcp.log      7 lines
dns.jsonl    43 lines
4abd521c5b7257f6936a267a7759d9f40ef38085465dbcd46d4cc5130edb6dd4  logs/access.log
cfd83de1ceef514289318169dfed7d99e48c425ae7c77884a01ca5d34446529b  logs/auth.log
8677e31ed820822f3feaf455816f2cfddb55b6605cfef1df5c3e43686757c468  logs/dhcp.log
7b21f6e4742b07303ac2f35db4345d7560278368d560b1a4c741b9f553308994  logs/dns.jsonl
4ff08555249ccbe26f346cba150c6b0eda9222572c818a2c23b70ae2bb4915e1  logs/idp.jsonl

04. Step 3: Start OpenSearch

This starts a single-node cluster with a 1 GB Java heap and keeps its data in osdata/. OS and OS_URL hold the address for curl and for the Python scripts. The until loop waits for the HTTP port, which can take a minute on the first start. Keep this terminal: the later steps use the variables.

Terminal
mkdir -p osdata && chmod 777 osdata   # the container runs as uid 1000
docker run -d --name siem-os -p 127.0.0.1:9200:9200 \
  -e discovery.type=single-node -e OPENSEARCH_JAVA_OPTS="-Xms1g -Xmx1g" \
  -e DISABLE_SECURITY_PLUGIN=true -e DISABLE_INSTALL_DEMO_CONFIG=true \
  -v "$PWD/osdata:/usr/share/opensearch/data" \
  opensearchproject/opensearch:2.19.4 > /dev/null
export OS=http://127.0.0.1:9200 OS_URL=http://127.0.0.1:9200
until curl -s "$OS" > /dev/null; do sleep 3; done
curl -s "$OS?filter_path=version.number"
curl -s "$OS/_cluster/health?wait_for_status=green&timeout=60s&filter_path=status"
echo
Expected output
{
  "version" : {
    "number" : "2.19.4"
  }
}
{"status":"green"}

05. Step 4: Create an index template with explicit types

An index template applies settings and mappings to every new index whose name matches a pattern, here logs-* and the failure index. A mapping gives each field a type. Left to itself, OpenSearch maps a new string as text or keyword, never as an address. Type ip allows network ranges such as 203.0.113.0/24 and correct sorting. Type date allows time ranges. Type keyword keeps the exact value for filters and counting. event.original keeps the raw line for evidence and re-parsing, but is not indexed, as ECS recommends. The dynamic template maps any other string to keyword. One shard and no replicas suit a single lab node.

JSON · siem-lab/template.json
{
  "index_patterns": ["logs-*", "failed-logs"],
  "template": {
    "settings": {"number_of_shards": 1, "number_of_replicas": 0},
    "mappings": {
      "dynamic_templates": [
        {"strings_as_keyword": {"match_mapping_type": "string",
          "mapping": {"type": "keyword", "ignore_above": 1024}}}
      ],
      "properties": {
        "@timestamp": {"type": "date"},
        "message": {"type": "text"},
        "event": {"properties": {
          "original": {"type": "keyword", "index": false, "doc_values": false},
          "created": {"type": "date"},
          "outcome": {"type": "keyword"},
          "category": {"type": "keyword"}}},
        "user": {"properties": {"name": {"type": "keyword"}}},
        "host": {"properties": {"hostname": {"type": "keyword"}}},
        "source": {"properties": {"ip": {"type": "ip"}, "port": {"type": "long"}}},
        "client": {"properties": {"ip": {"type": "ip"}}},
        "related": {"properties": {"ip": {"type": "ip"}}},
        "dns": {"properties": {"resolved_ip": {"type": "ip"}}},
        "process": {"properties": {"pid": {"type": "long"}}},
        "http": {"properties": {"response": {"properties": {
          "status_code": {"type": "long"},
          "body": {"properties": {"bytes": {"type": "long"}}}}}}}
      }
    }
  }
}
Terminal
curl -s -XPUT "$OS/_index_template/logs" -H 'Content-Type: application/json' \
  -d @template.json; echo
Expected output
{"acknowledged":true}

06. Step 5: Write one ingest pipeline per source

An ingest pipeline is a list of processors that OpenSearch runs on each document before it stores it. In linux-auth.json, rename moves the raw line to event.original. The first grok splits the syslog header with named patterns; pattern_definitions lets you build a long pattern from short named parts. Because RFC 3164 has no year, the script processor takes it from event.created, the time the collector read the file (section 5.1 of RFC 3164 mentions adding the year on the collector). The date processor then parses the time in the Berlin zone and writes @timestamp. The second grok reads SSH results and sudo commands, and ignore_failure lets other lines (cron, session notices) through without those fields. The set processors fill the ECS categorisation fields event.category, event.type, event.action and event.outcome, and append copies every address and user name into related.ip and related.user for pivoting. If any processor fails, on_failure sends the document to failed-logs with the error message instead of losing it.

JSON · siem-lab/pipelines/linux-auth.json
{
  "description": "auth.log lines from web01 (RFC 3164: sshd, sudo, cron) to ECS",
  "processors": [
    {"rename": {"field": "message", "target_field": "event.original"}},
    {"grok": {
      "field": "event.original",
      "patterns": ["^%{HEADER} %{PROC}: %{GREEDYDATA:message}$"],
      "pattern_definitions": {
        "HEADER": "%{SYSLOGTIMESTAMP:_tmp.ts} %{SYSLOGHOST:host.hostname}",
        "PROC": "%{PROG:process.name}(?:\\[%{POSINT:process.pid:int}\\])?"}}},
    {"script": {
      "source": "ctx._tmp.ts = ctx.event.created.substring(0, 4) + ' ' + ctx._tmp.ts"}},
    {"date": {
      "field": "_tmp.ts", "timezone": "Europe/Berlin",
      "formats": ["yyyy MMM d HH:mm:ss", "yyyy MMM  d HH:mm:ss"]}},
    {"set": {"field": "event.timezone", "value": "Europe/Berlin"}},
    {"grok": {
      "field": "message", "ignore_failure": true,
      "patterns": ["^%{SSHD}", "^\\s*%{SUDO}$"],
      "pattern_definitions": {
        "SSHD": "%{WORD:_tmp.result} %{WORD} for (?:invalid user )?%{WHO}",
        "WHO": "%{USERNAME:user.name} from %{IP:source.ip} port %{NUMBER:_tmp.port}",
        "SUDO": "%{USERNAME:user.name} : .*USER=%{USERNAME:user.target.name} ; %{CMD}",
        "CMD": "COMMAND=%{GREEDYDATA:process.command_line}"}}},
    {"convert": {"field": "_tmp.port", "target_field": "source.port",
                 "type": "integer", "ignore_missing": true}},
    {"set": {"if": "ctx._tmp.result != null",
             "field": "event.category", "value": ["authentication"]}},
    {"set": {"if": "ctx._tmp.result != null",
             "field": "event.action", "value": "ssh_login"}},
    {"set": {"if": "ctx._tmp.result == 'Accepted'",
             "field": "event.outcome", "value": "success"}},
    {"set": {"if": "ctx._tmp.result == 'Failed'",
             "field": "event.outcome", "value": "failure"}},
    {"set": {"if": "ctx.process.command_line != null",
             "field": "event.category", "value": ["process"]}},
    {"set": {"if": "ctx.process.command_line != null",
             "field": "event.action", "value": "sudo_command"}},
    {"set": {"if": "ctx.event.action != null",
             "field": "event.type", "value": ["start"]}},
    {"set": {"field": "event.kind", "value": "event"}},
    {"set": {"field": "event.dataset", "value": "linux.auth"}},
    {"append": {"if": "ctx.source?.ip != null",
                "field": "related.ip", "value": "{{{source.ip}}}"}},
    {"append": {"if": "ctx.user?.name != null",
                "field": "related.user", "value": "{{{user.name}}}"}},
    {"remove": {"field": "_tmp"}}
  ],
  "on_failure": [
    {"set": {"field": "_index", "value": "failed-logs"}},
    {"set": {"field": "event.kind", "value": "pipeline_error"}},
    {"set": {"field": "error.message", "value": "{{{_ingest.on_failure_message}}}"}},
    {"remove": {"field": "_tmp", "ignore_missing": true}}
  ]
}

The nginx line has fixed delimiters (spaces, brackets and quotes), so dissect is enough: it splits on literal text without regular expressions. Its timestamp carries an offset (+0100), so no time zone setting is needed.

JSON · siem-lab/pipelines/nginx-access.json
{
  "description": "nginx combined access log from web01 to ECS",
  "processors": [
    {"rename": {"field": "message", "target_field": "event.original"}},
    {"dissect": {"field": "event.original", "pattern":
      "%{source.ip} - %{_tmp.user} [%{_tmp.ts}] \"%{_tmp.req}\" %{_tmp.rest}"}},
    {"dissect": {"field": "_tmp.req", "pattern":
      "%{http.request.method} %{url.original} HTTP/%{http.version}"}},
    {"dissect": {"field": "_tmp.rest", "pattern":
      "%{_tmp.status} %{_tmp.bytes} \"%{_tmp.referrer}\" \"%{user_agent.original}\""}},
    {"date": {"field": "_tmp.ts", "formats": ["dd/MMM/yyyy:HH:mm:ss Z"]}},
    {"convert": {"field": "_tmp.status", "target_field": "http.response.status_code",
                 "type": "integer"}},
    {"convert": {"field": "_tmp.bytes", "target_field": "http.response.body.bytes",
                 "type": "integer"}},
    {"set": {"if": "ctx._tmp.user != '-'", "field": "user.name",
             "value": "{{{_tmp.user}}}"}},
    {"set": {"if": "ctx._tmp.referrer != '-'", "field": "http.request.referrer",
             "value": "{{{_tmp.referrer}}}"}},
    {"set": {"field": "event.outcome", "value": "success"}},
    {"set": {"if": "ctx.http.response.status_code >= 400",
             "field": "event.outcome", "value": "failure"}},
    {"set": {"field": "event.kind", "value": "event"}},
    {"set": {"field": "event.category", "value": ["web"]}},
    {"set": {"field": "event.type", "value": ["access"]}},
    {"set": {"field": "event.dataset", "value": "nginx.access"}},
    {"set": {"field": "host.hostname", "value": "web01"}},
    {"append": {"field": "related.ip", "value": "{{{source.ip}}}"}},
    {"remove": {"field": "_tmp"}}
  ],
  "on_failure": [
    {"set": {"field": "_index", "value": "failed-logs"}},
    {"set": {"field": "event.kind", "value": "pipeline_error"}},
    {"set": {"field": "error.message", "value": "{{{_ingest.on_failure_message}}}"}},
    {"remove": {"field": "_tmp", "ignore_missing": true}}
  ]
}

The sign-in log is JSON already, so the json processor parses it and rename moves each value to its ECS name. This first version copies the user name exactly as the server logged it; lesson 3 shows why that breaks joins between sources and fixes it.

JSON · siem-lab/pipelines/idp-signin.json (first version)
{
  "description": "SSO server sign-in log (JSON lines) to ECS, first version",
  "processors": [
    {"rename": {"field": "message", "target_field": "event.original"}},
    {"json": {"field": "event.original", "target_field": "_tmp"}},
    {"date": {"field": "_tmp.time", "formats": ["ISO8601"]}},
    {"rename": {"field": "_tmp.user", "target_field": "user.name"}},
    {"rename": {"field": "_tmp.src_ip", "target_field": "source.ip"}},
    {"rename": {"field": "_tmp.country", "target_field": "source.geo.country_iso_code",
                "ignore_missing": true}},
    {"rename": {"field": "_tmp.result", "target_field": "event.outcome"}},
    {"rename": {"field": "_tmp.app", "target_field": "idp.app"}},
    {"rename": {"field": "_tmp.mfa", "target_field": "idp.mfa"}},
    {"append": {"field": "related.hosts", "value": "{{{_tmp.device}}}"}},
    {"append": {"field": "related.ip", "value": "{{{source.ip}}}"}},
    {"append": {"field": "related.user", "value": "{{{user.name}}}"}},
    {"set": {"field": "event.kind", "value": "event"}},
    {"set": {"field": "event.category", "value": ["authentication"]}},
    {"set": {"field": "event.type", "value": ["start"]}},
    {"set": {"field": "event.action", "value": "sso_sign_in"}},
    {"set": {"field": "event.dataset", "value": "idp.signin"}},
    {"remove": {"field": "_tmp"}}
  ],
  "on_failure": [
    {"set": {"field": "_index", "value": "failed-logs"}},
    {"set": {"field": "event.kind", "value": "pipeline_error"}},
    {"set": {"field": "error.message", "value": "{{{_ingest.on_failure_message}}}"}},
    {"remove": {"field": "_tmp", "ignore_missing": true}}
  ]
}
Terminal
for p in linux-auth nginx-access idp-signin; do
  curl -s -XPUT "$OS/_ingest/pipeline/$p" -H 'Content-Type: application/json' \
    -d @pipelines/$p.json; echo " $p"
done
Expected output
{"acknowledged":true} linux-auth
{"acknowledged":true} nginx-access
{"acknowledged":true} idp-signin

07. Step 6: Test the parser on a known line

Before loading any data, run a line whose correct result you know through the pipeline with the _simulate API. Nothing is stored. Here the line is the attacker's successful SSH login, taken from auth.log.

Terminal
jq -n --arg m "$(grep -m1 'password for deploy' logs/auth.log)" \
  '{docs: [{_source: {message: $m, event: {created: "2026-11-12T12:00:00Z"}}}]}' \
  > sample.json
curl -s "$OS/_ingest/pipeline/linux-auth/_simulate" \
  -H 'Content-Type: application/json' -d @sample.json \
  | jq '.docs[0].doc._source | {"@timestamp", host: .host.hostname,
        user: .user.name, ip: .source.ip, outcome: .event.outcome,
        category: .event.category[0]}'
Expected output
{
  "@timestamp": "2026-11-12T10:07:12.000+01:00",
  "host": "web01",
  "user": "deploy",
  "ip": "203.0.113.45",
  "outcome": "success",
  "category": "authentication"
}

The line said 10:07:12 with no zone. The pipeline read it as Berlin time and stored 10:07:12.000+01:00, which is 09:07:12 UTC. The user, address, outcome and category are in their ECS fields.

08. Step 7: Negative tests: a missing time zone and a damaged line

Good parser tests include inputs that must not produce a normal event. The first command removes the timezone setting from a copy of the pipeline and simulates the same line. The second sends the damaged last line of auth.log through the real pipeline.

Terminal
jq 'del(.processors[].date.timezone?)' pipelines/linux-auth.json > no-tz.json
jq -n --slurpfile p no-tz.json --slurpfile d sample.json \
  '{pipeline: $p[0], docs: $d[0].docs}' \
  | curl -s "$OS/_ingest/pipeline/_simulate" -H 'Content-Type: application/json' -d @- \
  | jq -c '.docs[0].doc._source | {"@timestamp"}'
jq -n --arg m "$(tail -n 1 logs/auth.log)" \
  '{docs: [{_source: {message: $m, event: {created: "2026-11-12T12:00:00Z"}}}]}' \
  | curl -s "$OS/_ingest/pipeline/linux-auth/_simulate" \
      -H 'Content-Type: application/json' -d @- \
  | jq '.docs[0].doc | {_index, kind: ._source.event.kind,
        error: ._source.error.message[0:52]}'
Expected output
{"@timestamp":"2026-11-12T10:07:12.000Z"}
{
  "_index": "failed-logs",
  "kind": "pipeline_error",
  "error": "Provided Grok expressions do not match field value: "
}

Without a zone the date processor assumes UTC, so the login appears at 10:07:12 UTC, one hour late. In the lab data the attacker fetches the copied script at 09:10:05 UTC, so this mistake would put the login after the download it made possible. A whole-hour shift on one source is the usual sign of this problem; switching that source to RFC 5424 syslog, whose timestamps include the year and an offset, removes the guess. The damaged line went to failed-logs with the grok error, so it can be counted and fixed instead of silently disappearing.

09. Step 8: Load the three sources

load.py acts as a simple collector. It installs the template and every pipeline in pipelines/, deletes the lab indices so you can rerun it, and bulk-loads each file through its pipeline into its own index. It skips a source whose pipeline does not exist yet, so the same script loads all five sources after lesson 3. COLLECTED is fixed so that your results match this page; a real collector uses its own clock.

Python · siem-lab/load.py
"""Install the template and pipelines, then (re)load every lab source."""
import json
import os
from pathlib import Path

from opensearchpy import OpenSearch, helpers

SOURCES = [  # file, ingest pipeline, index
    ("logs/auth.log", "linux-auth", "logs-auth"),
    ("logs/access.log", "nginx-access", "logs-nginx"),
    ("logs/idp.jsonl", "idp-signin", "logs-idp"),
    ("logs/dhcp.log", "dhcp-lease", "logs-dhcp"),
    ("logs/dns.jsonl", "dns-query", "logs-dns"),
]
COLLECTED = "2026-11-12T12:00:00Z"  # when the collector read the files (fixed)

client = OpenSearch(os.environ.get("OS_URL", "http://127.0.0.1:9200"), timeout=60)
template = json.loads(Path("template.json").read_text())
client.indices.put_index_template(name="logs", body=template)
installed = []
for path in sorted(Path("pipelines").glob("*.json")):
    client.ingest.put_pipeline(id=path.stem, body=json.loads(path.read_text()))
    installed.append(path.stem)
print("pipelines:", ", ".join(installed))

names = ",".join([index for _, _, index in SOURCES] + ["failed-logs"])
client.indices.delete(index=names, ignore_unavailable=True)
for file, pipeline, index in SOURCES:
    if pipeline not in installed:
        continue  # this source is onboarded in a later lesson
    lines = Path(file).read_text().splitlines()
    docs = ({"_index": index, "message": line, "event": {"created": COLLECTED},
             "log": {"file": {"path": file}}} for line in lines)
    sent, errors = helpers.bulk(client, docs, pipeline=pipeline, raise_on_error=False)
    print(f"{file:<16} -> {pipeline:<13} sent {sent:>3}, rejected {len(errors)}")
client.indices.refresh(index="logs-*,failed-logs", ignore_unavailable=True)
Terminal
.venv/bin/python load.py
curl -s "$OS/_cat/indices/logs-*,failed-logs?h=index,docs.count&s=index"
Expected output
pipelines: idp-signin, linux-auth, nginx-access
logs/auth.log    -> linux-auth    sent  39, rejected 0
logs/access.log  -> nginx-access  sent  46, rejected 0
logs/idp.jsonl   -> idp-signin    sent   9, rejected 0
failed-logs  1
logs-auth   38
logs-idp     9
logs-nginx  46

All 39 lines of auth.log were accepted: 38 became events and one went to failed-logs.

10. Step 9: Prove the mapping works

Check the field types the template produced, then use one of them: a term query with a CIDR range only works on a field of type ip.

Terminal
curl -s "$OS/logs-auth/_mapping/field/@timestamp,source.ip,user.name,event.original" \
  | jq -r '[.["logs-auth"].mappings[]] | sort_by(.full_name)[]
    | .full_name + "  " + (.mapping[] | .type + if .index == false
                              then " (not indexed)" else "" end)'
curl -s "$OS/logs-*/_count?filter_path=count" -H 'Content-Type: application/json' -d '
{"query": {"bool": {"filter": [{"term": {"source.ip": "203.0.113.0/24"}},
                               {"term": {"event.outcome": "failure"}}]}}}'; echo
Expected output
@timestamp  date
event.original  keyword (not indexed)
source.ip  ip
user.name  keyword
{"count":30}

All 30 failed logins came from the 203.0.113.0/24 range. With source.ip mapped as text or keyword, the same query would silently match nothing.

11. Step 10: Check the failure index and search across sources

Read what landed in failed-logs, then ask one question across every source: which datasets mention the attacker's address?

Terminal
curl -s "$OS/failed-logs/_search?filter_path=hits.hits._source" \
  | jq -c '.hits.hits[]._source | {file: .log.file.path, raw: .event.original}'
curl -s "$OS/logs-*/_search?filter_path=aggregations.ds.buckets" \
  -H 'Content-Type: application/json' -d '
{"size": 0, "query": {"term": {"related.ip": "203.0.113.45"}},
 "aggs": {"ds": {"terms": {"field": "event.dataset"}}}}' \
  | jq -c '.aggregations.ds.buckets[] | [.key, .doc_count]'
Expected output
{"file":"logs/auth.log","raw":"ov 12 10:42:17 web01 sshd[2410]: Connection closed"}
["linux.auth",31]
["nginx.access",1]

One search covers two sources because both pipelines wrote the address to the same field. The SSH log gives 30 failures and one success; nginx shows one request. Keep the container running for the next two lessons, or stop it with docker stop siem-os; the data in osdata/ survives a restart.

12. The same steps in Wazuh and Elastic Security

Onboarding has the same parts in other products. In Wazuh, agents read log files and the server applies decoders (XML with regular expressions that extract fields such as srcip and user), then rules that raise alerts; you write your own decoders for formats it does not know. In Elastic Security, Elastic Agent integrations install ingest pipelines much like yours, with ECS names. Whatever you use, test each new source with known lines, as in steps 6 and 7.

13. Troubleshooting

14. Check your understanding

Practice check · 3 questions

The lab SIEM you built

Three questions about the template, the pipelines and the tests.

Q1. You delete the `on_failure` block from `linux-auth.json` and rerun step 8. What does `load.py` print for `logs/auth.log`, and why?
Q2. Why does the `term` query on `source.ip` with `203.0.113.0/24` in step 9 count 30 events?
Q3. You are about to onboard a new source. Which check from this lab gives the best evidence that its fields are parsed correctly?
Practice only: not graded, not saved, not evidence.

15. Apply it

Take the lab towards the skill project:

  • Write a pipeline for a fourth source of your choice, for example /var/log/nginx/error.log or a firewall log in key=value format (the kv processor helps). Simulate three known lines and one line that must fail.
  • Change make_logs.py so that web01 uses Europe/London, regenerate, and predict which @timestamp values change before you reload. Then check.
  • Add a check to load.py that prints a warning when a source sends more than 1 % of its lines to failed-logs.

16. Review prompt

Without looking back:

  1. Which three parts does onboarding a source need, and what does each prove?
  2. Why must the linux-auth pipeline set a time zone and a year, when the nginx pipeline needs neither?
  3. What happens to a line that a pipeline cannot parse, with and without on_failure?
  4. Why does source.ip need the type ip and not keyword?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check