Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eduGAIN Connectivity Check
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
edugain
eduGAIN Connectivity Check
Commits
c0434945
Commit
c0434945
authored
4 years ago
by
Marco Malavolti
Browse files
Options
Downloads
Patches
Plain Diff
Added ECCS2 FedStats API
parent
b8db0d6f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api.py
+76
-7
76 additions, 7 deletions
api.py
with
76 additions
and
7 deletions
api.py
+
76
−
7
View file @
c0434945
...
...
@@ -4,11 +4,12 @@ import json
import
logging
import
re
from
eccs2properties
import
DAY
,
ECCS2LOGSDIR
,
ECCS2OUTPUTDIR
#from flask.logging import default_handler
from
eccs2properties
import
DAY
,
ECCS2LOGSDIR
,
ECCS2OUTPUTDIR
,
ECCS2LISTFEDSURL
,
ECCS2LISTFEDSFILE
from
flask
import
Flask
,
request
,
jsonify
from
flask_restful
import
Resource
,
Api
from
utils
import
getLogger
from
utils
import
getLogger
,
getListFeds
,
getRegAuthDict
#from eccs2properties import ECCS2FAILEDCMD, ECCS2FAILEDCMDIDP, ECCS2STDOUT, ECCS2STDERR, ECCS2STDOUTIDP, ECCS2STDERRIDP, ECCS2DIR, ECCS2NUMPROCESSES, ECCS2LISTIDPSURL, ECCS2LISTIDPSFILE, ECCS2LISTFEDSURL, ECCS2LISTFEDSFILE
app
=
Flask
(
__name__
)
api
=
Api
(
app
)
...
...
@@ -35,7 +36,7 @@ def existsInFile(file_path, value, research_item, eccsDataTable):
if
(
eccsDataTable
):
return
''
else
:
return
jsonify
(
error
=
'
FileNotFound: ECCS2 script has not been executed
for
this day
'
)
return
jsonify
(
error
=
'
FileNotFound: ECCS2 script has not been executed
on
this day
'
)
for
line
in
lines
:
aux
=
json
.
loads
(
line
)
...
...
@@ -62,7 +63,6 @@ class EccsResults(Resource):
file_path
=
"
%s/eccs2_%s.log
"
%
(
ECCS2OUTPUTDIR
,
DAY
)
date
=
DAY
pretty
=
0
status
=
None
idp
=
None
reg_auth
=
None
...
...
@@ -96,7 +96,7 @@ class EccsResults(Resource):
if
(
eccsDataTable
):
return
''
else
:
return
jsonify
(
error
=
'
FileNotFound: ECCS2 script has not been executed
for
this day
'
)
return
jsonify
(
error
=
'
FileNotFound: ECCS2 script has not been executed
on
this day
'
)
for
line
in
lines
:
# Strip the line feed and carriage return characters
...
...
@@ -139,7 +139,76 @@ class EccsResults(Resource):
# /eccs2/api/fedstats
class
FedStats
(
Resource
):
def
get
(
self
):
return
{
'
fedstats
'
:
'
It Works!
'
}
list_feds
=
getListFeds
(
ECCS2LISTFEDSURL
,
ECCS2LISTFEDSFILE
)
regAuthDict
=
getRegAuthDict
(
list_feds
)
file_path
=
"
%s/eccs2_%s.log
"
%
(
ECCS2OUTPUTDIR
,
DAY
)
date
=
DAY
reg_auth
=
None
eccsDataTable
=
False
if
(
'
date
'
in
request
.
args
):
date
=
request
.
args
[
'
date
'
]
file_path
=
"
%s/eccs2_%s.log
"
%
(
ECCS2OUTPUTDIR
,
date
)
if
(
'
reg_auth
'
in
request
.
args
):
reg_auth
=
request
.
args
[
'
reg_auth
'
]
if
(
not
existsInFile
(
file_path
,
reg_auth
,
"
registrationAuthority
"
,
eccsDataTable
)):
return
jsonify
(
error
=
"
Registration Authority not found
"
)
lines
=
[]
results
=
[]
try
:
with
open
(
file_path
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
fo
:
lines
=
fo
.
readlines
()
except
FileNotFoundError
as
e
:
if
(
eccsDataTable
):
return
''
else
:
return
jsonify
(
error
=
'
FileNotFound: ECCS2 script has not been executed on this day
'
)
if
(
reg_auth
):
resultDict
=
{
'
date
'
:
date
,
'
registrationAuthority
'
:
reg_auth
,
'
OK
'
:
0
,
'
ERROR
'
:
0
,
'
DISABLED
'
:
0
}
for
line
in
lines
:
# Strip the line feed and carriage return characters
line
=
line
.
rstrip
(
"
\n\r
"
)
# Loads the json line into aux
aux
=
json
.
loads
(
line
)
if
(
aux
[
'
registrationAuthority
'
]
==
reg_auth
):
if
(
aux
[
'
status
'
]
==
"
OK
"
):
resultDict
[
'
OK
'
]
=
resultDict
[
'
OK
'
]
+
1
if
(
aux
[
'
status
'
]
==
"
ERROR
"
):
resultDict
[
'
ERROR
'
]
=
resultDict
[
'
ERROR
'
]
+
1
if
(
aux
[
'
status
'
]
==
"
DISABLED
"
):
resultDict
[
'
DISABLED
'
]
=
resultDict
[
'
DISABLED
'
]
+
1
results
.
append
(
resultDict
)
return
jsonify
(
results
)
else
:
for
name
,
regAuth
in
regAuthDict
.
items
():
resultDict
=
{
'
date
'
:
date
,
'
registrationAuthority
'
:
regAuth
,
'
OK
'
:
0
,
'
ERROR
'
:
0
,
'
DISABLED
'
:
0
}
for
line
in
lines
:
# Strip the line feed and carriage return characters
line
=
line
.
rstrip
(
"
\n\r
"
)
# Loads the json line into aux
aux
=
json
.
loads
(
line
)
if
(
regAuth
==
aux
[
'
registrationAuthority
'
]):
if
(
aux
[
'
status
'
]
==
"
OK
"
):
resultDict
[
'
OK
'
]
=
resultDict
[
'
OK
'
]
+
1
if
(
aux
[
'
status
'
]
==
"
ERROR
"
):
resultDict
[
'
ERROR
'
]
=
resultDict
[
'
ERROR
'
]
+
1
if
(
aux
[
'
status
'
]
==
"
DISABLED
"
):
resultDict
[
'
DISABLED
'
]
=
resultDict
[
'
DISABLED
'
]
+
1
results
.
append
(
resultDict
)
return
jsonify
(
results
)
# Routes
api
.
add_resource
(
Test
,
'
/test
'
)
# Route_1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment