[cisco_ios] Fix script_timezone crash for unrecognised TZ abbreviations. - #20733
[cisco_ios] Fix script_timezone crash for unrecognised TZ abbreviations.#20733ie-ops wants to merge 7 commits into
Conversation
✅ Elastic Docs Style Checker (Vale)No issues found on modified lines! The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale. |
|
Pinging @elastic/integration-experience (Team:Integration-Experience) |
…default-yml-30976768
…ack and add AUSEST test coverage
|
✅ All changelog entries have the correct PR link. |
| ZoneId.of(event_timezone); | ||
| ctx._temp_.date_timezone = event_timezone; | ||
| } catch (Exception e) { | ||
| String fallback = (ctx._conf?.tz_offset != null) ? ctx._conf.tz_offset : 'UTC'; |
There was a problem hiding this comment.
Severity: 🟡 Medium confidence: medium path: packages/cisco_ios/data_stream/log/elasticsearch/ingest_pipeline/default.yml:202
The new catch falls back to _conf.tz_offset, but on the no-_temp_.tz path that is the exact value ZoneId.of() just rejected, so the document still fails the date processor and event.timezone is overwritten with null; only use tz_offset as a fallback when it is not the value that failed, and only set event.timezone when _temp_.tz is non-null.
Details
This catch block completes the fix requested in prior finding 199cb7e30c178460 (validating the long-form branch with ZoneId.of()), and for the _temp_.tz != null case it works as intended. The gap is the other way into this branch.
get_timezone() returns ctx._conf.tz_offset when the log carries no timezone abbreviation (line 170-172). tz_offset is a free-text var (type: text, description 'IANA time zone or time offset (e.g. +0200)'), so an operator value such as UTC+2:00 or one with stray whitespace reaches the else branch (it contains '+' / is longer than 4 chars) and fails ZoneId.of(). In that case:
- Line 202 computes
fallbackasctx._conf.tz_offset— the very string that just failed validation — so line 203 puts the invalid zone straight back into_temp_.date_timezoneand thedate_cisco_timestampprocessor throws exactly as before. The guard does not actually prevent the failure it was added for. - Line 204 assigns
ctx.event.timezone = ctx._temp_.tz, which is null on this path. That discards the timezone valueget_timezone()already recorded at line 171, so the document losesevent.timezoneentirely.
Both are unconditional consequences of the code as written, not a hypothetical. Guarding the fallback also hardens the _temp_.tz != null case, where an invalid tz_offset is likewise copied into date_timezone unvalidated.
Recommendation:
Validate the fallback before using it, and only write event.timezone when there is an abbreviation to record:
} catch (Exception e) {
String fallback = 'UTC';
if (ctx._conf?.tz_offset != null && ctx._conf.tz_offset != event_timezone) {
try {
ZoneId.of(ctx._conf.tz_offset);
fallback = ctx._conf.tz_offset;
} catch (Exception inner) {
fallback = 'UTC';
}
}
ctx._temp_.date_timezone = fallback;
if (ctx._temp_?.tz != null) {
ctx.event.timezone = ctx._temp_.tz;
}
ctx._temp_.tz_unmapped = true;
}The same reasoning applies to the SimpleDateFormat catch at lines 187-194, which shares the identical fallback expression.
🤖 AI-Generated Review | Vera Review Bot - v0.2.6 | 📚 Knowledge base: integration-skills
⚠️ Automated review — verify suggestions before applying.
Review summaryIssues found across the latest commits 4b53fa7 — 1 medium, 1 low
Package-level:
Issues found across earlier commits 41ea84f — 2 medium
🤖 AI-Generated Review | Vera Review Bot - v0.2.6 | 📚 Knowledge base: integration-skills
|
💔 Build Failed
Failed CI StepsHistory
|
Executive summary
The fix addresses a failure in the
script_timezoneprocessor when Cisco IOS log messages contain timezone abbreviations (e.g. SGT, ICT, NPT) that Java'sSimpleDateFormatcannot resolve. Previously, an unhandled exception would crash the processor. The fix adds a built-in IANA zone-ID lookup map for 9 common abbreviations, wraps theSimpleDateFormatcall in a try/catch so unrecognised abbreviations fall back gracefully totz_offsetor UTC, preserves the original abbreviation inevent.timezone, and tags affected documents withcisco_ios_unmapped_timezoneto aid operator discovery.Proposed commit message
Root cause
The script_timezone Painless processor calls SimpleDateFormat('z').parse(event_timezone) without a try/catch, but Java's JDK only recognises a limited set of timezone abbreviations and throws ParseException for valid Cisco IOS-XR abbreviations common in APAC deployments (SGT, ICT, and others), causing the entire processor — including the cisco_timestamp append that feeds the date processor — to fail and routing the event to on_failure.
Approach
In the get_timezone() Painless function (default.yml lines 141–168), insert a hardcoded built-in IANA zone-ID lookup (SGT→Asia/Singapore, ICT→Asia/Bangkok, MYT→Asia/Kuala_Lumpur, PHT→Asia/Manila, TRT→Europe/Istanbul, BRT→America/Sao_Paulo, ART→America/Argentina/Buenos_Aires, CLT→America/Santiago, PET→America/Lima) immediately after the 'Z' check and before the length() <= 4 check, so matched abbreviations return canonical DST-aware zone IDs that exceed 4 characters and route through the existing else branch without touching SimpleDateFormat. Additionally, wrap all four SimpleDateFormat statements (lines 173–176: sdf construction, parse, date_timezone assignment, cisco_timestamp append) in a single try/catch(Exception e) block to catch any remaining unrecognised abbreviations; the catch sets ctx.temp.date_timezone and ctx.event.timezone to ctx._conf?.tz_offset if set, else 'UTC'. This preserves user tz_map precedence, avoids the misidentifying ZoneId.SHORT_IDS fallback, and fixes SGT without breaking existing AEST/ACDT/EDT/CST/METDST cases.
Implementation
Pipeline changes
Field / mapping changes
—
Sanitized error message
Processor 'script' with tag 'script_timezone' in pipeline 'logs-cisco_ios.log-default' failed with message '[on_failure_message]'Sanitized log (
event_sanitizedexcerpt)<190>Jun 28 03:00:24 198.51.100.10 SGT: ROCASRBR-REDACTED 106569598: RP/0/RSP0/CPU0:2026 Jun 28 03:00:24.143 SGT: ipv4_acl_mgr[299]: %ACL-IPV4_ACL-6-IPACCESSLOGDP : access-list oam_egress_nds (100) deny icmp 203.0.113.20 TenGigE0/0/1/0-> 192.0.2.30 (0/0), 300 packetsReviewer concerns
tz_mapentries.@timestampusing UTC or the configured offset rather than the device's actual timezone, which means timestamps for unrecognised zones will be silently wrong unless operators notice thecisco_ios_unmapped_timezonetag.event.timezoneis only set in the catch branch; for successfully resolved built-in abbreviations the field is not explicitly set, which may be inconsistent with ECS expectations.@timestampin UTC (2022-01-16T22:11:43.000Z) — this is correct for the fallback path but reviewers should confirm it matches the intended behaviour (NPT is UTC+5:45, so a UTC timestamp is deliberately incorrect).Self-review findings
—
Risk and classification
Links
7b2bddd483d30eee