Connectors

William Leemans edited this page Sep 17, 2015 · 2 revisions
Clone this wiki locally

Connectors are the very essence of inventoryd. They are in charge of getting the information and converting them so inventoryd can handle them.

Each connector requires information for its proper operation. These are called parameters. The parameters is a set of information defining the data source and the data it provides, including format.

Every connector requires a schema definition, which basically tells inventoryd how to interpret the data.

A schema consists of the following fields:

  • name - (mandatory) - string - The name of the 'column'. This is the name it will be known as by inventoryd;
  • index - (mandatory) - string|integer - The index of the data you want to read. If your source does not support naming your columns, you can use the numeral index;
  • datatype - (mandatory) - string - Supported datatypes: boolean, float, integer, json and string;
  • lookup - (optional) - dictionary - the lookup table pair for the value interpreted. This can be a regex;
  • default - (optional) - variable - the default value you want to use if no value is found, or something weird happens when interpreting the variable;
  • exclude - (optional) - boolean - Do you want to import this column into inventoryd? You can achieve the same result by not defining the field.

Example:

[
    { 'name': 'hostname', 'index':'hostname', 'datatype': 'string', 'default':'n/a' },
    { 'name': 'env', 'index':'environment', 'datatype':' 'string', 'lookup': { 'Production':'prd', 'Test':'tst', 'Development':'dev' } },
    { 'name': 'is_virtual', 'index':'guest', 'datatype': true, 'default': false },
    { 'index':'last_scan', 'exclude': True }
]

This defines a data source which can read the following data:

[{'hostname':'coruscant', 'environment':'Production', 'guest': 1}]

The information is stored by inventoryd as

[{'hostname':'coruscant', 'env':'prd', 'is_virtual': true}]

A complete parameters entry looks like:

{ 'schema': [ ... ] }

Currently, the following connectors are supported:

uri

This connector will fetch a csv or json file (local or remote) and parse it.

Required parameters:

  • format (mandatory) - json or csv - the expected format of the data source
  • uri (mandatory) - string - the complete path to the data source. (eg /tmp/test.csv, http://localhost/test.json)

At this point in time, there is no CLI tool yet, so I suggest you read up on the documentation of sqlite3 to manage connectors.

sync_connectors table structure:

  • id - integer The unique ID for the connector
  • enabled - 0|1 - is the connector enabled? (0 = no, 1 = yes)
  • name - string - a human name for the connector
  • schedule - cron string - This is the schedule used to sync the datasource (eg @hourly, * * * * *)
  • connector - string - the name of connector used (currently only uri is available)
  • type - hosts|groups - does the connector access info about hosts or groups. No, I don't do both
  • priority - integer - the highest priority wins
  • parameters - json string - connector-specific parameters