-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSearchAssets.py
52 lines (44 loc) · 2.15 KB
/
SearchAssets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Script to Search the assets in the CCS System
# For more details Refer the CCS REST API document at : https://apidocs.symantec.com/home/CCS
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Variable
# Replace the <hostname> with CCS application server host name
# Replace the <port number> with the configured port number for REST API, Default Port Number : 12431
# Replace the <user name> and <password> with valid CCS user name and password for example: UserName = domain1\\administrator, password = pass@123
HostName = '<hostname>'
PortNumber = '<port number>'
UserName = '<user name>'
Password = '<password>'
# Function to generate CCS REST API access token
def getToken():
urlToken = "https://" + HostName + ":" + PortNumber + "/ccs/api/v1/oauth/tokens"
payload = "grant_type=password&username=" + UserName + "&password=" + Password +""
headers = {'Content-Type': "application/json"}
responseToken = requests.request("POST", urlToken, data=payload, headers=headers, verify=False)
autheticationresult = responseToken.status_code
if (autheticationresult!=200) :
print("\nToken Generation Failed. Please check if the REST API is enabled and User name and password is correct\n")
exit()
tokenDict = responseToken.json()
token = tokenDict['access_token']
refreshToken = tokenDict['refresh_token']
print("bearer Token is:\n")
print(token)
print("\n Refresh Token is:\n")
print(refreshToken)
return token
url = "https://" + HostName + ":" + PortNumber + "/ccs/api/v1/Assets"
## Simple Search
#querystring = {"attributes":"displayname Contains 10.211.64"}
## Advanced Search
querystring = {"attributes":"(symc-csm-AssetSystem-Asset-unix-Machine-OSSystem Contains linux, displayname Contains 10.211.64)","ContainerPath":"asset system",
"searchsubtree":"false","page":"0","pagesize":"1"}
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
bearertoken = "Bearer " + getToken()
headers = {
'Authorization': bearertoken
}
response = requests.request("GET", url, headers=headers, params=querystring, verify=False)
assetsData = response.json()
print(response.text)