summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2023-12-02 16:41:52 +0100
committernicolargo <nicolas@nicolargo.com>2023-12-02 16:41:52 +0100
commit5fa7ae42641ca8e53d993d17d4b2b31eedf9563c (patch)
tree27b706d18d76fe866be28507c1b1e4d211359379
parent322d8c715aa749ad804ffc8e154a2c1e363fb9a8 (diff)
WARNING: Replace the get_raw command for processlist
-rw-r--r--Makefile2
-rw-r--r--glances/outputs/glances_restful_api.py13
-rw-r--r--glances/plugins/processlist/__init__.py9
-rwxr-xr-xunitest-restful.py4
4 files changed, 21 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index fd0cfae9..18c0958b 100644
--- a/Makefile
+++ b/Makefile
@@ -81,7 +81,7 @@ test-min-with-upgrade: venv-min-upgrade ## Upgrade deps and run unit tests in mi
./venv-min/bin/python ./unitest.py
test-restful-api: ## Run unit tests of the RESTful API
- ./venv-min/bin/python ./unitest-restful.py
+ ./venv/bin/python ./unitest-restful.py
# ===================================================================
# Linters and profilers
diff --git a/glances/outputs/glances_restful_api.py b/glances/outputs/glances_restful_api.py
index 06ab36f8..3c5ba284 100644
--- a/glances/outputs/glances_restful_api.py
+++ b/glances/outputs/glances_restful_api.py
@@ -84,15 +84,19 @@ class GlancesRestfulApi(object):
self.url_prefix)
# FastAPI Init
- self._app = FastAPI(dependencies=[Depends(self.authentication)])
+ if self.args.password:
+ self._app = FastAPI(dependencies=[Depends(self.authentication)])
+ else:
+ self._app = FastAPI()
+
+ # Change the default root path
if self.url_prefix != '/':
self._app.include_router(APIRouter(prefix=self.url_prefix))
# Set path for WebUI
- # self.STATIC_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/public')
- self.STATIC_PATH = 'static/public'
+ self.STATIC_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/public')
# TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/templates'))
- self.TEMPLATE_PATH = 'static/templates'
+ self.TEMPLATE_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/templates')
self._templates = Jinja2Templates(directory=self.TEMPLATE_PATH)
# FastAPI Enable CORS
@@ -133,6 +137,7 @@ class GlancesRestfulApi(object):
return self._app()
# TODO: the password comparaison is not working for the moment.
+ # if the password is wrong, authentication is working...
# Perahps because the password is hashed in the GlancesPassword class
# and the one given by creds.password is not hashed ?
def authentication(self, creds: Annotated[HTTPBasicCredentials, Depends(security)]):
diff --git a/glances/plugins/processlist/__init__.py b/glances/plugins/processlist/__init__.py
index ac6ade93..f643255c 100644
--- a/glances/plugins/processlist/__init__.py
+++ b/glances/plugins/processlist/__init__.py
@@ -135,6 +135,15 @@ class PluginModel(GlancesPluginModel):
"""Return the key of the list."""
return 'pid'
+ def get_raw(self):
+ """Overwrite the default get_raw methode in order to return dict in the values.
+ for example:
+ pmem(rss=6377472, vms=13946880, shared=4100096, text=913408, lib=0, data=2289664, dirty=0)
+ will be replaced by:
+ {'rss': 6377472, 'vms': 13946880, 'shared': 4100096, 'text': 913408, 'lib': 0, 'data': 2289664, 'dirty': 0}
+ """
+ return [{k: (v._asdict() if hasattr(v, '_asdict') else v) for k, v in p.items()} for p in self.stats]
+
def update(self):
"""Update processes stats using the input method."""
# Init new stats
diff --git a/unitest-restful.py b/unitest-restful.py
index 17e734e1..dd725f2c 100755
--- a/unitest-restful.py
+++ b/unitest-restful.py
@@ -54,12 +54,12 @@ class TestGlances(unittest.TestCase):
"""Start the Glances Web Server."""
global pid
- print('INFO: [TEST_000] Start the Glances Web Server')
+ print('INFO: [TEST_000] Start the Glances Web Server API')
if os.path.isfile('./venv/bin/python'):
cmdline = "./venv/bin/python"
else:
cmdline = "python"
- cmdline += " -m glances -B localhost -w -p %s" % SERVER_PORT
+ cmdline += " -m glances -B 0.0.0.0 -w -p %s --disable-webui" % SERVER_PORT
print("Run the Glances Web Server on port %s" % SERVER_PORT)
args = shlex.split(cmdline)
pid = subprocess.Popen(args)