mmisp-lib 0.7.5__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/PKG-INFO +2 -2
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/pyproject.toml +1 -1
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/config.py +7 -2
- mmisp_lib-0.8.0/src/mmisp/db/lib.py +17 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/log.py +68 -33
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/workflow.py +31 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/logger.py +30 -1
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/workflows/execution.py +10 -21
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp_lib.egg-info/PKG-INFO +2 -2
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp_lib.egg-info/SOURCES.txt +1 -1
- mmisp_lib-0.7.5/src/mmisp/lib/logging.py +0 -58
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/LICENSE +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/README.md +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/setup.cfg +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/attributes.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/auth_keys.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/authentication.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/common.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/events.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/feeds.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/galaxies.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/galaxy_clusters.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/galaxy_common.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/jobs.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/logs.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/noticelists.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/objects.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/organisations.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/py.typed +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/responses/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/responses/check_graph_response.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/responses/standard_status_response.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/roles.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/server.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/servers.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/shadow_attribute.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/sharing_groups.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/sightings.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/statistics.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/tags.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/taxonomies.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/user_settings.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/users.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/warninglists.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/workflows.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/commandline_tool/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/commandline_tool/main.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/commandline_tool/organisation.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/commandline_tool/py.typed +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/commandline_tool/setup.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/commandline_tool/user.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/additional_properties.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/all_models.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/database.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/mixins.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/admin_setting.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/attribute.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/auth_key.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/blocklist.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/correlation.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/event.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/feed.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/galaxy.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/galaxy_cluster.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/identity_provider.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/noticelist.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/object.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/organisation.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/post.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/role.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/server.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/shadow_attribute.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/sharing_group.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/sighting.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/tag.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/taxonomy.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/threat_level.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/user.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/user_setting.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/warninglist.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/models/workflow_blueprint.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/mypy.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/print_changes.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/py.typed +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/db/uuid_type.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/actions.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/attribute_search_filter.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/attributes.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/distribution.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/fallbacks.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/galaxies.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/galaxy_clusters.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/permissions.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/py.typed +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/serialisation_helper.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/lib/uuid.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/enrichment/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/enrichment/data.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/enrichment/enrichment_plugin.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/exceptions.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/models/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/models/attribute.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/plugin_info.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/plugin_type.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/plugins/py.typed +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/compatibility_helpers.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/fixtures.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/attribute_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/feed_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/attribute_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/auth_key_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/correlation_exclusions_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/correlation_value_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/default_correlation_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/event_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/galaxy_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/identity_provider_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/noticelist_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/object_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/organisation_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/over_correlating_value_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/post_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/role_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/server_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/shadow_attribute_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/sharing_group_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/sighting_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/tag_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/taxonomy_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/user_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/user_setting_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/warninglist_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/workflow_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/object_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/sighting_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/tag_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/taxonomies_generator.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/util/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/util/crypto.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/util/models.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/util/partial.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/util/py.typed +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/util/uuid.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/workflows/__init__.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/workflows/fastapi.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/workflows/graph.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/workflows/input.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/workflows/legacy.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/workflows/misp_core_format.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/workflows/modules.py +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/workflows/py.typed +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp_lib.egg-info/dependency_links.txt +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp_lib.egg-info/entry_points.txt +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp_lib.egg-info/requires.txt +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp_lib.egg-info/top_level.txt +0 -0
- {mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/tests/test_commandline_tool.py +0 -0
@@ -22,6 +22,7 @@ class DatabaseConfig:
|
|
22
22
|
DEBUG: bool
|
23
23
|
RETRY_SLEEP: int
|
24
24
|
MAX_RETRIES: int
|
25
|
+
DB_LOGLEVEL: str | None = None
|
25
26
|
|
26
27
|
|
27
28
|
load_dotenv(getenv("ENV_FILE", ".env"))
|
@@ -32,8 +33,12 @@ config: DatabaseConfig = DatabaseConfig(
|
|
32
33
|
DEBUG=bool(getenv("DEBUG", False)),
|
33
34
|
RETRY_SLEEP=int(getenv("DB_RETRY", 5)),
|
34
35
|
MAX_RETRIES=int(getenv("DB_MAX_RETRIES", 100)),
|
36
|
+
DB_LOGLEVEL=getenv("DB_LOGLEVEL", None),
|
35
37
|
)
|
36
38
|
sqlalchemy_logger = logging.getLogger("sqlalchemy.engine")
|
37
|
-
sqlalchemy_logger.setLevel(logging.
|
39
|
+
sqlalchemy_logger.setLevel(logging.WARNING)
|
38
40
|
if config.DEBUG:
|
39
|
-
sqlalchemy_logger.setLevel(logging.
|
41
|
+
sqlalchemy_logger.setLevel(logging.INFO)
|
42
|
+
|
43
|
+
if config.DB_LOGLEVEL is not None:
|
44
|
+
sqlalchemy_logger.setLevel(config.DB_LOGLEVEL)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import logging
|
2
|
+
|
3
|
+
from sqlalchemy import func
|
4
|
+
from sqlalchemy.ext.asyncio import AsyncSession
|
5
|
+
from sqlalchemy.sql import Select
|
6
|
+
|
7
|
+
logger = logging.getLogger("mmisp")
|
8
|
+
|
9
|
+
|
10
|
+
async def get_count_from_select(db: AsyncSession, query: Select) -> int:
|
11
|
+
logger.debug("Get count from query: %s", query)
|
12
|
+
count_query = (
|
13
|
+
query.with_only_columns(func.count(), maintain_column_froms=True).order_by(None).limit(None).offset(None)
|
14
|
+
)
|
15
|
+
logger.debug("Resulted count query: %s", count_query)
|
16
|
+
result = await db.execute(count_query)
|
17
|
+
return result.scalar()
|
@@ -1,33 +1,68 @@
|
|
1
|
-
from datetime import datetime
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
1
|
+
from datetime import datetime
|
2
|
+
from typing import Self
|
3
|
+
|
4
|
+
from sqlalchemy import DateTime, Integer, String, Text
|
5
|
+
|
6
|
+
from mmisp.db.mypy import Mapped, mapped_column
|
7
|
+
|
8
|
+
from ..database import Base
|
9
|
+
|
10
|
+
|
11
|
+
class Log(Base):
|
12
|
+
"""
|
13
|
+
A python class representation of the database model for logs in MISP.
|
14
|
+
|
15
|
+
Further explanation for some of the central attributes of the database model:
|
16
|
+
- Action: Describes the action that was logged, e.g. a login or workflow execution
|
17
|
+
- Change: A string-representation of the changes made to the logged object or of
|
18
|
+
central information about the logged object.
|
19
|
+
"""
|
20
|
+
|
21
|
+
__tablename__ = "logs"
|
22
|
+
|
23
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True, nullable=False)
|
24
|
+
title: Mapped[str] = mapped_column(Text, nullable=True)
|
25
|
+
created: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow)
|
26
|
+
model: Mapped[str] = mapped_column(String(80), nullable=False)
|
27
|
+
model_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
28
|
+
action: Mapped[str] = mapped_column(String(20), nullable=False)
|
29
|
+
user_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
30
|
+
change: Mapped[str] = mapped_column(Text, nullable=True)
|
31
|
+
email: Mapped[str] = mapped_column(String(255), nullable=False)
|
32
|
+
org: Mapped[str] = mapped_column(String(255), nullable=False)
|
33
|
+
description: Mapped[str] = mapped_column(Text, nullable=True)
|
34
|
+
ip: Mapped[str] = mapped_column(String(45), nullable=True)
|
35
|
+
|
36
|
+
def __init__(
|
37
|
+
self: Self,
|
38
|
+
*,
|
39
|
+
model: str,
|
40
|
+
model_id: int,
|
41
|
+
action: str,
|
42
|
+
user_id: int,
|
43
|
+
email: str,
|
44
|
+
org: str,
|
45
|
+
title: str | None = None,
|
46
|
+
change: str | None = None,
|
47
|
+
description: str | None = None,
|
48
|
+
ip: str | None = None,
|
49
|
+
created: datetime | None = None,
|
50
|
+
**kwargs,
|
51
|
+
) -> None:
|
52
|
+
if created is None:
|
53
|
+
created = datetime.now()
|
54
|
+
if isinstance(created, float):
|
55
|
+
created = datetime.fromtimestamp(created)
|
56
|
+
super().__init__(
|
57
|
+
title=title,
|
58
|
+
created=created,
|
59
|
+
model=model,
|
60
|
+
model_id=model_id,
|
61
|
+
action=action,
|
62
|
+
user_id=user_id,
|
63
|
+
change=change,
|
64
|
+
email=email,
|
65
|
+
org=org,
|
66
|
+
description=description,
|
67
|
+
ip=ip,
|
68
|
+
)
|
@@ -1,3 +1,6 @@
|
|
1
|
+
import logging
|
2
|
+
from functools import cached_property
|
3
|
+
from typing import Self
|
1
4
|
from uuid import uuid4 as _uuid4
|
2
5
|
|
3
6
|
from sqlalchemy import Boolean, Integer, String
|
@@ -7,6 +10,7 @@ from mmisp.db.mypy import Mapped, mapped_column
|
|
7
10
|
from ...workflows.graph import WorkflowGraph
|
8
11
|
from ...workflows.legacy import JSONGraphType
|
9
12
|
from ..database import Base
|
13
|
+
from .log import Log
|
10
14
|
|
11
15
|
|
12
16
|
def uuid() -> str:
|
@@ -36,3 +40,30 @@ class Workflow(Base):
|
|
36
40
|
trigger_id: Mapped[str] = mapped_column(String(191), nullable=False, index=True)
|
37
41
|
debug_enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=0)
|
38
42
|
data: Mapped[WorkflowGraph] = mapped_column(JSONGraphType, nullable=False, default=0)
|
43
|
+
|
44
|
+
def __init__(self: Self, *args, **kwargs) -> None:
|
45
|
+
super().__init__(*args, **kwargs)
|
46
|
+
|
47
|
+
@cached_property
|
48
|
+
def _logger(self: Self) -> logging.LoggerAdapter:
|
49
|
+
_logger = logging.LoggerAdapter(
|
50
|
+
logging.getLogger(f"mmisp.workflows.{self.name}"),
|
51
|
+
extra=dict(
|
52
|
+
dbmodel=Log,
|
53
|
+
model="Workflow",
|
54
|
+
model_id=self.id,
|
55
|
+
action="execute_workflow",
|
56
|
+
user_id=0,
|
57
|
+
email="SYSTEM",
|
58
|
+
org="SYSTEM",
|
59
|
+
description="",
|
60
|
+
change="",
|
61
|
+
ip="",
|
62
|
+
),
|
63
|
+
)
|
64
|
+
if self.debug_enabled:
|
65
|
+
_logger.setLevel(logging.DEBUG)
|
66
|
+
return _logger
|
67
|
+
|
68
|
+
def get_logger(self: Self) -> logging.LoggerAdapter:
|
69
|
+
return self._logger
|
@@ -3,8 +3,10 @@ import logging
|
|
3
3
|
from contextvars import ContextVar
|
4
4
|
from typing import Self, TypeVar
|
5
5
|
|
6
|
+
from sqlalchemy.ext.asyncio import AsyncSession
|
7
|
+
|
6
8
|
request_log: ContextVar[list] = ContextVar("request_log")
|
7
|
-
|
9
|
+
db_log: ContextVar[list] = ContextVar("db_log")
|
8
10
|
|
9
11
|
|
10
12
|
T = TypeVar("T")
|
@@ -56,20 +58,47 @@ class InMemoryContextHandler(logging.Handler):
|
|
56
58
|
request_log.get([]).append(self.format(record))
|
57
59
|
|
58
60
|
|
61
|
+
class InMemoryDBLogContextHandler(logging.Handler):
|
62
|
+
def emit(self: Self, record: logging.LogRecord) -> None:
|
63
|
+
if hasattr(record, "dbmodel"):
|
64
|
+
dbmodel_class = getattr(record, "dbmodel")
|
65
|
+
instance = dbmodel_class(
|
66
|
+
title=self.format(record),
|
67
|
+
**record.__dict__,
|
68
|
+
)
|
69
|
+
db_log.get([]).append(instance)
|
70
|
+
|
71
|
+
|
59
72
|
def print_request_log() -> None:
|
60
73
|
print(*request_log.get([]), sep="\n")
|
61
74
|
|
62
75
|
|
76
|
+
async def save_db_log(db: AsyncSession) -> None:
|
77
|
+
db.add_all(db_log.get([]))
|
78
|
+
await db.flush()
|
79
|
+
|
80
|
+
|
63
81
|
def reset_request_log() -> None:
|
64
82
|
request_log.set([])
|
65
83
|
|
66
84
|
|
85
|
+
def reset_db_log() -> None:
|
86
|
+
db_log.set([])
|
87
|
+
|
88
|
+
|
67
89
|
# Set up the logger
|
68
90
|
logger = logging.getLogger("mmisp")
|
69
91
|
in_memory_handler = InMemoryContextHandler()
|
92
|
+
in_memory_db_log_handler = InMemoryDBLogContextHandler()
|
70
93
|
log_formatter = logging.Formatter("%(asctime)s %(levelname)s: %(message)s")
|
94
|
+
dblog_formatter = logging.Formatter("%(message)s")
|
71
95
|
in_memory_handler.setFormatter(log_formatter)
|
96
|
+
in_memory_db_log_handler.setFormatter(dblog_formatter)
|
72
97
|
logger.addHandler(in_memory_handler)
|
98
|
+
logger.addHandler(in_memory_db_log_handler)
|
99
|
+
|
100
|
+
# adapter
|
101
|
+
|
73
102
|
|
74
103
|
sqlalchemy_logger = logging.getLogger("sqlalchemy.engine")
|
75
104
|
sqlalchemy_logger.addHandler(in_memory_handler)
|
@@ -15,7 +15,6 @@ from ..db.models.organisation import Organisation
|
|
15
15
|
from ..db.models.role import Role
|
16
16
|
from ..db.models.user import User
|
17
17
|
from ..db.models.workflow import Workflow
|
18
|
-
from ..lib.logging import ApplicationLogger
|
19
18
|
from .graph import Module, Trigger, VerbatimWorkflowInput
|
20
19
|
from .input import WorkflowInput
|
21
20
|
from .modules import ModuleLogic
|
@@ -45,7 +44,6 @@ async def walk_nodes(
|
|
45
44
|
input: WorkflowInput,
|
46
45
|
current_node: Module,
|
47
46
|
workflow: Workflow,
|
48
|
-
logger: ApplicationLogger,
|
49
47
|
db: AsyncSession,
|
50
48
|
jinja2_engine: Environment,
|
51
49
|
) -> Tuple[bool, List[str]]:
|
@@ -59,8 +57,6 @@ async def walk_nodes(
|
|
59
57
|
input: Workflow payload for `current_node`.
|
60
58
|
current_node: Node to resume execution with.
|
61
59
|
workflow: Workflow entity. Used for logging.
|
62
|
-
logger: Application logger to write debug messages and errors
|
63
|
-
from the execution.
|
64
60
|
db: Database session.
|
65
61
|
jinja2_engine: Instantiated templating engine to substitute placeholders
|
66
62
|
in module configuration with values from the payload.
|
@@ -85,13 +81,12 @@ async def walk_nodes(
|
|
85
81
|
current_config[config_key] = [_render(v) for v in value]
|
86
82
|
result, next_node = await current_node.exec(input, db)
|
87
83
|
except Exception as e:
|
88
|
-
|
84
|
+
workflow.get_logger().error(f"Error while executing module {current_node.id}. Error: {e}")
|
89
85
|
return False, []
|
90
86
|
|
91
87
|
success_type = "partial-success" if not result and not isinstance(current_node, ModuleLogic) else "success"
|
92
88
|
|
93
|
-
|
94
|
-
workflow,
|
89
|
+
workflow.get_logger().debug(
|
95
90
|
f"Executed node `{current_node.id}`\n"
|
96
91
|
+ f"Node `{current_node.id}` from Workflow `{workflow.name}` ({workflow.id}) executed "
|
97
92
|
+ f"successfully with status: {success_type}",
|
@@ -105,7 +100,7 @@ async def walk_nodes(
|
|
105
100
|
|
106
101
|
# At this stage we don't do any cycle detection, but assume that only
|
107
102
|
# valid graphs w/o cycles in it were saved by the API.
|
108
|
-
return await walk_nodes(input, next_node, workflow,
|
103
|
+
return await walk_nodes(input, next_node, workflow, db, jinja2_engine)
|
109
104
|
|
110
105
|
|
111
106
|
async def create_virtual_root_user(db: AsyncSession) -> User:
|
@@ -141,7 +136,7 @@ async def workflow_by_trigger_id(trigger: str, db: AsyncSession) -> Workflow | N
|
|
141
136
|
|
142
137
|
|
143
138
|
async def execute_workflow(
|
144
|
-
workflow: Workflow, user: User, input: VerbatimWorkflowInput, db: AsyncSession
|
139
|
+
workflow: Workflow, user: User, input: VerbatimWorkflowInput, db: AsyncSession
|
145
140
|
) -> Tuple[bool, List[str]]:
|
146
141
|
"""
|
147
142
|
Provides the functionality for executing a workflow, which consists of traversing
|
@@ -169,7 +164,6 @@ async def execute_workflow(
|
|
169
164
|
workflow: The Graph representation of the workflow to be executed.
|
170
165
|
input: Initial payload for the workflow.
|
171
166
|
db: SQLAlchemy session.
|
172
|
-
logger: Application logger to notify about errors or (if debug is enabled) execution steps.
|
173
167
|
"""
|
174
168
|
|
175
169
|
if not workflow.enabled:
|
@@ -188,8 +182,7 @@ async def execute_workflow(
|
|
188
182
|
|
189
183
|
if len(unsupported_modules_id) != 0:
|
190
184
|
unsupported_modules_str = ", ".join(unsupported_modules_id)
|
191
|
-
|
192
|
-
workflow,
|
185
|
+
workflow.get_logger().error(
|
193
186
|
"Workflow was not executed, because it contained unsupported modules with the following IDs: "
|
194
187
|
+ unsupported_modules_str,
|
195
188
|
)
|
@@ -198,9 +191,7 @@ async def execute_workflow(
|
|
198
191
|
+ unsupported_modules_str
|
199
192
|
]
|
200
193
|
|
201
|
-
|
202
|
-
workflow, f"Started executing workflow for trigger `{trigger.name}` ({workflow.id})"
|
203
|
-
)
|
194
|
+
workflow.get_logger().debug(f"Started executing workflow for trigger `{trigger.name}` ({workflow.id})")
|
204
195
|
|
205
196
|
next_step = next(iter(trigger.outputs.values()), None)
|
206
197
|
# Nothing to do.
|
@@ -211,7 +202,7 @@ async def execute_workflow(
|
|
211
202
|
roaming_data = await trigger.normalize_data(db, input)
|
212
203
|
except Exception as e:
|
213
204
|
await db.rollback()
|
214
|
-
|
205
|
+
workflow.get_logger().error(f"Error while normalizing data for trigger. Error: \n{e}")
|
215
206
|
return False, [f"Internal error: {e}"]
|
216
207
|
|
217
208
|
input = WorkflowInput(
|
@@ -222,17 +213,15 @@ async def execute_workflow(
|
|
222
213
|
|
223
214
|
await _increase_workflow_execution_count(db, workflow.id)
|
224
215
|
|
225
|
-
result = await walk_nodes(
|
226
|
-
input, _as_module(next_step[0][1]), workflow, logger, db, Environment(loader=BaseLoader())
|
227
|
-
)
|
216
|
+
result = await walk_nodes(input, _as_module(next_step[0][1]), workflow, db, Environment(loader=BaseLoader()))
|
228
217
|
|
229
218
|
if result[0]:
|
230
219
|
outcome = "success"
|
231
220
|
else:
|
232
221
|
outcome = "blocked" if trigger.blocking else "failure"
|
233
222
|
|
234
|
-
|
235
|
-
|
223
|
+
workflow.get_logger().debug(
|
224
|
+
f"Finished executing workflow for trigger `{trigger.name}` ({workflow.id}). Outcome: {outcome}"
|
236
225
|
)
|
237
226
|
|
238
227
|
if not result[0]:
|
@@ -44,6 +44,7 @@ src/mmisp/db/additional_properties.py
|
|
44
44
|
src/mmisp/db/all_models.py
|
45
45
|
src/mmisp/db/config.py
|
46
46
|
src/mmisp/db/database.py
|
47
|
+
src/mmisp/db/lib.py
|
47
48
|
src/mmisp/db/mixins.py
|
48
49
|
src/mmisp/db/mypy.py
|
49
50
|
src/mmisp/db/print_changes.py
|
@@ -87,7 +88,6 @@ src/mmisp/lib/fallbacks.py
|
|
87
88
|
src/mmisp/lib/galaxies.py
|
88
89
|
src/mmisp/lib/galaxy_clusters.py
|
89
90
|
src/mmisp/lib/logger.py
|
90
|
-
src/mmisp/lib/logging.py
|
91
91
|
src/mmisp/lib/permissions.py
|
92
92
|
src/mmisp/lib/py.typed
|
93
93
|
src/mmisp/lib/serialisation_helper.py
|
@@ -1,58 +0,0 @@
|
|
1
|
-
from typing import Self
|
2
|
-
|
3
|
-
from sqlalchemy.ext.asyncio import AsyncSession
|
4
|
-
|
5
|
-
from ..db.models.log import Log
|
6
|
-
from ..db.models.workflow import Workflow
|
7
|
-
|
8
|
-
|
9
|
-
class ApplicationLogger:
|
10
|
-
db_session: AsyncSession
|
11
|
-
|
12
|
-
def __init__(self: Self, db_session: AsyncSession) -> None:
|
13
|
-
self.db_session = db_session
|
14
|
-
|
15
|
-
def log_workflow_debug_message(self: Self, workflow: Workflow, message: str) -> Log | None:
|
16
|
-
"""
|
17
|
-
If debugging is enabled, logs a message for the given workflow.
|
18
|
-
|
19
|
-
Arguments:
|
20
|
-
workflow: The workflow a log entry is created for.
|
21
|
-
message: The message to log.
|
22
|
-
"""
|
23
|
-
|
24
|
-
if workflow.debug_enabled:
|
25
|
-
log_entry = self.__create_workflow(workflow.id, message)
|
26
|
-
self.db_session.add(log_entry)
|
27
|
-
|
28
|
-
return log_entry
|
29
|
-
|
30
|
-
return None
|
31
|
-
|
32
|
-
def log_workflow_execution_error(self: Self, workflow: Workflow, message: str) -> Log:
|
33
|
-
"""
|
34
|
-
Logs a message in case of an error for the given workflow.
|
35
|
-
|
36
|
-
Arguments:
|
37
|
-
workflow: The workflow a log entry is created for.
|
38
|
-
message: The message to log.
|
39
|
-
"""
|
40
|
-
|
41
|
-
log_entry = self.__create_workflow(workflow.id, message)
|
42
|
-
self.db_session.add(log_entry)
|
43
|
-
|
44
|
-
return log_entry
|
45
|
-
|
46
|
-
def __create_workflow(self: Self, id: int, message: str) -> Workflow:
|
47
|
-
return Log(
|
48
|
-
title=message,
|
49
|
-
action="execute_workflow",
|
50
|
-
model="Workflow",
|
51
|
-
model_id=id,
|
52
|
-
user_id=0,
|
53
|
-
email="SYSTEM",
|
54
|
-
org="SYSTEM",
|
55
|
-
description="",
|
56
|
-
change="",
|
57
|
-
ip="",
|
58
|
-
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/api_schemas/responses/standard_status_response.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/event_generator.py
RENAMED
File without changes
|
{mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/galaxy_generator.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/object_generator.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/post_generator.py
RENAMED
File without changes
|
{mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/role_generator.py
RENAMED
File without changes
|
{mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/server_generator.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/tag_generator.py
RENAMED
File without changes
|
File without changes
|
{mmisp_lib-0.7.5 → mmisp_lib-0.8.0}/src/mmisp/tests/generators/model_generators/user_generator.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|