public function indexAction($type) { if (!in_array($type, Command::getTypes())) { return $this->abort(404); } $findBy = array('type' => $type); $items = $this->getCommandRepository()->findBy($findBy, array('sort' => array('name' => 1))); return $this->renderView('DevtureNagiosBundle/command/index.html.twig', array('items' => $items, 'type' => $type)); }
public function connect(Application $app) { $controllers = $app['controllers_factory']; $namespace = 'devture_nagios'; $types = array_merge(Command::getTypes(), array('__TYPE__')); $controllers->get('/commands/{type}', 'devture_nagios.controller.command.api:listAction')->assert('type', implode('|', $types))->convert('type', function ($type) { return $type === '__TYPE__' ? Command::TYPE_SERVICE_CHECK : $type; })->bind($namespace . '.api.command.list'); $controllers->get('/hosts-info/{id}', 'devture_nagios.controller.host.api:infoAction')->value('id', null)->bind($namespace . '.api.host.info'); $controllers->post('/host/recheck-services/{id}/{recheckType}/{token}', 'devture_nagios.controller.host.api:recheckServicesAction')->assert('recheckType', 'all|failing|__RECHECK_TYPE__')->convert('recheckType', function ($type) { return $type === '__RECHECK_TYPE__' ? 'all' : $type; })->bind($namespace . '.api.host.recheck_services'); $controllers->get('/logs/{ifNewerThanId}', 'devture_nagios.controller.log.api:listAction')->value('ifNewerThanId', null)->bind($namespace . '.api.log.list'); return $controllers; }
/** * @param Command $entity * @param array $options * @return \Devture\Component\Form\Validator\ViolationsList */ public function validate($entity, array $options = array()) { $violations = parent::validate($entity, $options); $name = $entity->getName(); if (strlen($name) < 3 || !preg_match("/^[a-z][a-z0-9_\\-\\.]+\$/", $name)) { $violations->add('name', 'Invalid name.'); } else { try { $ent = $this->repository->findOneBy(array('name' => $name)); if (spl_object_hash($ent) !== spl_object_hash($entity)) { $violations->add('name', 'The name is already in use.'); } } catch (NotFound $e) { } } if (!in_array($entity->getType(), Command::getTypes())) { $violations->add('type', 'Invalid type.'); } $line = $entity->getLine(); if ($this->isEmpty($line)) { $violations->add('line', 'The command line cannot be empty.'); } else { if (strpos($line, "\n") !== false) { $violations->add('line', 'The command cannot contain a new line.'); } if (strpos($line, ';') !== false) { $violations->add('line', 'The command cannot contain `;` as that is considered a comment.'); } } $expectedArgumentsCount = $entity->getLineArgumentsCount(); $arguments = $entity->getArguments(); if (count($arguments) !== $expectedArgumentsCount) { $violations->add('arguments', 'Command expects %expected% arguments. Got only %provided%.', array('{{expected}}' => $expectedArgumentsCount, '{{provided}}' => count($arguments))); } foreach ($arguments as $argument) { $argumentId = $argument->getId(); if ($argumentId === null || !preg_match('/^\\$ARG([0-9]+)\\$$/', $argumentId)) { $violations->add('arguments', 'Invalid command argument id: %id%', array('%id%' => $argumentId)); } if ($this->isEmpty($argument->getDescription())) { $violations->add('arguments', 'Command argument descriptions cannot be empty.'); } } return $violations; }