예제 #1
0
        foreach ($cmds as $cmd) {
            $cmdData = RevDeploy::getDeploymentNRPECmd($deployment, $cmd, $deployRev);
            if ($cmdData !== false) {
                $results[$cmd] = $cmdData;
            }
        }
        if (!empty($results)) {
            $apiResponse = new APIViewData(0, $deployment, false);
            $apiResponse->setExtraResponseData('commands', $results);
            $apiResponse->printJson();
        } else {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect nrpe command(s) specified: {$nrpeCmd}");
            $app->halt(404, $apiResponse->returnJson());
        }
    } else {
        $cmdData = RevDeploy::getDeploymentNRPECmd($deployment, $nrpeCmd, $deployRev);
        if ($cmdData !== false) {
            $apiResponse = new APIViewData(0, $deployment, false);
            $apiResponse->setExtraResponseData('command', $cmdData);
            $apiResponse->printJson();
        } else {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect nrpe command specified: {$nrpeCmd}");
            $app->halt(404, $apiResponse->returnJson());
        }
    }
})->name('saigon-api-get-nrpe-cmd');
$app->delete('/sapi/nrpecmd/:deployment/:nrpecmd', function ($deployment, $nrpeCmd) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
 public function copy_to_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('nrpe_cmd_error');
     $nrpecmdInfo = $this->fetchNRPECmdInfo($deployment, 'copy_to_write');
     $todeployment = $this->getParam('todeployment');
     if ($todeployment === false) {
         $viewData->error = 'Unable to detect deployment to copy command to';
         $viewData->availdeployments = $this->getDeploymentsAvailToUser();
         $viewData->deployment = $deployment;
         $viewData->nrpecmdInfo = $nrpecmdInfo;
         $viewData->action = 'copy_to_write';
         $this->sendResponse('command_action_stage', $viewData);
     }
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($todeployment);
     $deployRev = RevDeploy::getDeploymentNextRev($deployment);
     $tdRev = RevDeploy::getDeploymentNextRev($todeployment);
     $nrpecmdName = $nrpecmdInfo['cmd_name'];
     $nrpecmdInfo = RevDeploy::getDeploymentNRPECmd($deployment, $nrpecmdName, $deployRev);
     if (RevDeploy::existsDeploymentNRPECmd($todeployment, $nrpecmdName, $tdRev) === true) {
         RevDeploy::modifyDeploymentNRPECmd($todeployment, $nrpecmdName, $nrpecmdInfo, $tdRev);
     } else {
         RevDeploy::createDeploymentNRPECmd($todeployment, $nrpecmdName, $nrpecmdInfo, $tdRev);
     }
     $viewData->deployment = $deployment;
     $viewData->todeployment = $todeployment;
     $viewData->command = $nrpecmdName;
     $this->sendResponse('nrpe_cmd_write', $viewData);
 }