getScriptingEvents() public static method

public static getScriptingEvents ( )
Example #1
0
 public function scriptingAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_LOGS_SCRIPTING_LOGS);
     $farms = self::loadController('Farms')->getList();
     array_unshift($farms, array('id' => '0', 'name' => 'All farms'));
     $scripts = array_map(function ($s) {
         return ['id' => $s['id'], 'name' => $s['name']];
     }, Script::getList($this->user->getAccountId(), $this->getEnvironmentId()));
     array_unshift($scripts, array('id' => 0, 'name' => ''));
     $glEvents = array_keys(EVENT_TYPE::getScriptingEvents());
     sort($glEvents);
     array_unshift($glEvents, '');
     $events = array_merge($glEvents, $this->db->GetCol('SELECT name FROM event_definitions WHERE env_id = ? ORDER BY name ASC', array($this->getEnvironmentId())));
     $tasks = $this->db->GetAll('SELECT id, name FROM scheduler WHERE env_id = ? ORDER BY name ASC', array($this->getEnvironmentId()));
     array_unshift($tasks, array('id' => 0, 'name' => ''));
     $this->response->page('ui/logs/scripting.js', array('farms' => $farms, 'scripts' => $scripts, 'events' => $events, 'tasks' => $tasks));
 }
Example #2
0
File: Logs.php Project: scalr/scalr
 public function orchestrationAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_LOGS_ORCHESTRATION_LOGS);
     $farms = self::loadController('Farms')->getList();
     array_unshift($farms, ['id' => '0', 'name' => 'All farms']);
     //todo: use Script::getScriptingData
     $scripts = array_map(function ($s) {
         return ['id' => $s['id'], 'name' => $s['name']];
     }, Script::getList($this->user->getAccountId(), $this->getEnvironmentId()));
     array_unshift($scripts, ['id' => 0, 'name' => '']);
     $glEvents = array_keys(EVENT_TYPE::getScriptingEvents());
     sort($glEvents);
     array_unshift($glEvents, '');
     $events = array_merge($glEvents, array_keys(\Scalr\Model\Entity\EventDefinition::getList($this->user->getAccountId(), $this->getEnvironmentId())));
     $tasks = $this->db->GetAll('SELECT id, name FROM scheduler WHERE env_id = ? ORDER BY name ASC', [$this->getEnvironmentId()]);
     array_unshift($tasks, ['id' => 0, 'name' => '']);
     $this->response->page('ui/logs/orchestration.js', ['farms' => $farms, 'scripts' => $scripts, 'events' => $events, 'tasks' => $tasks]);
 }
Example #3
0
 public function xSaveAction()
 {
     $this->request->defineParams(array('eventId', 'name', 'description'));
     if (!preg_match("/^[A-Za-z0-9]+\$/si", $this->getParam('name'))) {
         throw new Exception("Name should contain only alphanumeric characters");
     }
     if (strlen($this->getParam('name')) > 25) {
         throw new Exception("Name should be less than 25 characters");
     }
     if (in_array($this->getParam('name'), array_keys(EVENT_TYPE::getScriptingEvents()))) {
         throw new Exception(sprintf("'%' is reserved name for event. Please select another one.", $this->getParam('name')));
     }
     if (!$this->getParam('eventId')) {
         $this->db->Execute("INSERT INTO event_definitions SET\n                name = ?,\n                description = ?,\n                env_id = ?\n            ", array($this->getParam('name'), $this->getParam('description'), $this->getEnvironmentId()));
     } else {
         $this->db->Execute("UPDATE event_definitions SET\n                name = ?,\n                description = ?\n            WHERE\n                env_id = ? AND id = ?\n            ", array($this->getParam('name'), $this->getParam('description'), $this->getEnvironmentId(), $this->getParam('eventId')));
     }
     $this->response->success('Custom event definition successfully saved');
 }
Example #4
0
 private function getEventsList()
 {
     $events = EVENT_TYPE::getScriptingEvents();
     $envId = $this->getEnvironmentId();
     //Temporary added new events like this, workign on events refactoring
     $events['HostInitFailed'] = 'Instance was unable to initialize';
     $events['InstanceLaunchFailed'] = 'Scalr failed to launch instance due to cloud error';
     if ($envId) {
         $userEvents = $this->db->Execute("SELECT * FROM event_definitions WHERE env_id = ?", array($envId));
         while ($event = $userEvents->FetchRow()) {
             $events[$event['name']] = $event['description'];
         }
     }
     return $events;
 }
