use super::{FormatFamily, PatternPriority};
use regex::Regex;
#[derive(Debug, Clone)]
pub struct TimestampPattern {
pub regex: Regex,
pub format_type: TimestampFormat,
pub priority: PatternPriority,
pub source: PatternSource,
}
#[allow(dead_code)]
#[derive(Debug, Clone, PartialEq)]
pub enum TimestampFormat {
ISO8601Full,
ISO8601NoZ,
ISO8601Date,
ISO8601Time,
ISO8601Enhanced,
WeekDate,
OrdinalDate,
RFC3339,
RFC3339NoZ,
RFC2822,
JavaSimpleDate,
KubernetesLog,
DockerLog,
ElasticsearchLog,
Log4j,
Splunk,
MySQLTimestamp,
PostgreSQLTimestamp,
Oracle,
USDate,
USDateDash,
EuropeanDate,
EuropeanDateDot,
ApacheCommon,
ApacheError,
NginxAccess,
UnixTimestamp,
UnixTimestampMs,
UnixTimestampNs,
UnixBracketed,
UnixPrefixed,
SyslogBSD,
SyslogRFC5424,
SyslogWithYear,
IBMFormat,
CompactFormat,
TimeOnly,
Duration,
WindowsEvent,
WindowsIIS,
GitCommit,
Aws,
Gcp,
Azure,
Ansic,
RFC822,
}
impl TimestampFormat {
pub fn format_family(&self) -> FormatFamily {
match self {
TimestampFormat::ISO8601Full
| TimestampFormat::ISO8601NoZ
| TimestampFormat::ISO8601Date
| TimestampFormat::ISO8601Time
| TimestampFormat::ISO8601Enhanced
| TimestampFormat::WeekDate
| TimestampFormat::OrdinalDate
| TimestampFormat::RFC3339
| TimestampFormat::RFC3339NoZ
| TimestampFormat::RFC2822
| TimestampFormat::RFC822 => FormatFamily::Structured,
TimestampFormat::JavaSimpleDate
| TimestampFormat::KubernetesLog
| TimestampFormat::DockerLog
| TimestampFormat::ElasticsearchLog
| TimestampFormat::Log4j
| TimestampFormat::Splunk
| TimestampFormat::ApacheCommon
| TimestampFormat::ApacheError
| TimestampFormat::NginxAccess
| TimestampFormat::Aws
| TimestampFormat::Gcp
| TimestampFormat::Azure => FormatFamily::Application,
TimestampFormat::USDate
| TimestampFormat::USDateDash
| TimestampFormat::EuropeanDate
| TimestampFormat::EuropeanDateDot
| TimestampFormat::WindowsEvent
| TimestampFormat::WindowsIIS => FormatFamily::Regional,
TimestampFormat::MySQLTimestamp
| TimestampFormat::PostgreSQLTimestamp
| TimestampFormat::Oracle => FormatFamily::Database,
TimestampFormat::SyslogBSD
| TimestampFormat::SyslogRFC5424
| TimestampFormat::SyslogWithYear
| TimestampFormat::IBMFormat
| TimestampFormat::CompactFormat
| TimestampFormat::GitCommit
| TimestampFormat::Ansic => FormatFamily::Legacy,
TimestampFormat::UnixTimestamp
| TimestampFormat::UnixTimestampMs
| TimestampFormat::UnixTimestampNs
| TimestampFormat::UnixBracketed
| TimestampFormat::UnixPrefixed => FormatFamily::Unix,
TimestampFormat::TimeOnly | TimestampFormat::Duration => FormatFamily::Legacy,
}
}
pub fn specificity_score(&self) -> u32 {
match self {
TimestampFormat::ISO8601Enhanced
| TimestampFormat::KubernetesLog
| TimestampFormat::DockerLog => 100,
TimestampFormat::ISO8601Full
| TimestampFormat::RFC3339
| TimestampFormat::WeekDate
| TimestampFormat::OrdinalDate => 90,
TimestampFormat::ISO8601NoZ
| TimestampFormat::RFC3339NoZ
| TimestampFormat::RFC2822 => 80,
TimestampFormat::ApacheCommon
| TimestampFormat::ApacheError
| TimestampFormat::JavaSimpleDate
| TimestampFormat::Log4j
| TimestampFormat::ElasticsearchLog => 70,
TimestampFormat::USDate
| TimestampFormat::EuropeanDate
| TimestampFormat::MySQLTimestamp
| TimestampFormat::PostgreSQLTimestamp
| TimestampFormat::Oracle => 60,
TimestampFormat::SyslogBSD
| TimestampFormat::SyslogRFC5424
| TimestampFormat::CompactFormat
| TimestampFormat::IBMFormat => 50,
TimestampFormat::UnixTimestamp
| TimestampFormat::UnixTimestampMs
| TimestampFormat::UnixTimestampNs => 10,
TimestampFormat::UnixBracketed | TimestampFormat::UnixPrefixed => 20,
_ => 40,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum PatternSource {
OriginalTimestamp,
OriginalEssence,
Merged,
}