Splunk AppDynamics

How do I trigger an HTTP POST via the AppDynamics Synthetic jobs?

CommunityUser
Splunk Employee
Splunk Employee

Hi,

1: How do I trigger an HTTP POST via the AppDynamics Synthetic jobs? I think I have to write a script; is there any example I can use? 

2: https://docs.appdynamics.com/display/PRO44/Synthetic+Scripts  suggests I can use 'Python requests for humans' but doesn't give any examples. Where can I find a working example? 

Labels (3)
0 Karma

CommunityUser
Splunk Employee
Splunk Employee

Has anyone managed to get a POST Request through AppD Synthetics to work ? I've tried contacting AppD support but it hasn't yeilded any positive results.

0 Karma

Plinio_Moreira
Engager

Hi Terence, i had the same problem, I needed to call an API to get a token parameter, and use these token to call another API. For this i used the script below:

# importing the requests library
import requests
import json

# String used to validate the success of the call
stringVerificacao = "CDXM084E"
url = 'https://<api1>:8443/auth/oauth/v2/token'
headers = {'Content-Type':'application/x-www-form-urlencoded'}

# POST parameters

data = {'grant_type':'client_credentials',
'client_id': 'xxxxxxx',
'client_secret':'xxxxxxxxxx',
'scope': 'teste',}


#Execute the first POST request
res = requests.post(url, data=data, headers=headers, verify=False)

#Extract the token from the json response 
retornoPOST = res.text
print("Retorno da API " + str(url) + ": \n %s" % retornoPOST)
json_object = json.loads(retornoPOST)
token = json_object['access_token']
#print json_object['access_token']


url2 = 'https://<api2>:8443/v1/xxxxxx'
headers2 = {'Content-Type':'application/json','Authorization':+ token}
data2 = '{'grant_type':'client_credentials',
'client_id': 'xxxxxxx',
'client_secret':'xxxxxxxxxx',
'scope': 'teste',}'

#Execute the second POST request

res2 = requests.post(url2, data=data2, headers=headers2, verify=False)

# extracting response text
retornoPOST2 = res2.text
print("Retorno da API " + str(url) + ": \n %s" % retornoPOST2)
json_object2 = json.loads(retornoPOST2)
codigoerro = json_object2['CodigoErro']

#Compare if the response contains the validate string

# If contains the response, print the values

if codigoerro == stringVerificacao:
print("String de validação '" + str(codigoerro) + "' econtrada com sucesso")
print(retornoPOST2)

# Else, raise a Exception to the script to be mark as error in appdynamics
elif codigoerro != stringVerificacao:
raise Exception("Código '" + str(stringVerificacao) + "' não encontrado no retorno da API: \n %s" % retornoPOST2)

I hope this helps!

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...