Пример #1
0
 /**
  * init 
  * 
  * @static
  * @access public
  * @return void
  */
 public static function init()
 {
     /* Initial Redis Information */
     if (self::$init === false) {
         NagRedis::init();
         self::$log = new NagLogger();
         self::$init = true;
     }
     return;
 }
Пример #2
0
 /**
  * buildDiffRevisions - build the revisions of the deployment and store them for diffing
  * 
  * @param mixed $deployment    deployment we are building revisions for
  * @param mixed $subdeployment deployment we are building revisions for
  * @param mixed $fromrev       from revision we are building
  * @param mixed $torev         to revision we are building
  * @param mixed $shardposition shard position we may be using
  *
  * @static
  * @access public
  * @return void
  */
 public static function buildDiffRevisions($deployment, $subdeployment, $fromrev, $torev, $shardposition)
 {
     self::$_results = array();
     self::$_output = "";
     NagRedis::init(true);
     $lockReturn = NagTester::setDeploymentBuildLock($deployment, $subdeployment, $fromrev);
     if ($lockReturn === false) {
         self::$_output = "Unable to acquire build lock for Deployment/Revision: {$deployment}/{$fromrev}";
         return false;
     }
     NagCreate::resetLocalCache();
     /* Get Current Nagios Configs */
     NagCreate::buildDeployment($deployment, $fromrev, true, true, $shardposition);
     $fromconfs = NagCreate::returnDeploymentConfigs($deployment);
     $fromconfs['nrpe.cfg'] = self::_getNRPECfg($deployment, $fromrev);
     $fromconfs['supplemental-nrpe.cfg'] = self::_getSupNRPECfg($deployment, $fromrev);
     NagTester::deleteDeploymentBuildLock($deployment, $subdeployment, $fromrev);
     $lockReturn = NagTester::setDeploymentBuildLock($deployment, $subdeployment, $torev);
     if ($lockReturn === false) {
         self::$_output = "Unable to acquire build lock for Deployment/Revision: {$deployment}/{$torev}";
         return false;
     }
     /* Get Future Revision Configs */
     NagCreate::buildDeployment($deployment, $torev, true, true, $shardposition);
     $toconfs = NagCreate::returnDeploymentConfigs($deployment);
     $toconfs['nrpe.cfg'] = self::_getNRPECfg($deployment, $torev);
     $toconfs['supplemental-nrpe.cfg'] = self::_getSupNRPECfg($deployment, $torev);
     NagTester::deleteDeploymentBuildLock($deployment, $subdeployment, $torev);
     /* Get Plugin Information */
     $fnagplugins = RevDeploy::getDeploymentNagiosPlugins($deployment, $fromrev);
     $tnagplugins = RevDeploy::getDeploymentNagiosPlugins($deployment, $torev);
     $nagplugins = array_merge($fnagplugins, $tnagplugins);
     $fromnagiosplugins = self::_getPlugins('nagios', $deployment, $fromrev, $nagplugins);
     $tonagiosplugins = self::_getPlugins('nagios', $deployment, $torev, $nagplugins);
     $fplugins = RevDeploy::getDeploymentNRPEPlugins($deployment, $fromrev);
     $tplugins = RevDeploy::getDeploymentNRPEPlugins($deployment, $torev);
     $plugins = array_merge($fplugins, $tplugins);
     $fromnrpecoreplugins = self::_getPlugins('nrpe-core', $deployment, $fromrev, $plugins);
     $tonrpecoreplugins = self::_getPlugins('nrpe-core', $deployment, $torev, $plugins);
     $fsplugins = RevDeploy::getDeploymentSupNRPEPlugins($deployment, $fromrev);
     $tsplugins = RevDeploy::getDeploymentSupNRPEPlugins($deployment, $torev);
     $supplugins = array_merge($fsplugins, $tsplugins);
     $fromsupnrpeplugins = self::_getPlugins('nrpe-sup', $deployment, $fromrev, $supplugins);
     $tosupnrpeplugins = self::_getPlugins('nrpe-sup', $deployment, $torev, $supplugins);
     /* Ok lets diff the results and send it out */
     $results = array();
     $results['nagiosconfs']['from'] = $fromconfs;
     $results['nagiosconfs']['to'] = $toconfs;
     $results['plugins']['nagios']['from'] = $fromnagiosplugins;
     $results['plugins']['nagios']['to'] = $tonagiosplugins;
     $results['plugins']['nrpe']['core']['from'] = $fromnrpecoreplugins;
     $results['plugins']['nrpe']['core']['to'] = $tonrpecoreplugins;
     $results['plugins']['nrpe']['sup']['from'] = $fromsupnrpeplugins;
     $results['plugins']['nrpe']['sup']['to'] = $tosupnrpeplugins;
     self::$_results = $results;
     unset($fromconfs, $toconfs, $results);
     unset($fnagplugins, $tnagplugins, $nagplugins, $fromnagiosplugins, $tonagiosplugins);
     unset($fplugins, $tplugins, $plugins, $fromnrpecoreplugins, $tonrpecoreplugins);
     unset($fsplugins, $tsplugins, $supplugins, $fromsupnrpeplugins, $tosupnrpeplugins);
     return true;
 }
