Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
EUDAT-TOOLS
SVMON
pysvmon
Commits
bda5835e
Commit
bda5835e
authored
Aug 17, 2021
by
Agustin Pane
Browse files
Merge branch 'development' into 'master'
(Release) V2.2.7 See merge request
!15
parents
daad6a79
7c1c04d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
setup.py
View file @
bda5835e
...
...
@@ -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'
]},
...
...
svmon_client/report.py
View file @
bda5835e
...
...
@@ -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__
)
myt
oken
=
""
apiT
oken
=
""
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'
)
!=
''
:
myt
oken
=
load_dict
.
get
(
'token'
)
apiT
oken
=
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 '
+
myt
oken
headers
[
'Authorization'
]
=
'Bearer '
+
apiT
oken
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment