-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
defmodule Trento.ActivityLog.Logger.Parser.MetadataEnricher do | ||
@moduledoc """ | ||
Metadata enricher enriches metadata extracted by activity parser. | ||
""" | ||
alias Trento.Databases | ||
alias Trento.Clusters.Projections.ClusterReadModel | ||
alias Trento.Clusters | ||
alias Trento.Hosts.Projections.HostReadModel | ||
alias Trento.Hosts | ||
|
||
def enrich( | ||
%{ | ||
resource_id: resource_id, | ||
resource_type: resource_type | ||
} = metadata, | ||
activity, | ||
activity_context | ||
Check warning on line 17 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 17 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 17 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 17 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
|
||
) | ||
when activity in [:resource_tagging, :resource_untagging] do | ||
IO.inspect(activity, label: "activity") | ||
|
||
resource_name = | ||
case resource_type do | ||
:host -> get_hostname(resource_id) | ||
:cluster -> get_cluster_name(resource_id) | ||
_ -> nil | ||
end | ||
|
||
IO.inspect(resource_name, label: "resource_name") | ||
|
||
{:ok, | ||
case resource_name do | ||
nil -> metadata | ||
_ -> Map.put(metadata, :resource_name, resource_name) | ||
end} | ||
end | ||
|
||
def enrich(metadata, activity, activity_context) do | ||
Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
|
||
metadata | ||
end | ||
|
||
defp get_hostname(id) do | ||
case Hosts.by_host_id(id) do | ||
{:ok, %HostReadModel{hostname: hostname}} -> hostname | ||
{:error, :not_found} -> nil | ||
end | ||
end | ||
|
||
defp get_cluster_name(id) do | ||
case Clusters.by_cluster_id(id) do | ||
{:ok, %ClusterReadModel{name: cluster_name}} -> cluster_name | ||
{:error, :not_found} -> nil | ||
end | ||
end | ||
|
||
defp get_database_sid(id) do | ||
Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
|
||
end | ||
|
||
defp get_sap_system_sid(id) do | ||
Check warning on line 59 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 59 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 59 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 59 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
|
||
end | ||
|
||
defp get_application_instance_number(id) do | ||
Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
|
||
end | ||
|
||
defp get_database_instance_number(id) do | ||
Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / Test
Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V1)
Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / API bc check (V2)
Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex GitHub Actions / End to end tests
|
||
end | ||
end |