Пример #1
0
     $apiResponse = new APIViewData(1, $deployment, "Unable to detect deployment revision specified in datastore");
     $app->halt(404, $apiResponse->returnJson());
 }
 $request = $app->request();
 $contentType = $request->headers('Content-Type');
 if ($contentType == 'application/json') {
     $showInfo = $request->getBody();
     $showInfo = json_decode($diffInfo, true);
     if (!isset($showInfo['shard']) || empty($showInfo['shard'])) {
         $showInfo['shard'] = false;
     }
 } elseif (preg_match("/form-(data|urlencoded)/", $contentType)) {
     $showInfo = array();
     $showInfo['shard'] = $request->post('shard');
 }
 $islocked = NagTester::getDeploymentBuildLock($deployment, $subdeployment, $revision);
 if ($islocked === false) {
     $force = $app->request()->post('force');
     $deploymentResults = NagTester::getDeploymentBuildInfo($deployment, $subdeployment, $revision);
     if ($force !== null) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'revision' => $revision, 'type' => 'build', 'subdeployment' => $subdeployment, 'shard' => $showInfo['shard'])), 1024, 0, 900);
         $apiResponse = new APIViewData(0, $deployment, "Build process has been initiated, please change request type to GET to fetch results.");
     } elseif (empty($deploymentResults)) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'revision' => $revision, 'type' => 'build', 'subdeployment' => $subdeployment, 'shard' => $showInfo['shard'])), 1024, 0, 900);
         $apiResponse = new APIViewData(0, $deployment, "Build process has been initiated, please change request type to GET to fetch results.");
     } elseif (isset($deploymentResults['timestamp']) && $deploymentResults['timestamp'] < time() - 60) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'revision' => $revision, 'type' => 'build', 'subdeployment' => $subdeployment, 'shard' => $showInfo['shard'])), 1024, 0, 900);
         $apiResponse = new APIViewData(0, $deployment, "Build process has been initiated, please change request type to GET to fetch results.");
 /**
  * diff_configs - diff configurations view / routine 
  * 
  * @access public
  * @return void
  */
 public function diff_configs()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('deployment_error');
     $this->checkGroupAuth($deployment);
     $fromrev = $this->getParam('fromrev');
     $torev = $this->getParam('torev');
     if ($fromrev === false) {
         $viewData->header = $this->getErrorHeader('deployment_error');
         $viewData->error = 'Unable to detect revision to diff from...';
         $this->sendError('generic_error', $viewData);
     } elseif ($torev === false) {
         $viewData->header = $this->getErrorHeader('deployment_error');
         $viewData->error = 'Unable to detect revision to diff too...';
         $this->sendError('generic_error', $viewData);
     } elseif ($fromrev == $torev) {
         $viewData->header = $this->getErrorHeader('deployment_error');
         $viewData->error = 'Unable to diff the revisions when they are the same revision...';
         $this->sendError('generic_error', $viewData);
     }
     $subdeployment = $this->getParam('subdeployment');
     $shardposition = $this->getParam('shard');
     $islocked = NagTester::getDeploymentBuildLock($deployment, $subdeployment, $fromrev);
     if ($islocked === false) {
         $islocked = NagTester::getDeploymentBuildLock($deployment, $subdeployment, $torev);
         if ($islocked === false) {
             $viewData->running = false;
         } else {
             $viewData->running = true;
         }
     } else {
         $viewData->running = true;
     }
     $deploymentResults = NagTester::getDeploymentDiffInfo($deployment, $subdeployment);
     if (empty($deploymentResults) && $islocked !== false) {
         $viewData->jobadded = false;
         $deploymentResults['timestamp'] = '0000000000';
         $viewData->output = base64_encode('Job is currently processing, this page will reload automatically...');
     } elseif (empty($deploymentResults) && $islocked === false) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'type' => 'diff', 'fromrev' => $fromrev, 'torev' => $torev, 'subdeployment' => $subdeployment, 'shard' => $shardposition)), 1024, 0, 900);
         $viewData->jobadded = true;
         $deploymentResults['timestamp'] = '0000000000';
         $viewData->output = base64_encode('Build Process has been initiated, this page will reload automatically...');
     } elseif (isset($deploymentResults['timestamp']) && $deploymentResults['timestamp'] < time() - 60 && $islocked === false) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'type' => 'diff', 'fromrev' => $fromrev, 'torev' => $torev, 'subdeployment' => $subdeployment, 'shard' => $shardposition)), 1024, 0, 900);
         $viewData->jobadded = true;
         $viewData->output = base64_encode('Build Process has been initiated, this page will reload automatically...');
     } elseif (isset($deploymentResults['subdeployment']) && $deploymentResults['subdeployment'] != $subdeployment && $islocked === false) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'type' => 'diff', 'fromrev' => $fromrev, 'torev' => $torev, 'subdeployment' => $subdeployment, 'shard' => $shardposition)), 1024, 0, 900);
         $viewData->jobadded = true;
         $viewData->output = base64_encode('Build Process has been initiated, this page will reload automatically...');
     } elseif (isset($deploymentResults['fromrev']) && $deploymentResults['fromrev'] != $fromrev && $islocked === false) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'type' => 'diff', 'fromrev' => $fromrev, 'torev' => $torev, 'subdeployment' => $subdeployment, 'shard' => $shardposition)), 1024, 0, 900);
         $viewData->jobadded = true;
         $viewData->output = base64_encode('Build Process has been initiated, this page will reload automatically...');
     } elseif (isset($deploymentResults['torev']) && $deploymentResults['torev'] != $torev && $islocked === false) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'type' => 'diff', 'fromrev' => $fromrev, 'torev' => $torev, 'subdeployment' => $subdeployment, 'shard' => $shardposition)), 1024, 0, 900);
         $viewData->jobadded = true;
         $viewData->output = base64_encode('Build Process has been initiated, this page will reload automatically...');
     } elseif (!empty($deploymentResults) && $islocked !== false) {
         $viewData->output = base64_encode('Job is currently processing, this page will reload automatically...');
         $viewData->jobadded = false;
     } else {
         $viewData->jobadded = false;
         $configdata = json_decode($deploymentResults['configs'], true);
         $deploymentData = $deploymentResults;
         unset($deploymentData['configs']);
         unset($deploymentData['output']);
         $viewData->meta = $deploymentData;
         $viewData->diff = NagDiff::diff($configdata['nagiosconfs']['from'], $configdata['nagiosconfs']['to']);
         $viewData->nagplugins = NagDiff::diff($configdata['plugins']['nagios']['from'], $configdata['plugins']['nagios']['to']);
         $viewData->cplugins = NagDiff::diff($configdata['plugins']['nrpe']['core']['from'], $configdata['plugins']['nrpe']['core']['to']);
         $viewData->splugins = NagDiff::diff($configdata['plugins']['nrpe']['sup']['from'], $configdata['plugins']['nrpe']['sup']['to']);
     }
     if (isset($deploymentResults['starttime']) && $deploymentResults['timestamp'] != '0000000000') {
         $viewData->meta['totaltime'] = $deploymentResults['timestamp'] - $deploymentResults['starttime'];
     }
     if ($viewData->jobadded === true || $viewData->running === true) {
         $viewData->refresh = 15;
     }
     $viewData->deployment = $deployment;
     $viewData->subdeployment = $subdeployment;
     $viewData->action = 'diff_configs';
     $viewData->controller = 'deployment';
     $viewData->fromrev = $fromrev;
     $viewData->torev = $torev;
     $this->sendResponse('deployment_diff_configs', $viewData);
 }