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.
{
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.
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);
});
}
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:
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);
});
}
Last updated