Hello,
I need to run scripts using the REST API for adding hostgroups but I can't do that because it returns an HTTP 500 error when I run the python script.
The script is the following:
Questa e' la funzione che uso per il token di autenticazione e riesco tranquillamente a farlo.
def getAccessToken():
'''Get REST API Token'''
url = "https://" + SW_SMC_ADDRESS + "/token/v2/authenticate"
print('Stealthwatch login URL: ' + url)
login_credentials = {
"username": SW_USERNAME,
"password": SW_PASSWORD
}
try:
response = API_SESSION.post(url, data=login_credentials, verify=False)
if response.status_code == 200:
print('Successfully Authenticated.')
return response.text
else:
print('SMC Connection Failure - HTTP Return Code: {}\nResponse: {}'.format(response.status_code, response.text))
exit()
except Exception as err:
print('Unable to post to the SMC - Error: {}'.format(err))
exit()
Mentre questa e' la funzione che utso per fare l'aggiunta dell'hostgroup ma mi restituisce un errore HTTP 500:
def addHostGroup():
url = 'https://{}/smc-configuration/rest/v1/tenants/{}/tags'.format(SW_SMC_ADDRESS, SW_DOMAIN_ID)
hostg = {"name": "Test1","location": "INSIDE","description": "Test1","ranges": ["10.10.10.10/32"],"hostBaselines": "false","suppressExcludedServices": "true","inverseSuppression": "false","hostTrap": "false","sendToCta": "false","parentId": 1}
try:
response = API_SESSION.post(url, data=hostg, verify=False)
if response.status_code == 200:
print('Success')
return response.text
else:
print('Failure - HTTP Return Code: {}\nResponse: {}'.format(response.status_code, response.text))
exit()
except Exception as err:
print('Unable to post to the SMC - Error: {}'.format(err))
exit()
I noticed that when I connect to the https: // <smc ip> /smc/restapi-docs/index.html page the error in the image is returned.
how can i solve?
thank you
regards