You are here

function monitoring_search_api_index_update in Monitoring 8

File

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

Code

function monitoring_search_api_index_update(IndexInterface $index) {

  // Don't do anything if we are syncing, the sensor does not exists or the
  // index has not/ been renamed.
  $config_id = 'search_api_' . $index
    ->id();
  $new_config_id = 'search_api_' . $index->original
    ->id();
  if ($config_id == $new_config_id || $index
    ->isSyncing() || !SensorConfig::load($config_id)) {
    return;
  }
  $sensor = SensorConfig::load($config_id);

  // If the new sensor already exists, just drop this one.
  if (SensorConfig::load($new_config_id)) {
    $sensor
      ->delete();
  }
  else {
    $sensor->id = $new_config_id;
    $sensor->label = new FormattableMarkup('Search index queue size of @index', array(
      '@index' => $index
        ->id(),
    ));
    $sensor->settings['index_id'] = $index
      ->id();
    $sensor
      ->save();
  }
}