使用 Splunk - 使用 xpath 从日志文件中的 xml 数据中提取字段
Using Splunk - extract fields from xml data in a log file using xpath
我正在使用 Splunk 从日志文件中包含的 xml 数据中提取一些字段。因此,为了将搜索限制为主要是 xml 文件,我使用以下命令开始搜索:
来源类型="name of type here" "RULE"
这个returns:
0123459 TripMessage.createMessage MsgSource <?xml version="1.0" encoding="UTF-8"?>
<tmsTrip xmlns="http://ground.fedex.com/schemas/linehaul/trip" xmlns:ns2="http://ground.fedex.com/schemas/linehaul/TMSCommon">
...
文件很大。这是其中的一部分。
<?xml version="1.0" encoding="UTF-8"?>
<tmsTrip xmlns="http://ground.fedex.com/schemas/linehaul/trip" xmlns:ns2="http://ground.fedex.com/schemas/linehaul/TMSCommon">
<recordType>PURCHASEDLINEHAUL</recordType>
<eventType>APPROVE</eventType>
<tripId>116029927</tripId>
<legId>104257037</legId>
<tripNumber>104257037</tripNumber>
<tripLegNumber>1</tripLegNumber>
<updatedDateGMT>2020-02-20T21:53:39.000Z</updatedDateGMT>
.... more lines here that are not important
<purchasedCost>
<purchasedCostTripSegment>
<purchCostReference>1587040</purchCostReference>
<carrier>FXTR</carrier>
<vendorType>DRAY</vendorType>
<billingMethod>RULE</billingMethod>
<carrierTrailerType>PZ1</carrierTrailerType>
<origin>
<ns2:numberCode>923</ns2:numberCode>
<ns2:locAbbr>RLTO</ns2:locAbbr>
<ns2:address1>330 RESOURCE DRIVE</ns2:address1>
<ns2:address2>LH PHONE 877-851-3543</ns2:address2>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</origin>
此查询 select 是日志文件中的 xml 部分文本和一些字段,我可以将其添加到 table。 (不包括来源和来源类型..)
| xmlkv | table purchCostReference, eventType, carrier, billingMethod
但需要更多字段作为 xml 数据中的子元素。其中之一是 numberCode。我正在尝试使用 xpath 来提取这些附加字段。
| xmlkv | xpath
"//tmsTrip/purchasedCost/purchasedCostTripSegment/origin/ns2:numberCode" outfield=Origin | table purchCostReference, eventType, carrier, billingMethod, Origin
但是当我将字段添加到 table 时没有返回 Origin 数据。没有错误。来源列为空。
更新
我认为问题是我需要添加 field 参数。 xml 文件位于日志文本文件中。我将搜索限制为获取 xml 文件,但不仅限于 xml。所以我认为 xpath 正在与其他不是 xml.
的文本作斗争
更新
我尝试使用日志语句中 xml 文件的向导创建一个提取的字段。 xml 很大,我只能 select 大约 30%。如果有人擅长正则表达式,也许他们可以给我一些关于如何完成正则表达式命令以获取所有 xml 的指示。 (我尝试更新 props.conf 文件但没有添加 TRUNCATE = 0 的权限)。
这是 xml 文件示例:
<?xml version="1.0" encoding="UTF-8"?>
<tmsTrip xmlns="http://ground.fedex.com/schemas/linehaul/trip" xmlns:ns2="http://ground.fedex.com/schemas/linehaul/TMSCommon">
<recordType>PURCHASEDLINEHAUL</recordType>
<eventType>APPROVE</eventType>
<tripId>143642990</tripId>
<legId>129014817</legId>
<tripNumber>129014817</tripNumber>
<tripLegNumber>1</tripLegNumber>
<updatedDateGMT>2020-05-22T00:53:21.000Z</updatedDateGMT>
<origin>
<ns2:numberCode>928</ns2:numberCode>
<ns2:locAbbr>ANAH</ns2:locAbbr>
<ns2:address1>590 E ORANGE THORPE AVENUE</ns2:address1>
<ns2:city>ANAHEIM</ns2:city>
<ns2:stateProvince>CA</ns2:stateProvince>
<ns2:postalCode>92801</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>1</ns2:numberType>
<ns2:timeZoneAbbr>PST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</origin>
<destination>
<ns2:numberCode>89</ns2:numberCode>
<ns2:locAbbr>WOOD</ns2:locAbbr>
<ns2:address1>6000 RIVERSIDE DR</ns2:address1>
<ns2:address2>LH PHONE 732-512-5579</ns2:address2>
<ns2:city>KEASBEY</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>08832</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>2</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</destination>
<schedDispatchDateGMT>2020-05-22T13:00:00.000Z</schedDispatchDateGMT>
<estimatedArrivalDateGMT>2020-05-26T06:00:00.000Z</estimatedArrivalDateGMT>
<drop/>
<hook/>
<actualRoute>
<routeNumber>308229</routeNumber>
<routeOrderNumber>0</routeOrderNumber>
<totalMiles>2787</totalMiles>
<runTime>54.6</runTime>
</actualRoute>
<standardRoute>
<routeNumber>308229</routeNumber>
<routeOrderNumber>0</routeOrderNumber>
<totalMiles>2787</totalMiles>
<runTime>54.6</runTime>
</standardRoute>
<paidRoute>
<routeNumber>308229</routeNumber>
<routeOrderNumber>0</routeOrderNumber>
<totalMiles>2787</totalMiles>
<runTime>54.6</runTime>
</paidRoute>
<settlement>
<dispatchSettlementEligibility>false</dispatchSettlementEligibility>
</settlement>
<livePkgCount>0.0</livePkgCount>
<tripTollAmount>0.0</tripTollAmount>
<trailers>
<ns2:trailer>
<ns2:trailerNbr>531823</ns2:trailerNbr>
<ns2:trailerPrefix>FDXU</ns2:trailerPrefix>
<ns2:configOrderNbr>1</ns2:configOrderNbr>
<ns2:sealNbr>60606220</ns2:sealNbr>
<ns2:packageWeight>9931.59</ns2:packageWeight>
<ns2:unladenWeight>13870.0</ns2:unladenWeight>
<ns2:totalWeight>23801.59</ns2:totalWeight>
<ns2:packageNumber>703</ns2:packageNumber>
<ns2:percentCube>1</ns2:percentCube>
<ns2:hazmatFlag>false</ns2:hazmatFlag>
<ns2:originPlanned>
<ns2:numberCode>928</ns2:numberCode>
<ns2:locAbbr>ANAH</ns2:locAbbr>
<ns2:address1>590 E ORANGE THORPE AVENUE</ns2:address1>
<ns2:city>ANAHEIM</ns2:city>
<ns2:stateProvince>CA</ns2:stateProvince>
<ns2:postalCode>92801</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>1</ns2:numberType>
<ns2:timeZoneAbbr>PST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</ns2:originPlanned>
<ns2:nextSortLocation>
<ns2:numberCode>89</ns2:numberCode>
<ns2:locAbbr>WOOD</ns2:locAbbr>
<ns2:address1>6000 RIVERSIDE DR</ns2:address1>
<ns2:address2>LH PHONE 732-512-5579</ns2:address2>
<ns2:city>KEASBEY</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>08832</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>2</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</ns2:nextSortLocation>
<ns2:destinationPlanned>
<ns2:numberCode>89</ns2:numberCode>
<ns2:locAbbr>WOOD</ns2:locAbbr>
<ns2:address1>6000 RIVERSIDE DR</ns2:address1>
<ns2:address2>LH PHONE 732-512-5579</ns2:address2>
<ns2:city>KEASBEY</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>08832</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>2</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</ns2:destinationPlanned>
<ns2:loads>
<ns2:load>
<ns2:loadId>103718801</ns2:loadId>
<ns2:loadNumber>1</ns2:loadNumber>
<ns2:origin>
<ns2:numberCode>928</ns2:numberCode>
<ns2:locAbbr>ANAH</ns2:locAbbr>
<ns2:numberType>1</ns2:numberType>
</ns2:origin>
<ns2:destination>
<ns2:numberCode>89</ns2:numberCode>
<ns2:locAbbr>WOOD</ns2:locAbbr>
<ns2:address2>LH PHONE 732-512-5579</ns2:address2>
<ns2:numberType>2</ns2:numberType>
</ns2:destination>
<ns2:openDateGMT>2020-05-21T19:53:46.000Z</ns2:openDateGMT>
<ns2:dueOverrideFlag>false</ns2:dueOverrideFlag>
<ns2:hazmatFlag>false</ns2:hazmatFlag>
</ns2:load>
</ns2:loads>
</ns2:trailer>
</trailers>
<dollys/>
<purchasedCost>
<purchasedCostTripSegment>
<purchCostReference>2625998</purchCostReference>
<carrier>BNSF</carrier>
<vendorType>RAIL</vendorType>
<carrierTrailerType>53PC</carrierTrailerType>
<origin>
<ns2:numberCode>4022</ns2:numberCode>
<ns2:locAbbr>BNSF</ns2:locAbbr>
<ns2:address1>3770 EAST WASHINGTON AVENUE</ns2:address1>
<ns2:city>LOS ANGELES</ns2:city>
<ns2:stateProvince>CA</ns2:stateProvince>
<ns2:postalCode>90040</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>PST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</origin>
<destination>
<ns2:numberCode>4040</ns2:numberCode>
<ns2:locAbbr>CROX</ns2:locAbbr>
<ns2:address1>NORFOLK SOUTHERN RAILROAD</ns2:address1>
<ns2:address2>125 COUNTY ROAD</ns2:address2>
<ns2:city>CROXTON</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>07307</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</destination>
<stopOff>
<ns2:stopOffLocation>
<ns2:numberCode>9996</ns2:numberCode>
<ns2:stateProvince>DU</ns2:stateProvince>
<ns2:postalCode>00000</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>1</ns2:numberType>
</ns2:stopOffLocation>
</stopOff>
<schedDispatchDate>2020-05-22T05:00:00.000Z</schedDispatchDate>
<estimatedArrivalDate>2020-05-26T00:59:00.000Z</estimatedArrivalDate>
<billingMethod>RULE</billingMethod>
<STCCCode>4711110</STCCCode>
<planNumber>065</planNumber>
<powerType>1X</powerType>
<powerOnlyFlag>false</powerOnlyFlag>
</purchasedCostTripSegment>
<purchasedCostTripSegment>
<purchCostReference>2625998</purchCostReference>
<carrier>NS</carrier>
<vendorType>RAIL</vendorType>
<carrierTrailerType>53PC</carrierTrailerType>
<origin>
<ns2:numberCode>4061</ns2:numberCode>
<ns2:locAbbr>NSAU</ns2:locAbbr>
<ns2:address1>6300 SOUTH INDIANA AVENUE</ns2:address1>
<ns2:city>CHICAGO</ns2:city>
<ns2:stateProvince>IL</ns2:stateProvince>
<ns2:postalCode>60637</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>CST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</origin>
<destination>
<ns2:numberCode>4040</ns2:numberCode>
<ns2:locAbbr>CROX</ns2:locAbbr>
<ns2:address1>NORFOLK SOUTHERN RAILROAD</ns2:address1>
<ns2:address2>125 COUNTY ROAD</ns2:address2>
<ns2:city>CROXTON</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>07307</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</destination>
<stopOff>
<ns2:stopOffLocation>
<ns2:numberCode>4040</ns2:numberCode>
<ns2:locAbbr>CROX</ns2:locAbbr>
<ns2:address1>NORFOLK SOUTHERN RAILROAD</ns2:address1>
<ns2:address2>125 COUNTY ROAD</ns2:address2>
<ns2:city>CROXTON</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>07307</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</ns2:stopOffLocation>
</stopOff>
<schedDispatchDate>2020-05-22T05:00:00.000Z</schedDispatchDate>
<estimatedArrivalDate>2020-05-26T01:00:00.000Z</estimatedArrivalDate>
<billingMethod>LOCAL</billingMethod>
<STCCCode>4711110</STCCCode>
<planNumber>045</planNumber>
<powerType>1X</powerType>
<powerOnlyFlag>false</powerOnlyFlag>
</purchasedCostTripSegment>
</purchasedCost>
<drivers/>
</tmsTrip>
这是我可以提取多少字段select:
http://ground.fedex.com/schemas/linehaul/trip\" xmlns:ns2=\"http://ground.fedex.com/schemas/linehaul/TMSCommon\">
采购线运
批准
143642990
129014817
129014817
1个
2020-05-22T00:53:21.000Z
928
安娜
590 E 橙色索普大道
阿纳海姆
加州
92801
FDEG
1个
太平洋标准时间
真
这是 Splunk 为 select 上面 xml
创建的正则表达式
^[^$\n]*$\d+\.\w+\s+\w+\s+(?P<xmlMessage><\?\w+\s+\w+="\d+\.\d+"\s+\w+="\w+\-\d+"\?>\s+<\w+\s+\w+="\w+://\w+\.\w+\.\w+/\w+/\w+/\w+"\s+\w+:\w+="\w+://\w+\.\w+\.\w+/\w+/\w+/\w+">\s+<\w+>\w+</\w+>\s+<\w+>\w+</\w+>\s+<\w+>\d+</\w+>\s+<\w+>\d+</\w+>\s+<\w+>\d+</\w+>\s+<\w+>\d+</\w+>\s+<\w+>\d+\-\d+\-\d+\w+:\d+:\d+\.\d+\w+</\w+>\s+<\w+>\s+<\w+:\w+>\d+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\d+\s+\w+\s+\w+\s+\w+\s+\w+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\d+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\d+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>)
那么我可以更改上面的正则表达式以包含整个 xml 吗?
更新
我尝试从 xmlMessage 提取的字段中提取一个字段。 xml消息字段在上面。我使用 xpath 命令提取 recordType。将结果放在 table 中。这是命令
| xmlkv | xpath field=xmlMessage
"//tmsTrip/recordType" outfield=Origin | table Origin
没有返回任何结果。此 xpath 命令不适用于最简单的查询。
我做错了什么?
没有看到其余的事件数据,我不能说为什么 xpath
命令不起作用。
但是,作为解决方法,请尝试以下操作而不是 xmlkv
和 xpath
命令
| rex field=_raw "numberCode>(?<Origin>\d+)</"
这应该适用于混合文本和 xml 事件
| xmlkv | spath path="tmsTrip.purchasedCost.purchasedCostTripSegment.origin.ns2:numberCode" output=Origin
尝试spath
我能够使用 rex 从 xml 中提取数据,并使用 max_match[ 识别 numberCode 的每个实例=21=] 和 mvindex
这是遇到此问题的任何人的示例:
rex max_match=0 "\<ns2\:numberCode\>(?P<location>[^\<]+)"| eval Segment1_Origin = mvindex(location, 7)
xml 元素是 ns2:numberCode。它已重命名为 location。 max_match=0 表示无限个实例。 mvindex 是从零开始的。因此位置的第 8 个实例设置为变量 Segment1_origin
我正在使用 Splunk 从日志文件中包含的 xml 数据中提取一些字段。因此,为了将搜索限制为主要是 xml 文件,我使用以下命令开始搜索: 来源类型="name of type here" "RULE"
这个returns:
0123459 TripMessage.createMessage MsgSource <?xml version="1.0" encoding="UTF-8"?>
<tmsTrip xmlns="http://ground.fedex.com/schemas/linehaul/trip" xmlns:ns2="http://ground.fedex.com/schemas/linehaul/TMSCommon">
...
文件很大。这是其中的一部分。
<?xml version="1.0" encoding="UTF-8"?>
<tmsTrip xmlns="http://ground.fedex.com/schemas/linehaul/trip" xmlns:ns2="http://ground.fedex.com/schemas/linehaul/TMSCommon">
<recordType>PURCHASEDLINEHAUL</recordType>
<eventType>APPROVE</eventType>
<tripId>116029927</tripId>
<legId>104257037</legId>
<tripNumber>104257037</tripNumber>
<tripLegNumber>1</tripLegNumber>
<updatedDateGMT>2020-02-20T21:53:39.000Z</updatedDateGMT>
.... more lines here that are not important
<purchasedCost>
<purchasedCostTripSegment>
<purchCostReference>1587040</purchCostReference>
<carrier>FXTR</carrier>
<vendorType>DRAY</vendorType>
<billingMethod>RULE</billingMethod>
<carrierTrailerType>PZ1</carrierTrailerType>
<origin>
<ns2:numberCode>923</ns2:numberCode>
<ns2:locAbbr>RLTO</ns2:locAbbr>
<ns2:address1>330 RESOURCE DRIVE</ns2:address1>
<ns2:address2>LH PHONE 877-851-3543</ns2:address2>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</origin>
此查询 select 是日志文件中的 xml 部分文本和一些字段,我可以将其添加到 table。 (不包括来源和来源类型..)
| xmlkv | table purchCostReference, eventType, carrier, billingMethod
但需要更多字段作为 xml 数据中的子元素。其中之一是 numberCode。我正在尝试使用 xpath 来提取这些附加字段。
| xmlkv | xpath
"//tmsTrip/purchasedCost/purchasedCostTripSegment/origin/ns2:numberCode" outfield=Origin | table purchCostReference, eventType, carrier, billingMethod, Origin
但是当我将字段添加到 table 时没有返回 Origin 数据。没有错误。来源列为空。
更新 我认为问题是我需要添加 field 参数。 xml 文件位于日志文本文件中。我将搜索限制为获取 xml 文件,但不仅限于 xml。所以我认为 xpath 正在与其他不是 xml.
的文本作斗争更新 我尝试使用日志语句中 xml 文件的向导创建一个提取的字段。 xml 很大,我只能 select 大约 30%。如果有人擅长正则表达式,也许他们可以给我一些关于如何完成正则表达式命令以获取所有 xml 的指示。 (我尝试更新 props.conf 文件但没有添加 TRUNCATE = 0 的权限)。 这是 xml 文件示例:
<?xml version="1.0" encoding="UTF-8"?>
<tmsTrip xmlns="http://ground.fedex.com/schemas/linehaul/trip" xmlns:ns2="http://ground.fedex.com/schemas/linehaul/TMSCommon">
<recordType>PURCHASEDLINEHAUL</recordType>
<eventType>APPROVE</eventType>
<tripId>143642990</tripId>
<legId>129014817</legId>
<tripNumber>129014817</tripNumber>
<tripLegNumber>1</tripLegNumber>
<updatedDateGMT>2020-05-22T00:53:21.000Z</updatedDateGMT>
<origin>
<ns2:numberCode>928</ns2:numberCode>
<ns2:locAbbr>ANAH</ns2:locAbbr>
<ns2:address1>590 E ORANGE THORPE AVENUE</ns2:address1>
<ns2:city>ANAHEIM</ns2:city>
<ns2:stateProvince>CA</ns2:stateProvince>
<ns2:postalCode>92801</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>1</ns2:numberType>
<ns2:timeZoneAbbr>PST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</origin>
<destination>
<ns2:numberCode>89</ns2:numberCode>
<ns2:locAbbr>WOOD</ns2:locAbbr>
<ns2:address1>6000 RIVERSIDE DR</ns2:address1>
<ns2:address2>LH PHONE 732-512-5579</ns2:address2>
<ns2:city>KEASBEY</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>08832</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>2</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</destination>
<schedDispatchDateGMT>2020-05-22T13:00:00.000Z</schedDispatchDateGMT>
<estimatedArrivalDateGMT>2020-05-26T06:00:00.000Z</estimatedArrivalDateGMT>
<drop/>
<hook/>
<actualRoute>
<routeNumber>308229</routeNumber>
<routeOrderNumber>0</routeOrderNumber>
<totalMiles>2787</totalMiles>
<runTime>54.6</runTime>
</actualRoute>
<standardRoute>
<routeNumber>308229</routeNumber>
<routeOrderNumber>0</routeOrderNumber>
<totalMiles>2787</totalMiles>
<runTime>54.6</runTime>
</standardRoute>
<paidRoute>
<routeNumber>308229</routeNumber>
<routeOrderNumber>0</routeOrderNumber>
<totalMiles>2787</totalMiles>
<runTime>54.6</runTime>
</paidRoute>
<settlement>
<dispatchSettlementEligibility>false</dispatchSettlementEligibility>
</settlement>
<livePkgCount>0.0</livePkgCount>
<tripTollAmount>0.0</tripTollAmount>
<trailers>
<ns2:trailer>
<ns2:trailerNbr>531823</ns2:trailerNbr>
<ns2:trailerPrefix>FDXU</ns2:trailerPrefix>
<ns2:configOrderNbr>1</ns2:configOrderNbr>
<ns2:sealNbr>60606220</ns2:sealNbr>
<ns2:packageWeight>9931.59</ns2:packageWeight>
<ns2:unladenWeight>13870.0</ns2:unladenWeight>
<ns2:totalWeight>23801.59</ns2:totalWeight>
<ns2:packageNumber>703</ns2:packageNumber>
<ns2:percentCube>1</ns2:percentCube>
<ns2:hazmatFlag>false</ns2:hazmatFlag>
<ns2:originPlanned>
<ns2:numberCode>928</ns2:numberCode>
<ns2:locAbbr>ANAH</ns2:locAbbr>
<ns2:address1>590 E ORANGE THORPE AVENUE</ns2:address1>
<ns2:city>ANAHEIM</ns2:city>
<ns2:stateProvince>CA</ns2:stateProvince>
<ns2:postalCode>92801</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>1</ns2:numberType>
<ns2:timeZoneAbbr>PST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</ns2:originPlanned>
<ns2:nextSortLocation>
<ns2:numberCode>89</ns2:numberCode>
<ns2:locAbbr>WOOD</ns2:locAbbr>
<ns2:address1>6000 RIVERSIDE DR</ns2:address1>
<ns2:address2>LH PHONE 732-512-5579</ns2:address2>
<ns2:city>KEASBEY</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>08832</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>2</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</ns2:nextSortLocation>
<ns2:destinationPlanned>
<ns2:numberCode>89</ns2:numberCode>
<ns2:locAbbr>WOOD</ns2:locAbbr>
<ns2:address1>6000 RIVERSIDE DR</ns2:address1>
<ns2:address2>LH PHONE 732-512-5579</ns2:address2>
<ns2:city>KEASBEY</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>08832</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>2</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</ns2:destinationPlanned>
<ns2:loads>
<ns2:load>
<ns2:loadId>103718801</ns2:loadId>
<ns2:loadNumber>1</ns2:loadNumber>
<ns2:origin>
<ns2:numberCode>928</ns2:numberCode>
<ns2:locAbbr>ANAH</ns2:locAbbr>
<ns2:numberType>1</ns2:numberType>
</ns2:origin>
<ns2:destination>
<ns2:numberCode>89</ns2:numberCode>
<ns2:locAbbr>WOOD</ns2:locAbbr>
<ns2:address2>LH PHONE 732-512-5579</ns2:address2>
<ns2:numberType>2</ns2:numberType>
</ns2:destination>
<ns2:openDateGMT>2020-05-21T19:53:46.000Z</ns2:openDateGMT>
<ns2:dueOverrideFlag>false</ns2:dueOverrideFlag>
<ns2:hazmatFlag>false</ns2:hazmatFlag>
</ns2:load>
</ns2:loads>
</ns2:trailer>
</trailers>
<dollys/>
<purchasedCost>
<purchasedCostTripSegment>
<purchCostReference>2625998</purchCostReference>
<carrier>BNSF</carrier>
<vendorType>RAIL</vendorType>
<carrierTrailerType>53PC</carrierTrailerType>
<origin>
<ns2:numberCode>4022</ns2:numberCode>
<ns2:locAbbr>BNSF</ns2:locAbbr>
<ns2:address1>3770 EAST WASHINGTON AVENUE</ns2:address1>
<ns2:city>LOS ANGELES</ns2:city>
<ns2:stateProvince>CA</ns2:stateProvince>
<ns2:postalCode>90040</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>PST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</origin>
<destination>
<ns2:numberCode>4040</ns2:numberCode>
<ns2:locAbbr>CROX</ns2:locAbbr>
<ns2:address1>NORFOLK SOUTHERN RAILROAD</ns2:address1>
<ns2:address2>125 COUNTY ROAD</ns2:address2>
<ns2:city>CROXTON</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>07307</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</destination>
<stopOff>
<ns2:stopOffLocation>
<ns2:numberCode>9996</ns2:numberCode>
<ns2:stateProvince>DU</ns2:stateProvince>
<ns2:postalCode>00000</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>1</ns2:numberType>
</ns2:stopOffLocation>
</stopOff>
<schedDispatchDate>2020-05-22T05:00:00.000Z</schedDispatchDate>
<estimatedArrivalDate>2020-05-26T00:59:00.000Z</estimatedArrivalDate>
<billingMethod>RULE</billingMethod>
<STCCCode>4711110</STCCCode>
<planNumber>065</planNumber>
<powerType>1X</powerType>
<powerOnlyFlag>false</powerOnlyFlag>
</purchasedCostTripSegment>
<purchasedCostTripSegment>
<purchCostReference>2625998</purchCostReference>
<carrier>NS</carrier>
<vendorType>RAIL</vendorType>
<carrierTrailerType>53PC</carrierTrailerType>
<origin>
<ns2:numberCode>4061</ns2:numberCode>
<ns2:locAbbr>NSAU</ns2:locAbbr>
<ns2:address1>6300 SOUTH INDIANA AVENUE</ns2:address1>
<ns2:city>CHICAGO</ns2:city>
<ns2:stateProvince>IL</ns2:stateProvince>
<ns2:postalCode>60637</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>CST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</origin>
<destination>
<ns2:numberCode>4040</ns2:numberCode>
<ns2:locAbbr>CROX</ns2:locAbbr>
<ns2:address1>NORFOLK SOUTHERN RAILROAD</ns2:address1>
<ns2:address2>125 COUNTY ROAD</ns2:address2>
<ns2:city>CROXTON</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>07307</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</destination>
<stopOff>
<ns2:stopOffLocation>
<ns2:numberCode>4040</ns2:numberCode>
<ns2:locAbbr>CROX</ns2:locAbbr>
<ns2:address1>NORFOLK SOUTHERN RAILROAD</ns2:address1>
<ns2:address2>125 COUNTY ROAD</ns2:address2>
<ns2:city>CROXTON</ns2:city>
<ns2:stateProvince>NJ</ns2:stateProvince>
<ns2:postalCode>07307</ns2:postalCode>
<ns2:locType>FDEG</ns2:locType>
<ns2:numberType>8</ns2:numberType>
<ns2:timeZoneAbbr>EST</ns2:timeZoneAbbr>
<ns2:daylightSavingsFlag>true</ns2:daylightSavingsFlag>
</ns2:stopOffLocation>
</stopOff>
<schedDispatchDate>2020-05-22T05:00:00.000Z</schedDispatchDate>
<estimatedArrivalDate>2020-05-26T01:00:00.000Z</estimatedArrivalDate>
<billingMethod>LOCAL</billingMethod>
<STCCCode>4711110</STCCCode>
<planNumber>045</planNumber>
<powerType>1X</powerType>
<powerOnlyFlag>false</powerOnlyFlag>
</purchasedCostTripSegment>
</purchasedCost>
<drivers/>
</tmsTrip>
这是我可以提取多少字段select: http://ground.fedex.com/schemas/linehaul/trip\" xmlns:ns2=\"http://ground.fedex.com/schemas/linehaul/TMSCommon\"> 采购线运 批准 143642990 129014817 129014817 1个 2020-05-22T00:53:21.000Z 928 安娜 590 E 橙色索普大道 阿纳海姆 加州 92801 FDEG 1个 太平洋标准时间 真
这是 Splunk 为 select 上面 xml
创建的正则表达式^[^$\n]*$\d+\.\w+\s+\w+\s+(?P<xmlMessage><\?\w+\s+\w+="\d+\.\d+"\s+\w+="\w+\-\d+"\?>\s+<\w+\s+\w+="\w+://\w+\.\w+\.\w+/\w+/\w+/\w+"\s+\w+:\w+="\w+://\w+\.\w+\.\w+/\w+/\w+/\w+">\s+<\w+>\w+</\w+>\s+<\w+>\w+</\w+>\s+<\w+>\d+</\w+>\s+<\w+>\d+</\w+>\s+<\w+>\d+</\w+>\s+<\w+>\d+</\w+>\s+<\w+>\d+\-\d+\-\d+\w+:\d+:\d+\.\d+\w+</\w+>\s+<\w+>\s+<\w+:\w+>\d+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\d+\s+\w+\s+\w+\s+\w+\s+\w+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\d+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\d+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>\s+<\w+:\w+>\w+</\w+:\w+>)
那么我可以更改上面的正则表达式以包含整个 xml 吗?
更新 我尝试从 xmlMessage 提取的字段中提取一个字段。 xml消息字段在上面。我使用 xpath 命令提取 recordType。将结果放在 table 中。这是命令
| xmlkv | xpath field=xmlMessage
"//tmsTrip/recordType" outfield=Origin | table Origin
没有返回任何结果。此 xpath 命令不适用于最简单的查询。 我做错了什么?
没有看到其余的事件数据,我不能说为什么 xpath
命令不起作用。
但是,作为解决方法,请尝试以下操作而不是 xmlkv
和 xpath
命令
| rex field=_raw "numberCode>(?<Origin>\d+)</"
这应该适用于混合文本和 xml 事件
| xmlkv | spath path="tmsTrip.purchasedCost.purchasedCostTripSegment.origin.ns2:numberCode" output=Origin
尝试spath
我能够使用 rex 从 xml 中提取数据,并使用 max_match[ 识别 numberCode 的每个实例=21=] 和 mvindex 这是遇到此问题的任何人的示例:
rex max_match=0 "\<ns2\:numberCode\>(?P<location>[^\<]+)"| eval Segment1_Origin = mvindex(location, 7)
xml 元素是 ns2:numberCode。它已重命名为 location。 max_match=0 表示无限个实例。 mvindex 是从零开始的。因此位置的第 8 个实例设置为变量 Segment1_origin