LogoLogo
Enterprise GuideCommunity Edition GuideDeveloper Guide
  • Using The Polarity Developer Guide
  • Quick Start
    • What's New
    • Installing Integrations
    • Quick Start Guide
    • Learning Resources
  • Building an Integration
    • Directory Layout
    • package.json
    • Configuration File
    • Integration Main Module
      • startup
      • doLookup
        • Entity Objects
        • Result Objects
        • Error Objects
      • onDetails
      • onMessage
      • validateOptions
    • Customizing the Overlay Window
      • Templates
        • Conditionals
        • Displaying a List of Items
        • Display Object Properties
        • Built-in Helpers
        • Displaying Icons
      • Component File
        • Aliased Properties
        • Computed Properties
        • Event Hooks
      • CSS Styles
    • Vendor Javascript
      • Inserting Javascript into DOM
    • README Guide
    • Debugging Integrations
      • Web Inspector
      • Using Integration Logs
      • Testing Main Module
  • Recipes
    • Enabling User Actions
    • Throttling Lookups
    • Using Custom Entity Types
    • Custom Summary Tags
    • Creating a Tabbed Interface
    • Accessing Username of Requestor
Powered by GitBook
On this page
  • Define Custom Type in Config
  • Test for Custom Type
  • Multiple Custom Types
  1. Recipes

Using Custom Entity Types

Define your own custom entity types to receive data

Custom types allow integrations to receive any data that can be defined with a regular expression. To use a custom type you must define the custom type in your configuration file.

Define Custom Type in Config

In the example below we setup an integration configuration that identifies strings that match a special hostname naming convention.

config/config.js
{
    name: "Hostname Lookup",
    acronym: "HOST",
    description: "A sample integration that uses a custom regex to lookup hostnames and IPs",
    entityTypes: ['IPv4'],
    customTypes:[
        {
            key: 'hostname',
            regex: /[a-z]+_host/
        }
    ]
}

Test for Custom Type

Now in the main module's doLookup method we can test if the type is custom or IPv4 and take the appropriate action.

integration.js
function doLookup(entities, options, cb){
    let lookupResults = [];
    async.each(entities, function(entity, next){
        if(entity.type === 'IPv4'){
            // do IPv4 lookup logic here
            next(null);
        }else if(entity.type === 'custom'){
            // do hostname lookup logic here
            next(null);
        }
    }, function(err){
        cb(err, lookupResults);
    });    
}

Note that since the only custom type we defined is hostname we know that if the type property is custom then the entity must be a hostname entity.

Multiple Custom Types

If you have defined multiple custom types you can use javascript's Array.indexOf to test for specific types.

For example, if we have defined the custom types hostnameLinux and hostnameWindows we could test for the entity type in our doLookup method using the following:

integration.js
function doLookup(entities, options, cb){
    let lookupResults = [];
    async.each(entities, function(entity, next){
        if(entity.types.indexOf('custom.hostnameLinux') >= 0){
            // do hostnameLinux lookup logic here
            next(null);
        }else {
            // do hostnameWindows lookup here 
            next(null);
        }
    }, function(err){
        cb(err, lookupResults);
    });    
}

Note that custom types are prepended with custom.. This means if you want to check for the custom type hostnameLinux you must look for the type custom.hostnameLinux. Likewise, hostnameWindows would be stored in the types property as custom.hostnameWindows.

PreviousThrottling LookupsNextCustom Summary Tags

Last updated 5 years ago