cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Example of How to Use Python with SVR/Research API to Create Watchlists.

Example of How to Use Python with SVR/Research API to Create Watchlists.

Summary:

Example of How to Use Python with SVR/Research API to Create Watchlists.

 

Description:

You may run python from RHEL. Here are some steps to install Python on RHEL.

1. Install the pip from SCL as root

# subscription-manager repos --enable rhel-server-rhscl-7-rpms

# yum install python27-python-pip

2. Switch to a normal user and check the pip

# scl enable python27 bash

# which pip

# pip -V

3. Install requests modules with pip and run .py script

# pip install requests

# python YOUR_PYTHON_SCRIPT_NAME.py

Example Code:

import requests
import json

session = requests.Session()
session.headers.update({'Authorization': 'Token TOKENVALUEHERE', 'Content-Type': 'application/json',
'Accept': 'application/json', 'Host': 'app.flexerasoftware.com', 'Accept-Encoding': 'gzip, deflate'})

#Create Watchlist - Uncommment below to Create.
# response = session.post('https://app.flexerasoftware.com/api/asset-lists/', json={'enabled': True,'receive_all':False,'products':[],'vendors':[],'advisories_need_approval':False,'ticket_threshold_level':6,'notification_level_email':6,'notification_level_sms':1,'ignored':[],'selected':[],'custom_cr': None, 'custom_ir': None,'custom_ar': None,'product_releases':[60497],'name':'TEST2','group': None})

# print(response)
# print (json.dumps(response.json(), indent=4, sort_keys=True))

#Modify Watchlist - REPLACE 14 in both URL and payload with the Watchlist ID to update. Modify the json payload with changes to be made.
response = session.put('https://app.flexerasoftware.com/api/asset-lists/14/', json={"id":14,"enabled":True,"receive_all":False,"products":[],"vendors":[],"advisories_need_approval":False,"ticket_threshold_level":6,"notification_level_email":6,"notification_level_sms":1,"custom_cr":None,"custom_ir":None,"custom_ar":None,"host_group_id":None,"product_releases":[60497,46340],"group":1,"name":"TEST6"})

print(response)
print (json.dumps(response.json(), indent=4, sort_keys=True))

 

#Delete Watchlist - Uncomment below and REPLACE 16 in both URL and payload with the Watchlist ID to delete.
# response = session.delete('https://app.flexerasoftware.com/api/asset-lists/16/', json={"id":16})
print(response)

 

Additional Info:

https://access.redhat.com/solutions/1519803

Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Mar 09, 2021 02:37 PM
Updated by:
Contributors