chg: event_list - enable data validation only if pydantic available

This commit is contained in:
Bharath Vignesh J K 2024-05-16 16:58:25 +05:30
parent 05bc1449db
commit 98f2bb7fbe
4 changed files with 10 additions and 4 deletions

View File

@ -32,7 +32,13 @@ Item (or event) is defined by:
}
"""
from pydantic.dataclasses import dataclass
from glances.logger import logger
try:
from pydantic.dataclasses import dataclass
except ImportError as e:
logger.warning(f"Missing Python Lib ({e}), EventList will be skipping data validation")
from dataclasses import dataclass
from glances.processes import sort_stats

View File

@ -11,7 +11,7 @@
import time
from datetime import datetime
from pydantic import RootModel
from dataclasses import asdict
from glances.processes import glances_processes
from glances.thresholds import glances_thresholds
@ -201,7 +201,7 @@ class GlancesEventsList(object):
def get(self):
"""Return the RAW events list."""
return [RootModel[GlancesEvent](e).model_dump() for e in self.events_list]
return [asdict(e) for e in self.events_list]
def len(self):
"""Return the number of events in the logs list."""

View File

@ -22,6 +22,7 @@ podman; python_version >= "3.6"
potsdb
prometheus_client
pycouchdb
pydantic
pygal
pymdstat
pymongo; python_version >= "3.7"

View File

@ -2,4 +2,3 @@ psutil>=5.6.7
defusedxml
packaging
ujson>=5.4.0
pydantic>=2.0.0