Exemple #1
0
 public function export(Service $entity)
 {
     $contacts = array_map(function (Contact $contact) {
         return $this->contactBridge->export($contact);
     }, $entity->getContacts());
     return array('id' => (string) $entity->getId(), 'enabled' => $entity->isEnabled(), 'name' => $entity->getName(), 'host' => $this->hostBridge->export($entity->getHost()), 'contacts' => $contacts);
 }
 private function escapeShellArg(Service $service, $argumentValue)
 {
     //Macros won't work in command arguments (because we escape $ bellow).
     //Let's handle this single macro here (at generation time), for convenience.
     if ($argumentValue === '$HOSTADDRESS$') {
         return escapeshellarg($service->getHost()->getAddress());
     }
     //This argument should be turned into safe text.
     //`escapeshellarg($argumentValue)` will not work for our special needs.
     //The resulting string will be similar (single-quote surrounded), but not quite the same.
     $argumentValue = str_replace('\\', '\\\\', $argumentValue);
     $argumentValue = str_replace('$', '$$', $argumentValue);
     //`!` is used to separate the arguments passed to the command. It needs to be escaped.
     $argumentValue = str_replace('!', '\\!', $argumentValue);
     $argumentValue = str_replace(';', '\\;', $argumentValue);
     $argumentValue = str_replace("", '', $argumentValue);
     //Escape single-quotes within the would-be-single-quote-surrounded-string.
     //Basically turning `'can't'` into `'can'"'"'t' (break out of single quotes, concat a single quote, re-open single quotes)
     //This is similar to `escapeshellarg($string)`, but escpeshellarg turns `'can't'` into `'can'\''t'`,
     //and Nagios does not seem to like that way of escaping single quotes.
     $argumentValue = str_replace("'", "'" . '"' . "'" . '"' . "'", $argumentValue);
     return "'" . $argumentValue . "'";
 }
Exemple #3
0
 public function scheduleServiceCheck(Service $service)
 {
     $timeNow = time();
     $command = sprintf('[%d] SCHEDULE_SVC_CHECK;%s;%s;%d', $timeNow, $service->getHost()->getName(), $service->getName(), $timeNow);
     $this->submitter->submit($command);
 }
Exemple #4
0
 public function canUserManageService(User $user, Service $service)
 {
     return $this->canUserManageHost($user, $service->getHost());
 }
Exemple #5
0
 /**
  * @param Service $service
  * @return \Devture\Bundle\NagiosBundle\Status\ServiceStatus|NULL
  */
 public function getServiceStatus(Service $service)
 {
     $this->load();
     $serviceIdentifier = $service->getHost()->getName() . '/' . $service->getName();
     return isset($this->servicesStatusMap[$serviceIdentifier]) ? $this->servicesStatusMap[$serviceIdentifier] : null;
 }