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.

Last updated