正则表达式无法找到所有失败的存在

Regex couldn't find presence of all failures

Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 38, 382000, tzinfo=tzlocal())}}, {'Region': 'us-east-1', 'IPAddress': '01.000.2.12', 'StatusReport': {'Status': 'Success: DNS resolution Success: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 35, 371000, tzinfo=tzlocal())}}, {'Region': 'us-west-1', 'IPAddress': '01.000.14.10', 'StatusReport': {'Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 34, 715000, tzinfo=tzlocal())}}, {'Region': 'us-west-2', 'IPAddress': '01.000.22.10', 'StatusReport': {'Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 42, 801000, tzinfo=tzlocal())}}, {'Region': 'us-west-2', 'IPAddress': '01.000.18.10', 'StatusReport': {'Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 25, 189000, tzinfo=tzlocal())}}, {'Region': 'us-east-1', 'IPAddress': '01.000.1.10', 'StatusReport': {'Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 42, 293000, tzinfo=tzlocal())}}]}

问题:

我需要在字符串和关联的消息中找到任何失败,它不应该在消息中寻找任何成功。

Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 38, 382000, tzinfo=tzlocal())}}, {'Region': 'us-east-1', 'IPAddress': '01.000.2.12', 'Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 34, 715000, tzinfo=tzlocal())}}, {'Region': 'us-west-2', 'IPAddress': '01.000.22.10' etc.

我试过的:

Status':.+Failure.*(?=Success)

'Status':.+

但它没有给我想要的东西。

请帮忙!!

一个主要问题是数据也很相似,但又不完全 JSON。 Splunk 可以很好地处理 JSON,无论是在索引时,还是使用诸如 spath.

之类的命令

鉴于您的示例数据不是 JSON,我们需要回退到正则表达式。

这是一个非常基本的正则表达式,可以提取从初始 { 到双精度 }} 的所有内容,与您的数据相匹配。 (?m)max_match=0 告诉 Splunk 匹配尽可能多的次数。

| rex max_match=0 field=raw "(?m)(?<r>{.*}})"

现在 Splunk 已经匹配了事件中的每个条目,我们可以将它们拆分为单独的事件,并删除整个事件。

| mvexpand r | fields - raw

接下来,对每个条目执行 rex,仅提取 status_msg

| rex field=r "'Status': '(?<status_msg>[^']+)'"

最后,删除 events/rows,其中 status_msg 包含 Success

| where NOT status_msg LIKE "%Success%"

以下是处理您的数据的正则表达式示例。

| makeresults | eval raw="{[{'Region': 'us-east-1', 'IPAddress': '01.000.2.12', 'StatusReport': {'Status': 'Success: DNS resolution Success: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 35, 371000, tzinfo=tzlocal())}},
  {'Region': 'us-west-1', 'IPAddress': '01.000.14.10', 'StatusReport': {'Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 34, 715000, tzinfo=tzlocal())}},
  {'Region': 'us-west-2', 'IPAddress': '01.000.22.10', 'StatusReport': {'Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 42, 801000, tzinfo=tzlocal())}}, 
  {'Region': 'us-west-2', 'IPAddress': '01.000.18.10', 'StatusReport': {'Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 25, 189000, tzinfo=tzlocal())}},
  {'Region': 'us-east-1', 'IPAddress': '01.000.1.10', 'StatusReport': {'Status': 'Failure: DNS resolution failed: Rcode Domain(3)', 'CheckedTime': datetime.datetime(2017, 2, 1, 14, 47, 42, 293000, tzinfo=tzlocal())}}]}"
| rex max_match=9999 field=raw "(?m)(?<r>{.*}})"
| mvexpand r | fields - raw
| rex field=r "'Status': '(?<status_msg>[^']+)'"
| where NOT status_msg LIKE "%Success%"