handlers.relation_sync_handler

class RelationSyncHandler(handlers.eventhandler.EventHandler):

Synchronizes relations from one fact sheet type to another fact sheet type.

Relation triangle:

  • There are 3 fact sheet types: 0, 1 and 2.
  • rel_0_to_1 and rel_1_to_2 are leading.
  • rel_0_to_2 is derived from the two leading relations.

Example: A Server with the ITComponents "Windows Server 2019" and "IBM DB2" is linked to an Application. Then this automation links the ITComponents "Windows Server 2019" and "IBM DB2" to the Application as well. If the Server is removed from the Application or upgraded to another operating system, the ITComponents of the Application are kept consistent automatically (outdated ones removed, new ones added).

You can set the config value "delete_outdated" to False (default: True) if you don't want to automatically clean up outdated relations. Works if you touch rel_0_to_1 or rel_1_to_2.
WARNING: If this is set to True, it really removes all relations between fs0 and fs2 that don't have a linking fs1 between them! In the "Server" example, it really removes all ITComponents from an Application that are not linked to any of the Application's Servers, also the manually-linked ones. If you don't want that, set keep_manual_relations to True.

You can set the config value "watch_auto_relations" to True (default: False) if you want to monitor freshly created/modified/deleted rel_0_to_2 relations and see if the edit was ok, or if it needs to be reverted.

Recommendation: Set both config values to true or both to false.

Whenever you set up a new relation_sync automation, make sure to follow this procedure:

  1. Deactivate the Webhook
  2. Create the feature config
  3. Temporarily set all other feature configs of the relation_sync handler to “inactive”
  4. Trigger the initial full sync using ssh and this command:
    DJANGO_SETTINGS_MODULE=leanixdqm.production python -m scripts.lx.relation_sync
  5. Re-activate the webhook and the other feature configs
name = 'Relation Synchronization Handler'
description = 'Synchronizes relations from one fact sheet type to another fact sheet type.'
conditions = {'event_types': ['RelationCreatedEvent', 'RelationUpdatedEvent', 'RelationSwitchEvent', 'RelationArchivedEvent', 'RelationDeletedEvent']}
supports_initial_sync = True
config_template = {'delete_outdated': True, 'keep_manual_relations': True, 'watch_auto_relations': False, 'skip_fact_sheet_preload': False, 'fs_types': ['Application', 'Server', 'ITComponent'], 'leading_relations': ['relApplicationToServer', 'relServerToITComponent'], 'following_relation': 'relApplicationToITComponent'}
def handle(self, event, fs, **kwargs):

Called automatically whenever a FactSheetUpdated event comes in via webhook.

def path_exists(self, from_id, from_type, to_id, to_type):
def create_and_delete_on_base_fs0(self, fs, delete_outdated, mode=None, delete_candidates=None):
def initial_sync_event(self, fs):