Create Python Hook

Create a Python hook or script to manipulate the Active Directory (AD) server data during import to the InsightPro for License Analytics.

The Python script must be provided as a hook to the Organization Hierarchy service during the data import.

Administrator can select this hook during the data import and it will help in manipulating the data before importing.

  1. View an existing sample hook (example_hook.py) that is available at $SERVER_INSTALLATION_DIR/home/config/ldap_hooks/hooks/.
    The example hook will be similar to:
    #!/usr/bin/env python3
    from hook_interface import Hook
    
    class ExampleHook(Hook):
        # Define the name of the hook here
        def get_unique_name(self):
            return "Example hook"
    
        # Transform user attributes
        def process_user_attributes(self, user_attributes):
            # Rename co to country
            if 'co' in user_attributes:
                user_attributes['country'] = user_attributes['co']
                del user_attributes['co']
    
            # Change department value
            if 'department' in user_attributes:
                user_attributes['department'] = user_attributes['department'] + ' (transformed)'
    
            # Create new attribute
            user_attributes['email_name'] = user_attributes['mail'] + user_attributes['sAMAccountName']
            return user_attributes
    

    In the above script, the get_unique_name method returns the hook name to be displayed in the Data Import tab of the Organization Hierarchy User Interface.

    The process_user_attributes gets all the user attributes available, as user_attributes. The incoming user_attributes can be manipulated to add new attributes. Remove the existing ones and manipulate the attribute values as shown above.

  2. Create a new Python hook file similar to example_hook.py, change the name to <name of the hook>_hook.py and copy it to $SERVER_INSTALLATION_DIR/home/config/ldap_hooks/hooks/ directory.
  3. Restart InsightPro for License Analytics server so that the hook is picked by the Organization Hierarchy service.
    inpro-lic set service --start