Commit 7c1c04d6 authored by Agustin Pane's avatar Agustin Pane
Browse files

(Release) V2.2.7

parent daad6a79
......@@ -4,7 +4,7 @@ from setuptools import setup
setup(
name='svmon_python_client',
version='2.2.6',
version='2.2.7',
packages=['svmon_client'],
scripts=['svmon'],
package_data={'' : ['*.json','*.pem']},
......
......@@ -5,6 +5,7 @@ import os
import json
import subprocess
import sys
import logging
from . import services
from . import json_operations
from svmon_client import remoteConfig
......@@ -323,7 +324,7 @@ class SVMONReport:
import requests as re
print('Sending report to svmon server...')
cwd = os.path.dirname(services.__file__)
mytoken = ""
apiToken = ""
filename = os.environ.get('TOKEN_PATH', cwd + "/token.json")
if os.path.exists(filename) == False:
print("You have no token configured, please go to svmon.eudat.eu webpage to create a token and configure it")
......@@ -335,23 +336,25 @@ class SVMONReport:
with open(filename, 'r') as f:
load_dict = json.load(f)
if 'token' in load_dict and load_dict.get('token') != '':
mytoken = load_dict.get('token')
apiToken = load_dict.get('token')
else:
print("Please configure api token")
exit(1)
url = self.config['BACKEND_URL']
print("BACKEND_URL", url)
enableDebug = self.config['DEBUG_MODE']
if(enableDebug):
print("BACKEND_URL :" + url)
headers = {}
headers['Content-Type'] = 'application/json'
headers['Authorization'] = 'Bearer ' + mytoken
headers['Authorization'] = 'Bearer ' + apiToken
cert = os.environ.get('CERTIFICATE_PATH', cwd + "/chain_TERENA_SSL_CA_3.pem")
if(not len(self.service_names)):
print('No services available, sending report failed')
exit(1)
enableDebug = self.config['DEBUG_MODE']
postErrors = 0
for i in range(len(self.service_names)):
res = {}
......@@ -362,9 +365,15 @@ class SVMONReport:
res['serviceComponentName']=self.service_names[i]
res['tagAtSite']=self.tags[i]
if(enableDebug):
print('Going to send report: ', res, ' to endpoint: ',url)
print('Going to send report: ',res,' to endpoint: ' + url)
print('Certificate path: ', cert)
try:
if(enableDebug):
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
r = re.post(url, data=json.dumps(res), headers=headers, verify=cert)
#r = re.post(url, headers=headers, data=json.dumps(res), verify=False)
print('Request to svmon server finished with status code:', r.status_code)
......@@ -375,6 +384,10 @@ class SVMONReport:
print('Service ', self.service_type,' does not exists, please check the svmon config')
postErrors +=1
continue
if(r.status_code == 400):
print(r.json())
postErrors +=1
continue
if (r.status_code != 201 and r.status_code != 200):
print('Sending report failed, please check your configuration')
exit(1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment