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
f33a7dc7
Commit
f33a7dc7
authored
Oct 02, 2019
by
Jie Yuan
Browse files
add token to send report bypassing pakiti-client
parent
f0d38256
Changes
2
Hide whitespace changes
Inline
Side-by-side
svmon
View file @
f33a7dc7
...
...
@@ -15,7 +15,7 @@ def main(argv):
try
:
opts
,
args
=
getopt
.
getopt
(
argv
,
'h:t:S:THVpd:'
,[
'help'
,
'version'
,
'site='
,
'test'
,
\
'host='
,
'tag='
,
'print'
,
'dump'
,
'type='
,
'list-service-type'
,
'show-config'
,
'send'
,
\
'handle-server-path='
,
'with-version='
,
'component='
])
'handle-server-path='
,
'with-version='
,
'component='
,
'token='
])
except
getopt
.
GetoptError
:
print
(
help_info
())
sys
.
exit
(
0
)
...
...
@@ -33,6 +33,7 @@ def main(argv):
no_specified_components
=
0
specified_versions
=
[]
no_specified_versions
=
0
token
=
""
for
opt
,
arg
in
opts
:
# print opt,arg
if
opt
in
[
'-H'
,
'--help'
]:
...
...
@@ -93,6 +94,9 @@ def main(argv):
if
opt
in
[
'--handle-server-path'
]:
handle_server_path
=
arg
if
opt
in
[
'--token'
]:
token
=
arg
if
no_specified_versions
!=
no_specified_components
:
...
...
@@ -109,6 +113,8 @@ def main(argv):
svmonreport
.
save_b2handle_config_to_json
(
handle_server_path
=
handle_server_path
)
if
no_specified_components
>
0
:
svmonreport
.
save_with_components_to_json
(
specified_components
,
specified_versions
)
if
token
!=
""
:
svmonreport
.
save_token
(
token
)
...
...
@@ -160,6 +166,8 @@ def help_info():
--show-config Show the site,host, service type configurations.
--send Send the reports to SVMON server.
--handle-server-path Locate the directory where handle is installed when service type is "b2handle".
--token Add API token to post report to svmon.eudat.eu bypassing pakiti-client.
To get a token, one could go to the webpage; in the profile dialog, then create.
If you have problems with SVMON client usage, please contact us(jie.yuan@kit.edu).
...
...
svmon_client/report.py
View file @
f33a7dc7
...
...
@@ -305,10 +305,29 @@ class SVMONReport:
def
send_report_to_svmon_server
(
self
):
import
requests
as
re
url
=
'https://svmon.eudat.eu:8443/api/serviceComponent/jsonreport'
cwd
=
os
.
path
.
dirname
(
services
.
__file__
)
mytoken
=
""
filename
=
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"
)
exit
(
-
1
)
readok
=
os
.
access
(
filename
,
os
.
R_OK
)
if
readok
==
False
:
print
(
"You have no access to read config file: token.json"
)
exit
(
-
1
)
with
open
(
filename
,
'r'
)
as
f
:
load_dict
=
json
.
load
(
f
)
if
load_dict
.
has_key
(
'token'
)
and
load_dict
.
get
(
'token'
)
!=
''
:
mytoken
=
load_dict
.
get
(
'token'
)
url
=
'https://svmon-dev-test.scc.kit.edu:8443/api/serviceComponent/jsonreport'
headers
=
{}
headers
[
'Content-Type'
]
=
'application/json'
cwd
=
os
.
path
.
dirname
(
services
.
__file__
)
headers
[
'Authorization'
]
=
'Bearer '
+
mytoken
certs
=
cwd
+
"/chain_TERENA_SSL_CA_3.pem"
for
i
in
range
(
len
(
self
.
service_names
)):
res
=
{}
...
...
@@ -318,7 +337,7 @@ class SVMONReport:
res
[
'serviceType'
]
=
self
.
service_type
res
[
'serviceComponentName'
]
=
self
.
service_names
[
i
]
res
[
'tagAtSite'
]
=
self
.
tags
[
i
]
r
=
re
.
post
(
url
,
headers
=
headers
,
data
=
json
.
dumps
(
res
),
verify
=
certs
)
r
=
re
.
post
(
url
,
headers
=
headers
,
data
=
json
.
dumps
(
res
),
verify
=
False
)
if
(
r
.
status_code
!=
201
):
print
(
'Sending report failed, please check your configuration'
)
exit
(
1
)
...
...
@@ -326,6 +345,28 @@ class SVMONReport:
exit
(
0
)
def
save_token
(
self
,
token
):
if
token
==
""
:
print
(
"No token to be saved"
)
exit
(
0
)
cwd
=
os
.
path
.
dirname
(
services
.
__file__
)
filename
=
cwd
+
"/token.json"
res
=
{}
res
[
'token'
]
=
token
if
os
.
path
.
exists
(
filename
)
==
False
:
f
=
open
(
filename
,
'w'
)
f
.
close
()
writeok
=
os
.
access
(
filename
,
os
.
W_OK
)
if
writeok
==
False
:
print
(
"You have no access to write config file: token.json"
)
exit
(
-
1
)
success
=
json_operations
.
save_to_file
(
filename
,
res
)
if
success
==
False
:
print
(
"Save token data to json failed"
)
exit
(
1
)
if
__name__
==
"__main__"
:
re
=
SVMONReport
()
...
...
Write
Preview
Supports
Markdown
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