Custom Parser Development

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 10 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Custom Parser Development in Microsoft Sentinel

Introduction: Why Data Normalization Matters

In the world of security operations, you are rarely dealing with a single, uniform data source. Your environment likely consists of firewalls, identity providers, endpoint detection systems, cloud workloads, and physical security sensors, all of which speak different "languages." When you query your security information and event management (SIEM) system, you are often faced with a chaotic mix of field names, data types, and formatting conventions. If one firewall logs a source IP as src_ip and another labels it sourceAddress, building a detection rule that covers both becomes a tedious, error-prone exercise.

Data normalization is the process of transforming these disparate data formats into a common schema. In Microsoft Sentinel, this is primarily achieved through the Advanced SIEM Information Model (ASIM). However, not every data source is natively supported by ASIM, and even when they are, you may need to extract specific information from raw logs that the ingestion process missed. This is where custom parser development comes in.

Custom parsers are the bridge between your raw, ingested data and the analytical power of Sentinel. By developing effective parsers, you ensure that your security analysts spend less time manipulating data and more time investigating threats. This lesson will guide you through the theory, implementation, and maintenance of custom parsers, providing you with the skills to transform raw telemetry into actionable intelligence.


Not read yet

Understanding the ASIM Foundation

Before diving into writing Kusto Query Language (KQL) for parsers, it is essential to understand the framework that governs data normalization in Sentinel: the Advanced SIEM Information Model (ASIM). ASIM provides a set of standardized field names and schemas for common data types like authentication, network sessions, file events, and DNS queries.

When you create a custom parser, your primary goal is to map your proprietary or custom log data to these ASIM schemas. If your log source describes a VPN login, you should aim to map it to the Authentication schema. By doing so, any detection rule written against the Authentication schema will automatically work with your new parser without requiring any modifications.

Callout: Parser vs. Schema It is important to distinguish between a schema and a parser. A schema is the definition—a blueprint of what fields should exist and what they represent. A parser is the implementation—the actual KQL code that reads the raw data, applies the transformations, and outputs the result in the format of that schema. You build a parser to satisfy a schema.

The Anatomy of a Parser

A well-constructed parser typically follows a standard sequence of operations within KQL:

  1. Filtering: Selecting the specific table and records that contain the data of interest.
  2. Parsing/Extraction: Using operators like parse, parse_json, or extract to pull specific values out of unstructured or semi-structured text.
  3. Renaming/Aliasing: Mapping the extracted fields to the standard ASIM field names (e.g., changing src_ip to SrcIpAddress).
  4. Type Casting: Ensuring that fields are of the correct data type (e.g., converting a string to a datetime or integer).
  5. Enrichment/Defaulting: Adding constant values or calculating fields that may be missing from the raw log but are required by the schema.

Not read yet

Step-by-Step: Developing a Custom Parser

Let's walk through the creation of a parser for a hypothetical custom application log. Imagine you have a proprietary web server that logs access events in a custom format stored in a table called AppAccessLogs_CL.

Step 1: Analyze the Raw Data

First, look at the raw data. Suppose a sample row looks like this: 2023-10-27 10:00:00 | 192.168.1.5 | 443 | user_admin | success

The fields are delimited by a pipe character. We need to extract the timestamp, source IP, port, username, and the result of the action.

Step 2: Write the Extraction Logic

We will use the split and extend functions or the parse operator to break this string apart.

AppAccessLogs_CL
| extend parts = split(RawData, " | ")
| extend TimeGenerated = todatetime(parts[0]),
         SrcIpAddress = tostring(parts[1]),
         SrcPortNumber = toint(parts[2]),
         User = tostring(parts[3]),
         Result = tostring(parts[4])

Step 3: Map to ASIM

Now, we align these fields with the ASIM Authentication schema. The ASIM schema requires fields like EventResult, TargetUsername, and SrcIpAddress.

let parser = (T:(RawData:string)) {
    T
    | extend parts = split(RawData, " | ")
    | extend TimeGenerated = todatetime(parts[0]),
             SrcIpAddress = tostring(parts[1]),
             TargetUsername = tostring(parts[3]),
             EventResult = tostring(parts[4])
    | extend EventType = "Authentication",
             EventVendor = "CustomApp",
             EventProduct = "WebServer"
    | project-away parts
};
parser(AppAccessLogs_CL)

Step 4: Save as a Function

To use this throughout Sentinel, you must save it as a workspace function. Navigate to Logs, paste your query, and click Save > Save as function. Give it a meaningful alias, such as ASimAuthenticationCustomApp.

Tip: Function Aliasing Always use a consistent naming convention for your functions. A common practice is to use the prefix ASim followed by the schema name and the source name. This makes it easy for other team members to identify what the function does just by looking at its name.


Not read yet

Advanced Parsing Techniques

Sometimes, logs are not neatly delimited. You might encounter logs in JSON format, XML, or even unstructured free-text blobs. Sentinel provides powerful tools to handle these scenarios.

Handling JSON Logs

If your logs are already stored as JSON in a dynamic column, parsing is significantly easier. You can use the bag_unpack operator or dot notation to access fields directly.

JSONLogs_CL
| extend Parsed = parse_json(RawData)
| extend SrcIpAddress = tostring(Parsed.source_ip),
         TargetUsername = tostring(Parsed.user_name)

Using Regular Expressions (Regex)

When dealing with complex, unstructured text, extract with regex is your best friend. Suppose your log message is: User 'admin' logged in from 10.0.0.5 at 2023-10-27.

UnstructuredLogs_CL
| extend User = extract("User '([^']+)'", 1, RawData),
         SrcIpAddress = extract("from ([0-9.]+)", 1, RawData)

Warning: Regex Performance While regex is powerful, it is computationally expensive. If you are parsing millions of rows, complex regex patterns can significantly slow down your queries. Always try to use simpler operators like split, parse, or parse_json before resorting to regex.


Not read yet

Best Practices for Parser Development

Creating a parser is only half the battle; maintaining it over time is where the real work lies. Follow these industry-standard practices to ensure your parsers remain reliable.

1. Maintain Schema Compliance

Always check the official Microsoft documentation for the ASIM schema you are targeting. Ensure that all mandatory fields are present and that your data types match. If a field is required to be an integer, do not pass it as a string, as this will break downstream analytics that perform mathematical comparisons.

2. Implement Error Handling

What happens if the log format changes? If your parser expects a pipe delimiter and the application update introduces a comma, your parser will return empty values or errors. Use iff or case statements to validate that the expected data structure exists before attempting to parse it.

3. Use Project-Away

Keep your workspace clean by removing the raw, unparsed data after you have extracted the necessary fields. Use the project-away operator to drop the original RawData column if it is no longer needed. This reduces the memory footprint of your queries.

4. Optimize for Performance

KQL is designed for speed, but poorly written queries can still lead to "query too complex" errors.

  • Filter Early: Always filter by TimeGenerated and other indexed columns before performing heavy string manipulation.
  • Avoid extend on massive datasets: If you are querying a massive table, limit the scope of the data first.
  • Reuse Functions: Once a parser is created, use it as a building block for other, more complex queries rather than rewriting the parsing logic.

5. Version Control

Treat your KQL code like application code. Store your parser definitions in a Git repository. This allows you to track changes, roll back if a parser breaks, and collaborate with other security engineers. Use the Sentinel GitHub repository as a template for your own internal documentation and storage.


Not read yet

Comparison: Parsing Strategies

Method Best Used For Pros Cons
split Simple, fixed-delimiter logs Extremely fast, readable Fails if delimiter appears in data
parse Semi-structured logs Very fast, intuitive syntax Requires strict format consistency
parse_json JSON-formatted logs Native support, handles nested data High memory usage on large objects
extract Complex, unstructured text Highly flexible, precise Computationally expensive

Common Pitfalls and How to Avoid Them

Pitfall 1: The "Fragile Parser" Syndrome

A common mistake is assuming that log formats are static. When a software update changes the log format, your parser might silently fail, leading to gaps in your security visibility.

  • Avoidance: Always include a "fallback" or "default" case in your logic. If the parsing fails, assign a value like "Unknown" or "ParsingError" to your fields so that you can create a detection rule to alert you when your parser is broken.

Pitfall 2: Neglecting Data Types

KQL is sensitive to data types. If you map an IP address to a string instead of a dynamic or string that follows IP formatting, you may be unable to use IP-specific functions like ipv4_is_in_range().

  • Avoidance: Explicitly cast your variables using tostring(), toint(), or todatetime() as soon as you extract them.

Pitfall 3: Over-complicating Logic

Some engineers try to do everything in one massive, nested query. This makes the code unreadable and impossible to debug.

  • Avoidance: Break your logic into multiple, smaller functions. You can chain these functions together in your final query. This modular approach is much easier to maintain.

Pitfall 4: Ignoring Timezone Offsets

Logs often come in UTC, but your local environment might be in a different timezone. This can lead to significant discrepancies in detection rules that rely on time-based correlation.

  • Avoidance: Always normalize your timestamps to UTC at the very beginning of your parser. Use the datetime_add or datetime_diff functions if you need to adjust timestamps during the parsing phase.

Not read yet

Testing Your Parser

Before pushing a parser to production, you must validate it against a representative dataset. Create a test environment or use a dedicated "sandbox" workspace where you can run your parser against real-world logs without affecting active detection rules.

Validation Checklist

  • Sample Testing: Run the parser on a small subset of data and manually verify that every field is correctly mapped.
  • Edge Case Testing: Identify logs with missing fields, null values, or unusual characters. Does your parser handle these gracefully?
  • Performance Testing: Run the query over a large time range (e.g., 30 days) to ensure it executes within a reasonable timeframe.
  • Schema Validation: Use the getschema operator on your parser output to verify that the field names and data types match the target ASIM schema.

Example of schema validation:

ASimAuthenticationCustomApp
| getschema

Compare the output of this command against the official ASIM schema definition for Authentication. If you are missing mandatory fields or have mismatched types, adjust your extend or project statements accordingly.


Not read yet

Integrating Parsers into Sentinel Detection Rules

Once your parser is deployed and tested, the final step is to integrate it into your detection strategy. Because your parser adheres to the ASIM schema, you can now write detection rules that are "schema-aware."

For instance, if you have a rule that detects brute-force attempts, you can write it once for the Authentication schema:

// Brute Force Detection Rule
ASimAuthentication
| where EventResult == "Failure"
| summarize Count = count() by SrcIpAddress, TargetUsername, bin(TimeGenerated, 5m)
| where Count > 10

Because your custom parser is registered as part of the ASimAuthentication union, this rule will automatically include data from your custom application, alongside your firewalls, Active Directory logs, and any other authentication-related data source. This is the true power of normalization: you write the logic once, and it applies to everything.


Not read yet

Maintaining Parser Health

Security environments evolve. Applications are patched, network topologies change, and log formats are updated. Your parsers are not "set and forget" entities.

Establishing a Review Cycle

Set a quarterly review cycle for your custom parsers. During this review:

  1. Verify that the log source is still active and sending data.
  2. Check for any changes in the log format that might have occurred due to application updates.
  3. Review the performance metrics of the KQL queries to see if they can be optimized.
  4. Remove any parsers that are no longer needed, as unused functions clutter the workspace and can confuse other analysts.

Monitoring Parser Errors

You can create a "health check" rule to monitor the effectiveness of your parsers. For example, if you notice a sudden spike in "Unknown" values in a field that is supposed to be populated, it is a strong signal that your parser needs an update.

// Parser Health Monitoring
ASimAuthentication
| where EventVendor == "CustomApp"
| extend IsBroken = iff(isempty(TargetUsername) or TargetUsername == "N/A", 1, 0)
| summarize BrokenCount = sum(IsBroken) by bin(TimeGenerated, 1h)
| where BrokenCount > 0

This simple rule can alert your team to format changes before they impact your actual security detections.


Not read yet

Summary and Key Takeaways

Custom parser development is a fundamental skill for any Microsoft Sentinel professional. By normalizing your data, you move away from siloed investigations and toward a unified, schema-driven security operation.

Key Takeaways

  1. Normalization is Essential: Normalizing data into the ASIM schema allows you to write reusable, efficient detection rules that work across all your data sources, regardless of their origin.
  2. Follow the Schema: Always consult the official ASIM documentation. Your parser is only as good as its adherence to the defined schema standards.
  3. Modular Logic: Keep your KQL clean by using modular functions. Avoid massive, complex queries that are difficult to debug and maintain.
  4. Prioritize Performance: Use efficient operators like split, parse, and parse_json. Reserve complex regex for scenarios where no other option exists, and always filter your data early in the query.
  5. Proactive Maintenance: Treat your parsers as code. Use version control, perform regular health checks, and monitor your parsers for failures caused by upstream log format changes.
  6. Schema-Aware Detections: Once normalized, shift your focus from writing rules for specific log sources to writing rules for specific schemas, which provides broader coverage and better scalability.
  7. Test Thoroughly: Never deploy a parser to production without validating it against edge cases, performance benchmarks, and schema requirements.

By mastering these concepts, you ensure that your security operations center remains agile and capable of handling the constant influx of data in modern enterprise environments. You transform the SIEM from a simple log storage solution into a powerful, intelligent platform that provides clear, actionable insights into your security posture.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.