Not a customer? Click the 'Start a free trial' link to begin a 30-day SaaS trial of our product and to join our community.
Existing Cisco AppDynamics customers should click the 'Sign In' button to authenticate to access the community
on
03-23-2017
10:24 AM
- edited on
03-20-2020
11:06 PM
by
Claudia.Landiva
I want to enable/disable synthetic jobs programmatically in order to automate the process during the planned downtimes so that false alerts are not generated.
For dealing with synthetic jobs, use the https://api.eum-appdynamics.com
endpoint to make changes to the schedule, and either enable or disable jobs.
To use this API, use your username and password for authentication. The username should be the EUM account name, and the password should be the EUM license key. These can be found on the licensing page in the controller UI by clicking on the gear menu in the upper right corner of the controller UI, clicking on license and then scrolling down to "End User Monitoring" as seen in the screenshot below.
GET https://api.eum-appdynamics.com/v1/synthetic/schedule
GET https://api.eum-appdynamics.com/v1/synthetic/schedule/<schedule_id>
PUT https://api.eum-appdynamics.com/v1/synthetic/schedule/<schedule_id>
curl -XGET --user AppDynamics-a0Q340ABCDEABCDEAV:9ba9bd3b-652d-abcd-abcd-abcdefecd4f0 https://api.eum-appdynamics.com/v1/synthetic/schedule
Output:
{
"_first": null,
"_items": [
{
"_id": "fcedd1d0-88bc-49c1-9bbe-397227616d1f",
"appKey": "AD-AAB-WWW-WWW",
"browserCodes": [
"Chrome"
],
"captureVisualMetrics": true,
"created": "2016-11-02T04:07:22.764Z",
.....
curl -XGET --user AppDynamics-a0Q340ABCDEABCDEAV:9ba9bd3b-652d-abcd-abcd-abcdefecd4f0 https://api.eum-appdynamics.com/v1/synthetic/schedule/fcedd1d0-88bc-49c1-9bbe-397227616d1f 2>/dev/null|python -m json.tool
{
"_id": "fcedd1d0-88bc-49c1-9bbe-397227616d1f",
.....
"userEnabled": false,
"version": 13
}
curl -XPUT --user AppDynamics-a0Q340ABCDEABCDEAV:9ba9bd3b-652d-abcd-abcd-abcdefecd4f0 -H"Content-Type: application/json" -d '{
"_id": "fcedd1d0-88bc-49c1-9bbe-397227616d1f",
.....
"userEnabled": true,
"version": 13
}' https://api.eum-appdynamics.com/v1/synthetic/schedule/fcedd1d0-88bc-49c1-9bbe-397227616d1f
Use the following Python implementation as a starting point to create your own script.
osxltmkshi:analytics-agent mayuresh.kshirsagar$ python ~/Desktop/synth.py --help
usage: synth.py [-h] -n <eum_account_name> -l <eum_license_name>
[-u <eum_url>] -j <synth_job_name> [-e]
optional arguments:
-h, --help show this help message and exit
-n <eum_account_name>, --eumaccountname <eum_account_name>
EUM Account Name
-l <eum_license_name>, --eumlicensekey <eum_license_name>
EUM License Key
-u <eum_url>, --url <eum_url>
EUM Server URL, Defaults to https://api.eum-
appdynamics.com
-j <synth_job_name>, --job <synth_job_name>
Job Name
-e, --enable Enable Job - If present marks the job enabled. If
absent, marks the job disabled
python ~/Desktop/synth.py -n AppDynamics-a0Q340ABCDEABCDEAV -l 9ba9bd3b-652d-abcd-abcd-abcdefecd4f0 -j 90220 -e
python ~/Desktop/synth.py -n AppDynamics-a0Q340ABCDEABCDEAV -l 9ba9bd3b-652d-abcd-abcd-abcdefecd4f0 -j 90220
Click "Learn More" to view the synth.py file
# -*- coding: utf-8 -*-
import requests
import argparse
import sys
import json
def find(list, filter):
for x in list:
if filter(x):
return x
return None
def main():
accountname=None
licensekey=None
url=None
jobname=None
enable=False
getallschedules="/v1/synthetic/schedule"
scheduleendpoint="/v1/synthetic/schedule/"
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--eumaccountname", help="EUM Account Name", required=True, metavar='<eum_account_name>')
parser.add_argument("-l", "--eumlicensekey", help="EUM License Key", required=True, metavar='<eum_license_name>')
parser.add_argument("-u", "--url", help="EUM Server URL, Defaults to https://api.eum-appdynamics.com", default="https://api.eum-appdynamics.com", required=False, metavar='<eum_url>')
parser.add_argument("-j", "--job", help="Job Name", required=True, metavar='<synth_job_name>')
parser.add_argument("-e", "--enable", help="Enable Job - If present marks the job enabled. If absent, marks the job disabled", default=False, action="store_true", required=False)
args = parser.parse_args()
accountname=args.eumaccountname
licensekey=args.eumlicensekey
url=args.url
jobname=args.job
enable=args.enable
# Get all the schedules
response = requests.get(url + getallschedules,auth=(accountname,licensekey))
if response.status_code != 200:
print "Error Occurred. Status Code: " + str(response.status_code) + " Response: " + json.dumps(json.loads(response.text),indent=3)
sys.exit(1)
_json = json.loads(response.text)
_items= _json['_items']
_return = find(_items, lambda x: x['description'] == jobname)
scheduleid=_return['_id']
# Get the individual schedule matching the description
response = requests.get(url + scheduleendpoint + scheduleid,auth=(accountname, licensekey))
if response.status_code != 200:
print "Error Occurred. Status Code: " + str(response.status_code) + " Response: " + json.dumps(json.loads(response.text),indent=3)
sys.exit(1)
_json = json.loads(response.text)
_json['userEnabled'] = enable
_json=json.dumps(_json, indent=3)
print "Request: " + _json
headers = {'Content-type': 'application/json'}
# Modify the schedule
response = requests.put(url + scheduleendpoint + scheduleid, auth=(accountname, licensekey), headers=headers, data=_json)
if response.status_code != 200:
print "Error Occurred. Status Code: " + str(response.status_code) + " Response: " + json.dumps(json.loads(response.text),indent=3)
sys.exit(1)
_json = json.loads(response.text)
_json=json.dumps(_json, indent=3)
print "Response: " + _json
if __name__ == "__main__":
main()
Hi Mayuresh,
Great article.
Unfortunately I could not see a link to download the synth.py file. Could you please help out.
Thanks,
Alakshya
Hi Alakshya,
That's strange, the script does not show up in the published article but it's there when I click edit. I'll check with the team about that.
Anyway, here is the script:
synth.py:
# -*- coding: utf-8 -*- import requests import argparse import sys import json def find(list, filter): for x in list: if filter(x): return x return None def main(): accountname=None licensekey=None url=None jobname=None enable=False getallschedules="/v1/synthetic/schedule" scheduleendpoint="/v1/synthetic/schedule/" parser = argparse.ArgumentParser() parser.add_argument("-n", "--eumaccountname", help="EUM Account Name", required=True, metavar='<eum_account_name>') parser.add_argument("-l", "--eumlicensekey", help="EUM License Key", required=True, metavar='<eum_license_name>') parser.add_argument("-u", "--url", help="EUM Server URL, Defaults to https://api.eum-appdynamics.com", default="https://api.eum-appdynamics.com", required=False, metavar='<eum_url>') parser.add_argument("-j", "--job", help="Job Name", required=True, metavar='<synth_job_name>') parser.add_argument("-e", "--enable", help="Enable Job - If present marks the job enabled. If absent, marks the job disabled", default=False, action="store_true", required=False) args = parser.parse_args() accountname=args.eumaccountname licensekey=args.eumlicensekey url=args.url jobname=args.job enable=args.enable # Get all the schedules response = requests.get(url + getallschedules,auth=(accountname,licensekey)) if response.status_code != 200: print "Error Occurred. Status Code: " + str(response.status_code) + " Response: " + json.dumps(json.loads(response.text),indent=3) sys.exit(1) _json = json.loads(response.text) _items= _json['_items'] _return = find(_items, lambda x: x['description'] == jobname) scheduleid=_return['_id'] # Get the individual schedule matching the description response = requests.get(url + scheduleendpoint + scheduleid,auth=(accountname, licensekey)) if response.status_code != 200: print "Error Occurred. Status Code: " + str(response.status_code) + " Response: " + json.dumps(json.loads(response.text),indent=3) sys.exit(1) _json = json.loads(response.text) _json['userEnabled'] = enable _json=json.dumps(_json, indent=3) print "Request: " + _json headers = {'Content-type': 'application/json'} # Modify the schedule response = requests.put(url + scheduleendpoint + scheduleid, auth=(accountname, licensekey), headers=headers, data=_json) if response.status_code != 200: print "Error Occurred. Status Code: " + str(response.status_code) + " Response: " + json.dumps(json.loads(response.text),indent=3) sys.exit(1) _json = json.loads(response.text) _json=json.dumps(_json, indent=3) print "Response: " + _json if __name__ == "__main__": main()
Hi Erin/Mayuresh,
Is there an option to delete jobs using rest call.
Thanks,
Alakshya
Got it. The below worked.
curl -XDELETE -x <http proxy>:<proxy port> --user <EumAccountName>:<EUMKey> https://api.eumappdynamics.com/v1/synthetic/schedule/<id>
Hi Mayuresh/Erin,
Is there an API to create synthetic job for older version of appdynamics.
And what parameters are required in that API to create the job successfully?
Latest appdynamics version does have a create api.
Hi, @Hiten.Bhatia
Can you tell us more about how much older the version range of AppDynamics you're interested in?
Claudia
Community Manager & Editor
Thank you! Your submission has been received!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form