cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Mayuresh.Kshirsagar
AppDynamics Team (Retired)

Problem 

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.

 

Solution

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. 

 

Screen Shot 2017-03-22 at 5.13.15 PM.png

 

The APIs below can be used to get and modify the schedules:  

  1. Get a list of all the synthetic jobs available for the authenticated user:
    GET https://api.eum-appdynamics.com/v1/synthetic/schedule
  2.  Get the exact job identified by the schedule ID. To find the schedule ID and description, use the previous request to get a list of all jobs:
    GET https://api.eum-appdynamics.com/v1/synthetic/schedule/<schedule_id>

     

  3. Modify the schedule according to the new schedule object provided in the body:
    PUT https://api.eum-appdynamics.com/v1/synthetic/schedule/<schedule_id>​

    Use the response body from the previous request to get the exact job using the schedule ID as the JSON body. The field "userEnabled" controls whether the job is enabled or disabled, and will show the same result as enabling/disabling from the UI.

 

Sample curl implementation

 

Get all schedules

 

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",
.....

 

 

Get a particular schedule

 

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
}

 

 

Modify the given schedule

 

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

 

 

Create your own script

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

 

 

Enable a particular job

 

python ~/Desktop/synth.py -n AppDynamics-a0Q340ABCDEABCDEAV -l 9ba9bd3b-652d-abcd-abcd-abcdefecd4f0 -j 90220 -e

 

 

Disable a particular job

 

python ~/Desktop/synth.py -n AppDynamics-a0Q340ABCDEABCDEAV -l 9ba9bd3b-652d-abcd-abcd-abcdefecd4f0 -j 90220

 

 

synth.py

Click "Learn More" to view the  synth.py file

Spoiler
# -*- 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()

 

Related Links

Comments
alakshya.maheria
Discoverer

Hi Mayuresh,

 

Great article.

Unfortunately I could not see a link to download the synth.py file. Could you please help out.

 

Thanks,

Alakshya

Erin
AppDynamics Team (Retired)

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()

 

alakshya.maheria
Discoverer
Thanks Erin. Regards, Alakshya
alakshya.maheria
Discoverer

Hi Erin/Mayuresh,

 

Is there an option to delete jobs using rest call.

 

Thanks,

Alakshya

alakshya.maheria
Discoverer

Got it. The below worked.

curl -XDELETE -x <http proxy>:<proxy port> --user <EumAccountName>:<EUMKey> https://api.eumappdynamics.com/v1/synthetic/schedule/<id>

Hiten.Bhatia
Maker

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.

 

 

Claudia.Landivar
AppDynamics Team (Retired)

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

Hiten.Bhatia
Maker

Hi @Claudia.Landivar ,

Our appdynamics onpremise setup is 21.4.7 version (controller)

 

Version history
Last update:
‎03-20-2020 11:06 PM
Updated by:
On-Demand Webinar
Discover new Splunk integrations and AI innovations for Cisco AppDynamics.


Register Now!

Observe and Explore
Dive into our Community Blog for the Latest Insights and Updates!


Read the blog here