как написать splunk-запрос для xml

#splunk

Вопрос:

 lt;!DOCTYPE EmployeeInventory SYSTEM 'EmployeeInventory.dtd'gt;lt;EmployeeInventory version="2.0"gt;lt;ProductInventoryInfogt;lt;Productgt;7781105882846lt;/Productgt;lt;EmployeeIDgt;12151lt;/EmployeeIDgt;lt;Quantitygt;28lt;/Quantitygt;lt;CenterIDgt;167551lt;/CenterIDgt;lt;/ProductInventoryInfogt;lt;/EmployeeInventorygt;   lt;!DOCTYPE EmployeeInventory SYSTEM 'EmployeeInventory.dtd'gt;lt;EmployeeInventory version="2.0"gt;lt;ProductInventoryInfogt;lt;Productgt;1781305782846lt;/Productgt;lt;EmployeeIDgt;12152lt;/EmployeeIDgt;lt;Quantitygt;18lt;/Quantitygt;lt;CenterIDgt;167552lt;/CenterIDgt;lt;/ProductInventoryInfogt;lt;/EmployeeInventorygt;  

Как написать splunk-запрос сверху журнала splunk, который будет извлекать таблицу, подобную этой .

 Product EmployeeID Quantity CenterID 7781105882846 12151 28 167551 1781305782846 12152 18 167552  

Ответ №1:

Это помогло бы узнать, что вы пробовали до сих пор и как эти попытки не смогли удовлетворить ваши потребности.

Хитрость заключается в извлечении полей из XML. Вы могли бы использовать ряд rex команд, но spath это проще.

 | makeresults | eval data="lt;!DOCTYPE EmployeeInventory SYSTEM 'EmployeeInventory.dtd'gt;lt;EmployeeInventory version="2.0"gt;lt;ProductInventoryInfogt;lt;Productgt;7781105882846lt;/Productgt;lt;EmployeeIDgt;12151lt;/EmployeeIDgt;lt;Quantitygt;28lt;/Quantitygt;lt;CenterIDgt;167551lt;/CenterIDgt;lt;/ProductInventoryInfogt;lt;/EmployeeInventorygt;;lt;!DOCTYPE EmployeeInventory SYSTEM 'EmployeeInventory.dtd'gt;lt;EmployeeInventory version="2.0"gt;lt;ProductInventoryInfogt;lt;Productgt;1781305782846lt;/Productgt;lt;EmployeeIDgt;12152lt;/EmployeeIDgt;lt;Quantitygt;18lt;/Quantitygt;lt;CenterIDgt;167552lt;/CenterIDgt;lt;/ProductInventoryInfogt;lt;/EmployeeInventorygt;" | eval data=split(data,";") | mvexpand data  ```The above is just for setting up test data``` ```Parse the data``` | spath input=data ```Replace "data" with the name of the field containing the data, perhaps "_raw"``` ```Simplify the field names``` | rename EmployeeInventory.ProductInventoryInfo.* as * ```Display the data``` | table Product EmployeeID Quantity CenterID