You can add a filter to basic integrations that filter integration data before it is sent to Oomnitza. The filter must begin with the recordfilter
keyword followed by a colon and then the filtering logic in the indented code block.
Tip
If you only want to apply basic filtering rules, such as checking if a value is not null or equals a specific value, you can create a filter for your integration in the Oomnitza UI. In the integration mapping section, click Edit integration to define rules for your integration.
Recordfilter
examples
Example 1: Filter values that are not null/are null
recordfilter: return record["field_name_in_data_source"] is not None recordfilter: return record["field_name_in_data_source"] is None
Example 2: Filter roles that do not equal employee
recordfilter: return record.get('Role') != 'Employee'
Example 3: Filter records that have a Serial Number and name starting with OOM
recordfilter: return record['hardware']['serial_number'] and record['hardware']['serial_number'].startswith('OOM') and record['hardware']['name'] and record['hardware']['name'].startswith('OOM')
Example 4: Filter records that have a name starting with ALIAS
recordfilter: return not record['profile']['lastName'].startswith('_ALIAS!')
Example 5: Filter records where the make is not VMware, Inc.
recordfilter: return record['hardware']['make'] != 'VMware, Inc.'
Example 6: Filter records where the username equals specialuseraccount, specialuseraccount2, or specialuseraccount3
recordfilter: return record.get('UserName') == 'specialuseraccount' or record.get('UserName') == 'specialuseraccount2' or record.get('UserName') == 'specialuseraccount3'
Example 7: Filter records that do not match a specific make but match an OS
recordfilter: return record['hardware']['os_version'] == "Microsoft Windows 7 Enterprise" and record['hardware']['make'] != "VMWare, Inc."
Example 8: Filter records that correspond to a certain location and make
recordfilter: check_location= record['hardware']['location_name'] and '/Building 500/' in record['hardware']['location_name'] check_make = record['hardware']['make'] != 'VMware, Inc.' if not (check_location and check_make): return False
Example 9: Queries serial numbers in Oomnitza using the Oomnitza API. The script checks if the vendor serial number exists in Oomnitza and is assigned to an active user. If the vendor serial number exists and is assigned to an active user, it indicates that the asset already exists in Oomnitza, and therefore, the asset is not uploaded. However, if the vendor serial number does not exist in Oomnitza, it can be pushed to Oomnitza for further processing.
recordfilter: vendor_serial_number = record['hardware']['serial_number'] oomnitza_serial_number_field = 'serial' from lib.connector import BaseConnector oomnitza_connector = BaseConnector.OomnitzaConnector if vendor_serial_number: oomnitza_asset_url = "{host}/api/v3/assets?filter={oomnitza_serial_number_field} eq '{vendor_serial_number}'&fields=assigned_to&include_deleted=1".format( host=oomnitza_connector.settings['url'], vendor_serial_number=vendor_serial_number, oomnitza_serial_number_field=oomnitza_serial_number_field ) assets = oomnitza_connector.get(oomnitza_asset_url).json() if assets: assigned_to = assets[0]['assigned_to'] if assigned_to: oomnitza_user_url = "{host}/api/v3/users/{username}?include_deleted=1".format( host=oomnitza_connector.settings['url'], username=assigned_to, ) user_active = oomnitza_connector.get(oomnitza_user_url).json()['active'] if user_active == 'False': return False return True
Example 10: Queries assets in Oomnitza using the Oomnitza API. The script checks if the vendor serial number exists. If a matching asset is found, it checks if the last_vendor_checkin value exists and is less than or equal to the check_in_date of the asset. If the check passes, it indicates that the asset has been checked in. If no matching asset is found or the check fails, the record can be pushed to Oomnitza.
recordfilter: try: check_in_date = arrow.get(record.updated_at).timestamp from lib.connector import BaseConnector oomnitza_connector = BaseConnector.OomnitzaConnector api_url = "{domain}/api/v3/assets?filter=serial_number eq '{value}'".format(domain=oomnitza_connector.settings['url'], value=record.serial_number) response = oomnitza_connector.get(api_url) response.raise_for_status() assets = response.json() if assets: last_vendor_checkin = assets[0].get('last_vendor_checkin') if last_vendor_checkin : return last_vendor_checkin <= check_in_date return True except: return True
Where to apply recordfilter
You can append a filter to the integration in the config.ini file.
[sccm] username = NEED TO FILL enable = True database = NEED TO FILL sync_field = 123456465454654654654 server = NEED TO FILL authentication = NEED TO FILL password = NEED TO FILL recordfilter: return record['hardware']['make'] != 'VMware, Inc.'
mapping.3123456487879879879879791 = {"source": "hardware.make"}
Ensure that the attribute you want to process is mapped in the config.ini file, not in the Web UI, to ensure that the filtering rules are applied correctly. If the mapping is done in the Web UI, the filtering may be ignored.
Uploading an integration using recordfilter
Use the test mode, in the format python connector.py upload [vendor_name_in_configuration_file] --testmode
, to verify that the filtering rules are being applied correctly. The log files will list the records that are excluded by the filter with the message: Skipping record [record details] because it did not pass the filter.
If you encounter any issues with the filtering logic, send the following to support for assistance.
-
- The saved data. Run the connector with the
--save-data
argument, which will generate JSON files. Package and zip the files extracted to the saved_data folder. - The
recordfilter
script. - The errors.log file.
- The saved data. Run the connector with the
Comments
0 comments
Please sign in to leave a comment.