xpath icon indicating copy to clipboard operation
xpath copied to clipboard

Wanted help parsing xml data with telegraf

Open pratikdas44 opened this issue 2 years ago • 2 comments

My xml data is - <root> <measEntity localDn="VNFID=bangloreiit-5005cucp1; gNBID=5005; gNBName=;" swVersion="6.0.00.49.6"/> <measData> <measInfo measInfoId="OR.end"> <granPeriod duration="PT300S" endTime="2021-07-02T17:10:00+00:00"/> <measTypes>SgnbAddAttemptCell.enb.0 SgnbAddAttemptCell.enb.1 SgnbAddAttemptCell.enb.2 SgnbAddAttemptCell.enb.3</measTypes> <measResults>0 0 0 0</measResults> </measInfo> </measData> </root>

I wanted to parse it using telegraf. I am able to get measurement, but currently i am facing 2 challenges:

Tag name - measEntity will provide tag name; eg - tag VNFID with value bangaloreiit-5005cucp1 and so on. But i am not able to get the tags.

Field name - Using measTypes i want to get the fieldnames which are separated by space- eg - SgnbAddAttemptCell.enb.0, SgnbAddAttemptCell.enb.1 and so on and their respective values inside measResults portion. I tried using tokenize but it was giving error in telegraf. Any way to do that using other predefined functions?

pratikdas44 avatar Jul 07 '21 07:07 pratikdas44

Hi, it seems like we are trying to do the same, but my xml looks a bit different: (simplified)

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="MeasDataCollection.xsl"?>
<measCollecFile xmlns="http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec">
	<measData>
		<managedElement localDn="foobar.example.com" />
		<measInfo measInfoId="metric_name">
			<job jobId="job_name" />
			<granPeriod duration="PT900S" endTime="2022-04-20T15:15:01+02:00" />
			<repPeriod duration="PT900S" />
			<measType p="1">field1</measType>
			<measType p="2">field2</measType>
			<measValue measObjLdn="identifier">
				<r p="1">31854</r>
				<r p="2">159773</r>
			</measValue>
		</measInfo>
	</measData>
</measCollecFile>

Anyway, for your schema, I would collect @localDn and measTypes as tags and measResults as string field, so telegraf can process them later with for example starlark processor for parsing the actual fields based on measTypes and measResults, and process the localdn with for example logfmt parser.

Hipska avatar May 04 '22 07:05 Hipska

@pratikdas44 please discuss this in the telegraf Slack channel or open an issue for telegraf.

srebhan avatar Jun 13 '22 12:06 srebhan