Default language.

Creating import triggers


Use the import trigger discovery run to create a discovery run that executes a trigger pattern without performing any discovery.

An import trigger discovery run can be a simple pattern that runs when triggered or one written to access a defined data source type when triggered. Import trigger discovery runs are particularly useful when you want to run arbitrary patterns without performing discovery.

The primary use case for import trigger discovery runs is a scheduled run that triggers a pattern to perform a regular task. For example, a local data source, accessible using a REST API, could contain information about your network devices. You could write a pattern that pulls data from the data source and uses it to update certain attributes on your discovered network devices.

When the discovery run occurs, it creates a DiscoveryAccess of the type defined in the trigger pattern, such as test_trigger. In this example, the pattern is triggered on a DiscoveryAccess whose trigger type is test_trigger, and the pattern runs.

Import trigger pattern with no data source

The simple import trigger example does not access a data source, and the pattern triggers on a DiscoveryAccess whose trigger type is, in the following example, test trigger.

tpl 1.16 module TriggerPatterns;

pattern trigger_pattern 1.0
 """
 Test for import trigger of pattern without a datasource
 """

    metadata
        trigger_type := "test trigger";
        categories := "Test";
    end metadata;

  overview
    tags test;
  end overview;

  triggers
    on da := DiscoveryAccess where trigger_type = "test trigger";
  end triggers;

  body
     log.info("trigger_pattern triggered");

     // The body of the pattern.

  end body;

end pattern; 

The metadata specifies a trigger type of test trigger, and when you create the discovery run, test trigger is available in the Trigger Type drop-down list. When the discovery run occurs, it creates a DiscoveryAccess whose trigger type is test trigger, and the pattern is triggered and runs.

Import trigger pattern using a data source

An import trigger that needs to access a data source triggers on a DiscoveryAccess whose trigger type is, in the following example, test datasource trigger.

tpl 1.16 module TriggerPatterns;


pattern trigger_pattern_datasource 1.0
 """
 Test for import trigger of pattern with datasource
 """

    metadata
        trigger_type := "test datasource trigger";
        data_source_types := "web_basic";
        categories := "Test";
    end metadata;

  overview
    tags test, datasource, web_basic;
  end overview;

  triggers
    on da := DiscoveryAccess where trigger_type = "test datasource trigger";
  end triggers;

  body
    log.info("trigger_pattern_datasource triggered");

    datasource := discovery.dataSource(da.data_source);

    if datasource = none then
        log.info('Datasource %da.data_source% not found');
        stop;
    end if;

    result := discovery.restfulGet(datasource, '', '/api/about');

    if result then
        if result.response_status = 200 then
            if result.response_body then
                decoded := json.decode(result.response_body);
                if decoded then
                    product_version := decoded["version"];
                    product_name := decoded["product"];
                    log.debug("Found product version from REST API: %product_version%");
                    log.debug("Found product version from REST API product_name: %product_name%");
                else
                   log.debug("Failed to json decode /api/about response. Raw response: %result.response_body%");
                end if;
            else
                log.debug("/api/about returned no response body");
            end if;
        else
            log.debug("/api/about returned %result.response_status%");
        end if;
    else
        log.debug("Failed to query /api/about");
    end if;

  end body;

end pattern;

The metadata specifies a trigger type of test datasource trigger, and when you create the discovery run, test datasource trigger is available in the Trigger Type drop-down list. 

When you select test datasource trigger the dialog box shows an additional list from which you select a named Data Source of the type specified in the  
data_source_types metadata.

When the discovery run occurs, it creates a DiscoveryAccess whose trigger type is test trigger and the pattern triggers and runs, by using the Data Source Rest API which is a REST API with basic authentication.
 

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*