author = $author; $this->comment = $comment; $this->forced = $forced; $this->broadcast = $broadcast; } /** * Get Custom Notification command format string according to if its sent to a host or a service * * @param string $type Identifier for either host or service * * @return string * * @throws InvalidCommandException When the given type is unknown * @see \Icinga\Protocol\Commandpipe\CommandPipe::TYPE_HOST * @see \Icinga\Protocol\Commandpipe\CommandPipe::TYPE_SERVICE */ public function getFormatString($type) { switch ($type) { case CommandPipe::TYPE_HOST: $format = '%s'; break; case CommandPipe::TYPE_SERVICE: $format = '%s;%s'; break; default: throw new InvalidCommandException('Custom Notifications can only apply on hosts and services'); } $options = 0; if ($this->forced) { $options |= self::NOTIFY_FORCED; } if ($this->broadcast) { $options |= self::NOTIFY_BROADCAST; } // Build the command $command = 'SEND_CUSTOM_' . $type . '_NOTIFICATION;' . $format . ';' . $options . ';' . $this->author . ';' . $this->comment; return $command; } }