Xml multi elemts parsing


(Povilas) #1

Hello,

I have a problem with multi elements XML

I try take values like this:

xml {
source => "parsedXML"
remove_namespaces => "true"
force_array => "false"
force_content => "true"
xpath => ["//msisdn/text()", "msisdn",
"//ocsIp/text()", "ocsIP",
"//sessionId/text()","sessionId",
"//sgsnIp/text()", "sgsnIp",
"//ggsnIp/text()", "ggsnIp",
"//sgsnMccMnc/text()", "sgsnMccMnc",
"//apn/text()", "apn",
"//imsi/text()", "imsi",
"//imei/text()", "imei",
"//userLocationInfo/text()", "userLocationInfo",
"//chargingId/text()", "chargingId",
"//ip/text()", "ip",
"//chargingCharacteristic/text()", "chargingCharacteristic",
"//qos/text()", "qos",
"//chargingRuleName/text()", "chargingRuleName",
"//requestNumber/text()", "requestNumber",
"//creditControlFailureHandlingType/text()", "creditControlFailureHandlingType",
"//ccSessionFailover/text()", "ccSessionFailover",
"//ccRequestType/text()", "ccRequestType",
"//ccRequestNumber/text()", "ccRequestNumber",
"/cca/resultCode/text()", "totalResultCode",
"//msccList/mscc", "parsedMscc",
"//requestType/text()", "requestType"
]
store_xml => "false"
}
xml {
source => "parsedMscc"
remove_namespaces => "true"
#target => "mscc"
force_array => "false"
force_content => "true"
xpath => ["/mscc/inputOctetsGranted/text()", "inputOctetsGranted",
"/mscc/outputOctetsGranted/text()", "outputOctetsGranted",
"/mscc/totalOctetsGranted/text()", "totalOctetsGranted",
"/mscc/timeGranted/text()", "timeGranted",
"/mscc/quotaConsumptionTime/text()", "quotaConsumptionTime",
"/mscc/quotaHoldingTime/text()", "quotaHoldingTime",
"/mscc/volumeQuotaThreshold/text()", "volumeQuotaThreshold",
"/mscc/resultCode/text()", "resultCode",
"/mscc/message/text()", "message",
"/mscc/ratingGroup/text()", "ratingGroup",
"/mscc/finalUnitIndication/text()", "finalUnitIndication"
]
store_xml => "false"
}
mutate {
remove_field => [ "parsedXML", "message", "msg","parsedMscc"]
}

but then I get json like this :

{
"_index": "ocs-2018.12.05",
"_type": "doc",
"id": "AWd-cYVFO5tqPqZWL1T",
"_version": 1,
"_score": null,
"_source": {
"resultCode": [
"2001"
],
"@version": "1",
"outputOctetsGranted": [
"0"
],
"offset": 514999799,
"ccRequestNumber": [
"19"
],
"totalResultCode": [
"2001"
],
"ccRequestType": [
"2"
],
"host": "miram.int.bite.lt",
"quotaConsumptionTime": [
"0"
],
"ratingGroup": [
"2040","2050"
],
"@timestamp": "2018-12-05T12:57:03.214Z",
"totalOctetsGranted": [
"15728640"
],
"prospector": {
"type": "log"
},
"ts": "2018-12-05 14:09:18,018",
"inputOctetsGranted": [
"0"
],
"beat": {
"hostname": "sssss",
"version": "6.2.3",
"name": "miram.int.bite.lt"
},
"loglevel": "INFO",
"timeGranted": [
"6407"
],
"tags": [
"beats_input_codec_plain_applied"
],
"msisdn": [
"370000000"
],
"volumeQuotaThreshold": [
"0"
],
"source": "/ocs/mobicents/server/bite/log/ocs.log",
"quotaHoldingTime": [
"0"
]
},
"fields": {
"@timestamp": [
1544014623214
]
},
"sort": [
1544014623214
]
}

my xml looks like:

<?xml version="1.0"?>
<cca>
	<ccRequestType>1</ccRequestType>
	<ccRequestNumber>1000</ccRequestNumber>
	<msisdn>37000000</msisdn>
	<resultCode>4012</resultCode>
	<msccList>
		<mscc>
			<inputOctetsGranted>0</inputOctetsGranted>
			<outputOctetsGranted>0</outputOctetsGranted>
			<totalOctetsGranted>0</totalOctetsGranted>
			<timeGranted>0</timeGranted>
			<quotaConsumptionTime>0</quotaConsumptionTime>
			<quotaHoldingTime>0</quotaHoldingTime>
			<timeQuotaThreshold>0</timeQuotaThreshold>
			<volumeQuotaThreshold>0</volumeQuotaThreshold>
			<resultCode>4012</resultCode>
			<message>OK</message>
			<ratingGroup>1000</ratingGroup>
			<finalUnitIndication/>
		</mscc>
		<mscc>
			<inputOctetsGranted>0</inputOctetsGranted>
			<outputOctetsGranted>0</outputOctetsGranted>
			<totalOctetsGranted>0</totalOctetsGranted>
			<timeGranted>0</timeGranted>
			<quotaConsumptionTime>0</quotaConsumptionTime>
			<quotaHoldingTime>0</quotaHoldingTime>
			<timeQuotaThreshold>0</timeQuotaThreshold>
			<volumeQuotaThreshold>0</volumeQuotaThreshold>
			<resultCode>4012</resultCode>
			<message>OK</message>
			<ratingGroup>2000</ratingGroup>
			<finalUnitIndication/>
		</mscc>
	</msccList>
</cca>

I need to make json like xml ( if you check mscc this is my multi elemnt xml)