You are here

function monitoring_icinga_active_check in Monitoring 7

Prints sensor status message and exits with sensor status code.

This callback should be used for active icinga checks where icinga directly invokes the sensor and expects printed output and exit code.

Parameters

string $sensor_name: Sensor name to run.

1 call to monitoring_icinga_active_check()
monitoring_icinga_drush_callback in modules/monitoring_icinga/monitoring_icinga.drush.inc
Drush callback to get the sensor info.

File

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

Code

function monitoring_icinga_active_check($sensor_name) {
  $statuses = monitoring_icinga_status_codes();
  try {
    $result = monitoring_sensor_run($sensor_name);
  } catch (NonExistingSensorException $e) {
    drush_set_error('MONITORING_SENSOR_INVALID_NAME', dt('Sensor "@name" does not exist.', array(
      '@name' => $sensor_name,
    )));
    return $statuses[SensorResultInterface::STATUS_CRITICAL];
  } catch (DisabledSensorException $e) {
    drush_set_error('MONITORING_SENSOR_DISABLED', dt('Sensor "@name" is not enabled.', array(
      '@name' => $sensor_name,
    )));
    return $statuses[SensorResultInterface::STATUS_CRITICAL];
  }
  drush_print(iconv('utf-8', 'ASCII', $result
    ->getMessage()));

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