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.nameEVAL 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
- Collect sample lines of every line type, including errors and rare messages.
- Map each value to an ECS field. Use the field reference, search for the concept, not the name.
- Set
event.kind,event.category,event.type,event.outcomefrom the line type. - Put values without an ECS home in a namespace (
kestrel.*,system.auth.*). - Keep the original line in
message(orevent.original). - 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.