Iniciar sesión

Mapping your own data to ECS

15 min · 2 ejercicio(s)

Mapping a source to ECS means deciding, for every piece of information in it, which ECS field it belongs to. Write the mapping down before you parse:

sshd line ECS field
Mar 11 02:14:03 @timestamp
srv-web-01 host.name
sshd[2211] process.name, process.pid
Failed password event.category: authentication, event.outcome: failure
password system.auth.ssh.method (not in ECS, so a namespaced custom field)
for root user.name
from 185.220.101.47 port 51234 source.ip, source.port

Parse straight into ECS names

Grok and DISSECT accept dotted names, so the parser can write ECS fields directly:

FROM lab-raw
| WHERE event.dataset == "system.auth"
| GROK message """%{WORD:result} password for (?:invalid user )?%{USERNAME:user.name} from %{IP:source.ip} port %{INT:source.port:long}"""
| EVAL event.outcome = CASE(result == "Accepted", "success", result == "Failed", "failure", null)
| WHERE event.outcome IS NOT NULL
| STATS logons = COUNT(*) BY event.outcome, user.name

EVAL sets the categorization fields from what was parsed. An ingest pipeline does the same with a set processor or a short script.

Composite patterns already speak ECS

%{COMBINEDAPACHELOG} writes source.address, http.request.method, url.original, http.response.status_code, http.response.body.bytes and user_agent.original. Only source.address needs a final step: ECS says source.address is the raw value and source.ip the parsed IP, so pipelines copy it with convert/set.

Map once, benefit everywhere

After the mapping, the raw sshd log answers the same questions as lab-auth, with the same queries, rules and dashboards. That's the whole point.

🔎 Profundiza: funciones, errores habituales y práctica

Checklist for a new source

  1. Collect sample lines of every line type, including errors and rare messages.
  2. Map each value to an ECS field. Use the field reference, search for the concept, not the name.
  3. Set event.kind, event.category, event.type, event.outcome from the line type.
  4. Put values without an ECS home in a namespace (kestrel.*, system.auth.*).
  5. Keep the original line in message (or event.original).
  6. Set ecs.version, then test with the simulate API and real data.

related.*

ECS has a field set just for pivoting: related.ip, related.user, related.hosts, related.hash. A pipeline copies every IP of an event (source, destination, an IP inside a URL, …) into related.ip. Then one query, related.ip: 45.133.1.20, finds the address no matter in which role it appeared. The lab data doesn't fill related.*, but Elastic's integrations do.

Ejercicios prácticos de esta lección

Resuelve estos ejercicios con una consulta en el laboratorio Elasticsearch real. Inicia sesión gratis para acceder al laboratorio, las pistas y la corrección automática.

  1. 1. Parse straight into ECS

    Write a Grok pattern for the failed SSH logons that uses ECS field names directly: the account, the address and the port of the client.

    Mar 11 02:14:03 srv-web-01 sshd[2211]: Failed password for root from 185.220.101.47 port 51234 ssh2
    Mar  9 00:21:08 srv-web-01 sshd[27460]: Failed password for invalid user ubuntu from 112.22.254.249 port 58777 ssh2
  2. 2. Rename to ECS

    A colleague parsed the sshd lines with their own field names:

    Parsed field Example
    program sshd
    pid 2211
    user root
    ip 185.220.101.47
    port 51234

    Map all five to ECS, one line each: parsed_field -> ecs.field.