// SPDX-License-Identifier: MIT-0 // Copyright (c) 2026 EgosTech Innovations SRL // // PXM Log Exporter: parser function for Microsoft Sentinel, schema egos.tech/pxmlogexporter version 1. // // The module posts each event, unchanged, to the stream of a data collection rule (preset "Microsoft // Sentinel"). Create, in this order: // // 1. A custom table PxmLogExporter_CL with these columns: // TimeGenerated datetime, EventTime datetime, EventId string, Seq long, EventName string, Category string, // Severity string, Outcome string, Tenant string, Environment string, Host string, Source dynamic, // Actor dynamic, Target dynamic, Targets dynamic, TargetsOmitted int, Request dynamic, Data dynamic, // Truncated boolean, SchemaVersion string // // 2. A data collection rule whose stream Custom-PxmLogExporter declares the event fields: // schema string, id string, seq long, time datetime, tenant string, environment string, host string, // source dynamic, event string, category string, severity string, outcome string, actor dynamic, // target dynamic, targets dynamic, targets_omitted int, request dynamic, data dynamic, truncated boolean // and whose data flow sends the stream to Custom-PxmLogExporter_CL with this transformation: // // source // | project TimeGenerated = time, EventTime = time, EventId = id, Seq = seq, EventName = event, // Category = category, Severity = severity, Outcome = outcome, Tenant = tenant, // Environment = environment, Host = host, Source = source, Actor = actor, Target = target, // Targets = targets, // TargetsOmitted = coalesce(targets_omitted, 0), Request = request, Data = data, // Truncated = coalesce(truncated, false), SchemaVersion = schema // // 3. The role Monitoring Metrics Publisher for the app registration the module signs in with, on the data // collection rule (Access control (IAM) > Add role assignment). // // 4. This query, saved as the workspace function PxmLogExporter. Queries and analytics rules then read // PxmLogExporter instead of the table. // // In the module, the endpoint is the logs ingestion endpoint of the data collection rule (its JSON view), // or of the data collection endpoint where you use one. // // Delivery is at least once: an event can arrive twice; EventId is unique per event. Seq is the event's // place in the tenant's queue. A merged event names its records in Targets, with Target empty; TargetCount // counts them, including the ones left out of Targets to keep the event within 8,192 bytes. EventCount is // how many failed logins (auth.login.failure), refused web service calls (api.access_denied), rejected // inputs (security.input_rejected) or application errors (app.error) one event stands for, or how many // events an exporter.dropped reports. IngestionTime is when the workspace stored the event, minutes after // its TimeGenerated and later after an outage; the detection rules in the module's documentation, // https://egos.tech/modules/pxmlogexporter/detection-rules/, select by it. // Azure can store a late event with its arrival as TimeGenerated; EventTime keeps its time. PxmLogExporter_CL | extend IngestionTime = ingestion_time(), ActorType = tostring(Actor.type), ActorUserId = toint(Actor.user_id), ActorUserName = tostring(Actor.user_name), SrcIpAddr = tostring(Actor.ip), SrcIpNetwork = tostring(Actor.ip_network), SrcIpSource = tostring(Actor.ip_source), PeerIpAddr = tostring(Actor.ip_peer), ForwardedFor = tostring(Actor.ip_forwarded), HttpUserAgent = tostring(Actor.user_agent), TargetClass = tostring(Target.class), TargetId = tostring(Target.id), TargetLabel = tostring(Target.label), RequestId = tostring(Request.id), CfRay = tostring(Request.cf_ray), HttpRequestMethod = tostring(Request.method), UrlPath = tostring(Request.path), RequestMode = tostring(Request.mode), HttpStatusCode = toint(Request.status), LoginMechanism = tostring(Data.mechanism), FailureReason = tostring(Data.reason), PresentedUserName = tostring(Data.presented_user_name), EventCount = toint(Data.count), TargetCount = array_length(Targets) + TargetsOmitted, ModuleVersion = tostring(Source.version), PxmVersion = tostring(Source.pxm) | project TimeGenerated, EventTime, IngestionTime, EventName, Category, Severity, Outcome, Tenant, Environment, Host, ActorType, ActorUserId, ActorUserName, SrcIpAddr, SrcIpNetwork, SrcIpSource, PeerIpAddr, ForwardedFor, HttpUserAgent, TargetClass, TargetId, TargetLabel, Targets, TargetCount, RequestId, CfRay, HttpRequestMethod, UrlPath, RequestMode, HttpStatusCode, LoginMechanism, FailureReason, PresentedUserName, EventCount, Data, EventId, Seq, ModuleVersion, PxmVersion, Truncated, SchemaVersion