You are here

function monitoring_icinga_drush_callback in Monitoring 7

Drush callback to get the sensor info.

Parameters

string $sensor_name: Sensor name.

1 string reference to 'monitoring_icinga_drush_callback'
monitoring_icinga_drush_command in modules/monitoring_icinga/monitoring_icinga.drush.inc
Implements hook_drush_command().

File

modules/monitoring_icinga/monitoring_icinga.drush.inc, line 39
Drush integration for monitoring_icinga.module.

Code

function monitoring_icinga_drush_callback($sensor_name = NULL) {

  // If we are provided with sensor name we expect an active check.
  if (!empty($sensor_name)) {
    monitoring_icinga_active_check($sensor_name);
  }
  $results = monitoring_sensor_run_multiple();
  $output = '';
  foreach ($results as $result) {
    $message = iconv('utf-8', 'ASCII', truncate_utf8(strip_tags($result
      ->getMessage()), 124, TRUE, TRUE));
    $service_description = monitoring_icinga_service_description($result
      ->getSensorInfo());

    // Map INFO status to OK.
    $status = $result
      ->getStatus();
    if ($status == SensorResultInterface::STATUS_INFO) {
      $status = SensorResultInterface::STATUS_OK;
    }

    // Make sure the output does not have any new lines.
    $output .= preg_replace('/\\s+/', ' ', $service_description . '|' . $status . '|' . $message) . '~';
  }
  drush_print($output, 0, NULL, FALSE);
}