Пример #3
0
 */
$app->get('/sapi/consumer/routervms/:zone', function ($zone) use($app) {
    $zone = strtoupper($zone);
    if (CDC_DS::isRouterZone($zone) === false) {
        $apiResponse = new APIViewData(1, false, "Unable to detect router vm zone specified: {$zone}");
        $apiResponse->setExtraResponseData('zone', $zone);
        $app->halt(403, $apiResponse->returnJson());
    }
    $results = json_decode(CDC_DS::getRouterInfo($zone), true);
    $apiResponse = new APIViewData(0, $zone, false);
    $apiResponse->setExtraResponseData('routervms', $results);
    $apiResponse->printJson();
})->name('saigon-api-consumer-routervms');
/*
 * Saigon Host Audit Consumer Output
 */
$app->get('/sapi/consumer/hostaudit/:deployment', function ($deployment) use($app) {
    check_deployment_exists($app, $deployment);
    $hostAuditInfo = array();
    $hostAuditInfo = NagTester::getDeploymentHostAuditInfo($deployment);
    if (empty($hostAuditInfo)) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to detect Saigon Host Audit Results");
        $app->halt(403, $apiResponse->returnJson());
    }
    $hostAuditInfo = json_decode($hostAuditInfo);
    $apiResponse = new APIViewData(0, $deployment, false);
    foreach ($hostAuditInfo as $key => $value) {
        $apiResponse->setExtraResponseData($key, $value);
    }
    $apiResponse->printJson();
})->name('saigon-api-consumer-hostaudit');
Пример #4
0
 }
 foreach (array('from', 'to') as $revKey) {
     if (!isset($diffInfo[$revKey]) || empty($diffInfo[$revKey])) {
         $apiResponse = new APIViewData(1, $deployment, "Unable to detect necessary parameter for diff job creation: {$revKey}");
         $app->halt(404, $apiResponse->returnJson());
     }
     validateForbiddenChars($app, $deployment, '/[^0-9]/s', $revKey, $diffInfo[$revKey]);
     if (RevDeploy::existsDeploymentRev($deployment, $diffInfo[$revKey]) === false) {
         $apiResponse = new APIViewData(1, $deployment, "Unable to detect deployment revision specified in datastore for {$revKey} / " . $diffInfo[$revKey]);
         $app->halt(404, $apiResponse->returnJson());
     }
 }
 $islocked = NagTester::getDeploymentDiffLock($deployment, $subdeployment);
 if ($islocked === false) {
     $force = $request->post('force');
     $diffResults = NagTester::getDeploymentDiffInfo($deployment, $subdeployment);
     if ($force !== null) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'type' => 'diff', 'subdeployment' => $subdeployment, 'fromrev' => $diffInfo['from'], 'torev' => $diffInfo['to'], 'shard' => $diffInfo['shard'])), 1024, 0, 900);
         if ($diffInfo['to'] < $diffInfo['from']) {
             $apiResponse = new APIViewData(0, $deployment, "Reverse diff process has been initiated, please change request type to GET to fetch results.");
         } else {
             $apiResponse = new APIViewData(0, $deployment, "Diff process has been initiated, please change request type to GET to fetch results.");
         }
     } elseif (empty($diffResults)) {
         NagPhean::init(BEANSTALKD_SERVER, BEANSTALKD_TUBE, true);
         NagPhean::addJob(BEANSTALKD_TUBE, json_encode(array('deployment' => $deployment, 'type' => 'diff', 'subdeployment' => $subdeployment, 'fromrev' => $diffInfo['from'], 'torev' => $diffInfo['to'], 'shard' => $diffInfo['shard'])), 1024, 0, 900);
         if ($diffInfo['to'] < $diffInfo['from']) {
             $apiResponse = new APIViewData(0, $deployment, "Reverse diff process has been initiated, please change request type to GET to fetch results.");
         } else {
             $apiResponse = new APIViewData(0, $deployment, "Diff 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);
 }