{
  "description": "Casa: containers da borda (Pocket ID) -> ECS",
  "created_date_millis": 1796443242637,
  "processors": [
    {
      "set": {
        "field": "event.dataset_casa",
        "value": "borda.container"
      }
    },
    {
      "grok": {
        "ignore_failure": true,
        "field": "message",
        "if": "ctx.message != null && ctx.message.contains('app=pocket-id')",
        "patterns": [
          "^%{SYSLOGTIMESTAMP:_tmp.ts} %{WORD:log.level} %{DATA:pocketid.msg} app=pocket-id %{GREEDYDATA:_tmp.kv}$"
        ]
      }
    },
    {
      "kv": {
        "ignore_failure": true,
        "field": "_tmp.kv",
        "target_field": "pocketid",
        "field_split": " (?=[a-z_]+=)",
        "strip_brackets": true,
        "trim_value": "\"",
        "ignore_missing": true,
        "value_split": "="
      }
    },
    {
      "script": {
        "source": "\n   def p=ctx.pocketid; ctx.observer=['name':'borda','product':'Pocket ID','type':'idp'];\n   ctx.event=ctx.event?:[:]; ctx.event.kind='event'; ctx.event.category=['authentication','web'];\n   if (p.ip!=null) ctx.source=['ip':p.ip];\n   if (p.path!=null) { p.path=/one-time-access-token\\/[^\\/?]+/.matcher(p.path).replaceAll('one-time-access-token/***'); ctx.url=['path':p.path]; }\n   if (p.method!=null) ctx.http=['request':['method':p.method]];\n   if (p.status!=null) { ctx.http=ctx.http?:[:]; ctx.http.response=['status_code':Integer.parseInt(p.status)]; }\n   if (p.user_agent!=null) ctx.user_agent=['original':p.user_agent];\n   if (p.error!=null) ctx.error=['message':p.error];\n   String a=null; String path=p.path==null?'':p.path; int st=p.status==null?0:Integer.parseInt(p.status);\n   if (p.msg!=null && p.msg.contains('Failed to authorize')) { a='oidc-acesso-negado'; ctx.event.outcome='failure'; }\n   else if (path=='/api/webauthn/register/finish') { a= st<400 ? 'passkey-registrada' : 'passkey-registro-falhou'; }\n   else if (path=='/api/webauthn/login/finish') { a= st<400 ? 'login-passkey-ok' : 'login-passkey-falhou'; ctx.event.outcome= st<400?'success':'failure'; }\n   else if (path.startsWith('/api/one-time-access') || path=='/lc' || path.startsWith('/api/one-time-access-email')) { a='login-code'; }\n   else if (path.startsWith('/api/oidc/interactions/') && path.endsWith('/complete')) { a='oidc-app-autorizado'; }\n   else if (path.startsWith('/api/oidc/clients/') && path.endsWith('/secrets')) { a='admin-secret-oidc-gerado'; }\n   else if (path=='/api/oidc/token') { a= st<400 ? 'oidc-token-emitido' : 'oidc-token-falhou'; }\n   else if (path.startsWith('/api/users') && p.method!=null && p.method!='GET') { a='admin-usuario-alterado'; }\n   else if (path.startsWith('/api/oidc/clients') && p.method!=null && p.method!='GET') { a='admin-cliente-oidc-alterado'; }\n   else if (path.startsWith('/api/user-groups') && p.method!=null && p.method!='GET') { a='admin-grupo-alterado'; }\n   if (a!=null) ctx.event.action=a; else ctx.event.action='http-request';",
        "lang": "painless",
        "if": "ctx.pocketid != null"
      }
    },
    {
      "user_agent": {
        "field": "user_agent.original",
        "ignore_missing": true
      }
    },
    {
      "gsub": {
        "pattern": "one-time-access-token/[^/?\\s\"]+",
        "ignore_missing": true,
        "field": "message",
        "replacement": "one-time-access-token/***"
      }
    },
    {
      "remove": {
        "field": [
          "_tmp",
          "pocketid.query"
        ],
        "ignore_missing": true
      }
    }
  ],
  "modified_date_millis": 1796443409391
}
