Splunk AppDynamics

Escaping control codes in HTTP Request Templates

Douglas_McGibbo
New Member

Hi.

I'm trying to pass Appdynamics error data to Opsgenie using the HTTP Request Templates to format it in JSON.

My simplest template is :

{
"event_name": "${latestEvent.displayName}",
"event_Message":"${latestEvent.eventMessage}",
}

But this is erroring at Opsgenie because there's a Line Feed in the event message :

The content is not a valid json. Reason: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value at [Source: (String)"{ "event_name": "Business Transaction Error", "event_Message":"

Is there an easy way to escape/replace this in the template?

Thanks

Doug McGibbon

Labels (3)
0 Karma

iamryan
Community Manager
Community Manager

Hi @Douglas.McGibbon,

An existing Community post, Escaped double quotes in HTTP template links to this reference guide: https://velocity.apache.org/tools/2.0/apidocs/org/apache/velocity/tools/generic/EscapeTool.html

Please do let me know if you find the post or the reference guide helpful. Since this is a peer-to-peer community, if you happen to find a solution, please come back and share it as a reply to your post. This helps keep the knowledge sharing going forward.

0 Karma

Douglas_McGibbo
New Member

Yes, I found that post and the guide, but it's not at all clear. And replacing one character with another is much easier than trying to get rid of a control character.  I've already spent several hours trying to do this in various ways, to no avail.

0 Karma

Morelz
Motivator

Hi There

We have done the following in one of our templates, to ensure that the Quotes and line breaks etc. are replaced by other characters. We used *. You can modify and replace it with whatever you require.

You can then add as many processing steps as needed at the start of the template, and then use the final processed message that is left over into your template.

#set ($em = ${latestEvent.eventMessage.replace('"','*')})
#set ( $em = $em.replace('<b>', '*') )
#set ( $em = $em.replace('</b>', '*') )
#set ( $em = $em.replace('<br>', ' ') )


{
"event_name": "${latestEvent.displayName}",
"event_Message":"$em",
}

Otherwise you can remove the values completed as below

#set ($em = ${latestEvent.eventMessage.replace('"','')})
#set ( $em = $em.replace('<b>', '') )
#set ( $em = $em.replace('</b>', '') )
#set ( $em = $em.replace('<br>', '') )


{
"event_name": "${latestEvent.displayName}",
"event_Message":"$em",
}

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...