Example #5
0
 public function getScriptingData()
 {
     $retval = array('events' => EVENT_TYPE::getScriptingEvents(), 'scripts' => $this->getList());
     try {
         $envId = $this->getEnvironmentId();
         if ($envId) {
             $events = $this->db->Execute("SELECT * FROM event_definitions WHERE env_id = ?", array($envId));
             while ($event = $events->FetchRow()) {
                 $retval['events'][$event['name']] = $event['description'];
             }
         }
     } catch (Exception $e) {
     }
     return $retval;
 }
Example #6
0
 public function getScriptingData()
 {
     return array('events' => EVENT_TYPE::getScriptingEvents(), 'scripts' => $this->getList());
 }
Example #7
0
 /**
  * @param   integer $id
  * @param   string  $name
  * @param   string  $description
  * @param   bool    $replaceEvent
  * @throws  Exception
  * @throws  Scalr_Exception_Core
  */
 public function xSaveAction($id = 0, $name, $description, $replaceEvent = false)
 {
     $this->request->restrictAccess(Acl::RESOURCE_GENERAL_CUSTOM_EVENTS, Acl::PERM_GENERAL_CUSTOM_EVENTS_MANAGE);
     $validator = new \Scalr\UI\Request\Validator();
     $validator->addErrorIf(!preg_match("/^[A-Za-z0-9]+\$/si", $name), 'name', "Name should contain only alphanumeric characters");
     $validator->addErrorIf(strlen($name) > 25, 'name', "Name should be less than 25 characters");
     $validator->addErrorIf(in_array($name, array_keys(EVENT_TYPE::getScriptingEvents())), 'name', sprintf("'%' is reserved name for event. Please select another one.", $name));
     $scope = $this->request->getScope();
     if (!$id) {
         $criteria = [['name' => $name]];
         if ($this->user->isScalrAdmin()) {
             $criteria[] = ['accountId' => NULL];
         } else {
             $criteria[] = ['$or' => [['accountId' => $this->user->getAccountId()], ['accountId' => NULL]]];
             if ($scope == 'account') {
                 $criteria[] = ['envId' => NULL];
             } else {
                 $criteria[] = ['$or' => [['envId' => NULL], ['envId' => $this->getEnvironmentId(true)]]];
             }
         }
         $validator->addErrorIf(EventDefinition::find($criteria)->count(), 'name', 'This name is already in use. Note that Event names are case-insensitive.');
         // check replacements
         $replacements = NULL;
         if ($this->user->isScalrAdmin()) {
             $replacements = EventDefinition::find([['name' => $name], ['accountId' => ['$ne' => NULL]]]);
         } else {
             if ($scope == 'account') {
                 $replacements = EventDefinition::find([['name' => $name], ['accountId' => $this->user->getAccountId()], ['envId' => ['$ne' => NULL]]]);
             }
         }
     }
     if (!$validator->isValid($this->response)) {
         return;
     }
     if ($replacements && $replacements->count() && !$replaceEvent) {
         $this->response->data(['replaceEvent' => true]);
         $this->response->failure();
         return;
     }
     if ($id) {
         $event = EventDefinition::findPk($id);
         /* @var $event EventDefinition */
         if (!$event) {
             throw new Exception('Event not found');
         }
         if ($this->user->isScalrAdmin() && $event->accountId == NULL && $event->envId == NULL || $this->user->isUser() && $event->accountId == $this->user->getAccountId() && ($event->envId == NULL || $event->envId == $this->getEnvironmentId())) {
             $event->description = $description;
         } else {
             throw new Scalr_Exception_InsufficientPermissions();
         }
         $event->save();
     } else {
         $event = new EventDefinition();
         if ($this->user->isScalrAdmin()) {
             $event->accountId = NULL;
             $event->envId = NULL;
         } else {
             $event->accountId = $this->user->getAccountId();
             $event->envId = $scope == 'account' ? NULL : $this->getEnvironmentId();
         }
         $event->name = $name;
         $event->description = $description;
         $event->save();
         if ($replacements) {
             foreach ($replacements as $e) {
                 $e->delete();
             }
         }
     }
     $used = $event->getUsed($this->user->getAccountId(), $this->getEnvironmentId(true));
     $this->response->data(['event' => ['id' => $event->id, 'name' => $event->name, 'description' => $event->description, 'used' => $used, 'scope' => $scope, 'status' => $used ? 'In use' : 'Not used']]);
     $this->response->success('Custom event definition successfully saved');
 }
Example #8
0
 public static function getScriptingData($accountId, $envId)
 {
     return ['events' => array_merge(\EVENT_TYPE::getScriptingEvents(), EventDefinition::getList($accountId, $envId)), 'scripts' => self::getList($accountId, $envId)];
 }