private function isMasterService(Service $service)
 {
     $name = $service->getName();
     foreach ($this->masterServicesRegexes as $regex) {
         if (preg_match($regex, $name)) {
             return true;
         }
     }
     return false;
 }
Пример #2
0
 /**
  * @see \Devture\Component\DBAL\Repository\BaseRepository::hydrateModel()
  */
 protected function hydrateModel(array $data)
 {
     $model = new Service($data);
     if (isset($data['hostId'])) {
         $model->setHost($this->hostRepository->find($data['hostId']));
     }
     if (isset($data['commandId'])) {
         $model->setCommand($this->commandRepository->find($data['commandId']));
     }
     if (isset($data['contactsIds']) && is_array($data['contactsIds'])) {
         foreach ($data['contactsIds'] as $contactId) {
             $model->addContact($this->contactRepository->find($contactId));
         }
     }
     return $model;
 }
Пример #3
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 . "'";
 }
Пример #5
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);
 }
Пример #6
0
 public function canUserManageService(User $user, Service $service)
 {
     return $this->canUserManageHost($user, $service->getHost());
 }
Пример #7
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;
 }