public function renderAddComment(AddCommentCommand $command)
 {
     $object = $command->getObject();
     if ($command->getObject()->getType() === $command::TYPE_HOST) {
         /** @var \Icinga\Module\Monitoring\Object\Host $object */
         $commandString = sprintf('ADD_HOST_COMMENT;%s', $object->getName());
     } else {
         /** @var \Icinga\Module\Monitoring\Object\Service $object */
         $commandString = sprintf('ADD_SVC_COMMENT;%s;%s', $object->getHost()->getName(), $object->getName());
     }
     return sprintf('%s;%u;%s;%s', $commandString, $command->getPersistent(), $command->getAuthor(), $command->getComment());
 }
Exemplo n.º 2
0
 /**
  * (non-PHPDoc)
  * @see \Icinga\Web\Form::onSuccess() For the method documentation.
  */
 public function onSuccess()
 {
     foreach ($this->objects as $object) {
         /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
         $comment = new AddCommentCommand();
         $comment->setObject($object);
         $comment->setComment($this->getElement('comment')->getValue());
         $comment->setAuthor($this->request->getUser()->getUsername());
         $comment->setPersistent($this->getElement('persistent')->isChecked());
         $this->getTransport($this->request)->send($comment);
     }
     Notification::success($this->translatePlural('Adding comment..', 'Adding comments..', count($this->objects)));
     return true;
 }
 public function renderAddComment(AddCommentCommand $command)
 {
     $endpoint = 'actions/add-comment';
     $data = array('author' => $command->getAuthor(), 'comment' => $command->getComment());
     $this->applyFilter($data, $command->getObject());
     return IcingaApiCommand::create($endpoint, $data);
 }