protected function sendCommand(IcingaApiCommand $command) { Logger::debug('Sending Icinga command "%s" to the API "%s:%u"', $command->getEndpoint(), $this->getHost(), $this->getPort()); $response = RestRequest::post($this->getUriFor($command->getEndpoint()))->authenticateWith($this->getUsername(), $this->getPassword())->sendJson()->noStrictSsl()->setPayload($command->getData())->send(); if (isset($response['error'])) { throw new CommandTransportException('Can\'t send external Icinga command: %u %s', $response['error'], $response['status']); } $result = array_pop($response['results']); if ($result['code'] < 200 || $result['code'] >= 300) { throw new CommandTransportException('Can\'t send external Icinga command: %u %s', $result['code'], $result['status']); } if ($command->hasNext()) { $this->sendCommand($command->getNext()); } }
public function renderToggleInstanceFeature(ToggleInstanceFeatureCommand $command) { $endpoint = 'objects/icingaapplications/' . $this->getApp(); if ($command->getEnabled() === true) { $enabled = true; } else { $enabled = false; } switch ($command->getFeature()) { case ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS: $attr = 'enable_host_checks'; break; case ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS: $attr = 'enable_service_checks'; break; case ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS: $attr = 'enable_event_handlers'; break; case ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION: $attr = 'enable_flapping'; break; case ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS: $attr = 'enable_notifications'; break; case ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA: $attr = 'enable_perfdata'; break; default: throw new InvalidArgumentException($command->getFeature()); } $data = array('attrs' => array($attr => $enabled)); return IcingaApiCommand::create($endpoint, $data); }