* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} namespace Monitoring\Form\Command; use Icinga\Exception\ProgrammingError; /** * Form for submitting passive check results */ class SubmitPassiveCheckResultForm extends CommandForm { /** * Type constant for host form */ const TYPE_HOST = 'host'; /** * Type constant for service form */ const TYPE_SERVICE = 'service'; /** * List of choices for plugin states * @var array */ private static $options = array(); /** * Type of form * @var string */ private $type; /** * Setup plugin states * @see Zend_Form::init */ public function init() { if (!count(self::$options)) { self::$options = array( self::TYPE_HOST => array( 0 => t('UP'), 1 => t('DOWN'), 2 => t('UNREACHABLE') ), self::TYPE_SERVICE => array( 0 => t('OK'), 1 => t('WARNING'), 2 => t('CRITICAL'), 3 => t('UNKNOWN') ) ); } parent::init(); } /** * Setter for type * @param string $type */ public function setType($type) { $this->type = $type; } /** * Getter for type * @return string */ public function getType() { return $this->type; } /** * Return array of options * @return array * @throws \Icinga\Exception\ProgrammingError */ public function getOptions() { if (in_array($this->getType(), array(self::TYPE_HOST, self::TYPE_SERVICE)) === false) { throw new ProgrammingError('Type is not valid'); } return self::$options[$this->getType()]; } /** * Create the form's elements * * @see CommandForm::create() */ protected function create() { $this->addElement( 'select', 'pluginstate', array( 'label' => t('Plugin state'), 'multiOptions' => $this->getOptions(), 'required' => true, 'validators' => array( array( 'Digits', true ), array( 'InArray', true, array( array_keys($this->getOptions()) ) ) ) ) ); $this->addElement( 'textarea', 'checkoutput', array( 'label' => t('Check output'), 'rows' => 2, 'required' => true ) ); $this->addElement( 'textarea', 'performancedata', array( 'label' => t('Performance data'), 'rows' => 2 ) ); $this->setSubmitLabel(t('Submit passive check result')); parent::create(); } public function getState() { return intval($this->getValue('pluginstate')); } public function getOutput() { return $this->getValue('checkoutput'); } public function getPerformancedata() { return $this->getValue('performancedata'); } }