You are here

function monitoring_search_api_index_insert in Monitoring 8

File

./monitoring.module, line 508
Monitoring bootstrap file.

Code

function monitoring_search_api_index_insert(IndexInterface $index) {
  if (!empty(\Drupal::configFactory()
    ->get('monitoring.settings')
    ->get('disable_sensor_autocreate'))) {
    return FALSE;
  }

  // Don't do anything if we are syncing or if the sensor already exists.
  $config_id = 'search_api_' . $index
    ->id();
  if ($index
    ->isSyncing() || SensorConfig::load($config_id)) {
    return;
  }
  $sensor = SensorConfig::create(array(
    'id' => $config_id,
    'label' => new FormattableMarkup('Search index queue size of @index', array(
      '@index' => $index
        ->label(),
    )),
    'plugin_id' => 'search_api_unindexed',
    'value_label' => 'Unindexed items',
    'value_type' => 'number',
    'category' => 'Search API',
    'caching_time' => 900,
    'status' => TRUE,
    'settings' => array(
      'index_id' => $index
        ->id(),
    ),
  ));
  $sensor
    ->save();
}