/** * init - initialize the connection to beanstalkd * * @param mixed $server server ip to connect too * @param mixed $defaultTube specify a default tube to watch * @param bool $ignoreDefault ignore the 'default' tube * * @access public * @return void */ public static function init($server, $defaultTube = false, $ignoreDefault = false) { if (self::$init === false) { self::$pheanstalk = new Pheanstalk_Pheanstalk($server); if ($ignoreDefault === true && $defaultTube !== false) { if (preg_match('/,/', $defaultTube)) { $tubes = preg_split("/\\s?,\\s?/", $defaultTube); foreach ($tubes as $tube) { self::$pheanstalk->watch($tube); } self::$pheanstalk->ignore('default'); } else { self::$pheanstalk->watch($defaultTube)->ignore('default'); } } else { if ($ignoreDefault === false && $defaultTube !== false) { if (preg_match('/,/', $defaultTube)) { $tubes = preg_split("/\\s?,\\s?/", $defaultTube); foreach ($tubes as $tube) { self::$pheanstalk->watch($tube); } } else { self::$pheanstalk->watch($defaultTube); } } } self::$init = true; } return; }
} else { $apiResponse = new APIViewData(1, $deployment, "Unable to detect server parameter (nagios server to submit results too)"); $app->halt(404, $apiResponse->returnJson()); } } else { $nagiosServer = $eventInfo['server']; } $msg = $eventInfo['host'] . ","; if ($type == 'service') { $msg .= $eventInfo['service'] . ","; } $msg .= $eventInfo['exitcode'] . "," . $eventInfo['output']; $eventSubmission = API_EVENT_SUBMISSION; if ($eventSubmission == 'enqueue') { NagPhean::init(BEANSTALKD_SERVER, 'events', true); NagPhean::addJob('events', json_encode(array('server' => $nagiosServer, 'type' => 'nsca', 'data' => $msg)), 1024, 0, 10); $apiResponse = new APIViewData(0, $deployment, $msg); $apiResponse->setExtraResponseData('eventsubmission', $eventSubmission); $apiResponse->printJson(); } else { $nscabin = '/usr/sbin/send_nsca'; if (file_exists($nscabin)) { shell_exec("echo {$msg} | {$nscabin} -H {$nagiosServer} -d , -c /etc/nagios/send_nsca.cfg"); $apiResponse = new APIViewData(0, $deployment, $msg); $apiResponse->setExtraResponseData('eventsubmission', $eventSubmission); $apiResponse->printJson(); } else { $apiResponse = new APIViewData(1, $deployment, "Unable to detect /usr/sbin/send_nsca binary needed for communication"); $app->halt(404, $apiResponse->returnJson()); } }
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 (isset($diffResults['fromrev']) && $diffResults['fromrev'] != $diffInfo['from']) { 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 (isset($diffResults['torev']) && $diffResults['torev'] != $diffInfo['to']) { 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."); } } else { $apiResponse = new APIViewData(1, $deployment, "Diff process initiation failed, revisions match what was asked for less than a minutes ago, add force=1 to params to initiate job forcefully."); $app->halt(404, $apiResponse->returnJson()); } } else { $apiResponse = new APIViewData(2, $deployment, "Job is still processing, change request type to GET to fetch results."); } $apiResponse->printJson(); })->name('saigon-api-configs-create-diff'); /*
public function build_nrpe_rpm() { $viewData = new ViewData(); $this->checkGroupAuth(SUPERMEN); $deployment = $this->getDeployment('deployment_error'); $deployInfo = RevDeploy::getDeploymentInfo($deployment); if (BUILD_NRPERPM === true) { if ($deployInfo['deploystyle'] == 'both' || $deployInfo['deploystyle'] == 'nrpe') { $filecontents = NRPERpm::createSpec($deployment); NagPhean::init(BEANSTALKD_SERVER, 'nrperpm', true); NagPhean::addJob('nrperpm', json_encode(array('deployment' => $deployment, 'data' => $filecontents)), 1024, 0, 60); } $viewData->status = "success"; } else { $viewData->status = "inactive"; } $this->sendResponse('deployment_build_nrpe_rpm', $viewData); }