Example #1
0
    if ($contentType == 'application/json') {
        $supNRPECfgInfo = $request->getBody();
        $supNRPECfgInfo = json_decode($supNRPECfgInfo, true);
    } elseif (preg_match("/form-(data|urlencoded)/", $contentType)) {
        $supNRPECfgInfo['location'] = $request->post('location');
        $supNRPECfgInfo['cmds'] = $request->post('cmds');
    }
    // A bit of param validation
    if (!isset($supNRPECfgInfo['location']) || empty($supNRPECfgInfo['location'])) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to detect location parameter (unix path including filename)");
        $app->halt(404, $apiResponse->returnJson());
    }
    // Param manipulation depending on what is detected
    if (is_array($supNRPECfgInfo['cmds'])) {
        $supNRPECfgInfo['cmds'] = implode(',', $supNRPECfgInfo['cmds']);
    }
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentSupNRPECfg($deployment, $deployRev) === true) {
        RevDeploy::modifyDeploymentSupNRPECfg($deployment, $supNRPECfgInfo, $deployRev);
        $msg = "Successfully Modified NRPE Config";
    } else {
        RevDeploy::createDeploymentSupNRPECfg($deployment, $supNRPECfgInfo, $deployRev);
        $msg = "Successfully Created NRPE Config";
    }
    $supNRPECfgInfo = RevDeploy::getDeploymentNRPECfg($deployment, $deployRev);
    $fileContents = NRPECreate::buildSupNRPEFile($deployment, $deployRev, $supNRPECfgInfo);
    $apiResponse = new APIViewData(0, $deployment, $msg);
    $apiResponse->setExtraResponseData('md5', md5($fileContents));
    $apiResponse->printJson();
})->name('saigon-api-create-sup-nrpe-cfg');
Example #2
0
 /**
  * _getSupNRPECfg - get supplemental nrpe config file 
  * 
  * @param mixed $deployment 
  * @param mixed $revision 
  *
  * @static
  * @access private
  * @return void
  */
 private static function _getSupNRPECfg($deployment, $revision)
 {
     $results = "";
     if (RevDeploy::existsDeploymentSupNRPECfg($deployment, $revision) !== false) {
         $supnrpecfgInfo = RevDeploy::getDeploymentSupNRPECfg($deployment, $revision);
         $results = NRPECreate::buildSupNRPEFile($deployment, $revision, $supnrpecfgInfo);
         return $results;
     }
     return $results;
 }
Example #3
0
        $viewData->b64 = "";
        $viewData->location = "";
        $viewData->md5 = "";
        $viewData->plugins = $plugins;
    } elseif (!empty($nrpeCfgInfo) && empty($plugins)) {
        $msg = NRPECreate::buildSupNRPEFile($deployment, $deployrev, $nrpeCfgInfo);
        $viewData->b64 = base64_encode($msg);
        $viewData->location = $nrpeCfgInfo['location'];
        $viewData->md5 = md5($msg);
        $viewData->plugins = array();
    } else {
        foreach ($plugins as $plugin => $pArray) {
            unset($plugins[$plugin]['desc']);
            unset($plugins[$plugin]['deployment']);
        }
        $msg = NRPECreate::buildSupNRPEFile($deployment, $deployrev, $nrpeCfgInfo);
        $viewData->b64 = base64_encode($msg);
        $viewData->location = $nrpeCfgInfo['location'];
        $viewData->md5 = md5($msg);
        $viewData->plugins = $plugins;
    }
    echo json_encode($viewData);
})->via('GET', 'POST');
$app->map('/api/getNRPEPlugin/:deployment/:plugins', function ($deployment, $plugins) use($app) {
    check_deployment_exists($app, $deployment);
    $deployrev = RevDeploy::getDeploymentRev($deployment);
    if (preg_match('/,/', $plugins)) {
        $tmpplugins = preg_split('/,/', $plugins);
        $results = array();
        foreach ($tmpplugins as $plugin) {
            $plugindata = RevDeploy::getCommonMergedDeploymentNRPEPlugin($deployment, $plugin, $deployrev);
 public function supshow()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('sup_nrpe_cfg_error');
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     if (RevDeploy::existsDeploymentSupNRPECfg($deployment, $modrevision) !== false) {
         $supnrpecfgInfo = RevDeploy::getDeploymentSupNRPECfg($deployment, $modrevision);
         $filecontents = NRPECreate::buildSupNRPEFile($deployment, $modrevision, $supnrpecfgInfo);
         $viewData->md5 = md5($filecontents);
         $viewData->location = $supnrpecfgInfo['location'];
         $viewData->msg = $filecontents;
         $viewData->deployment = $deployment;
         $this->sendResponse('sup_nrpe_cfg_output', $viewData);
     }
     $viewData->header = $this->getErrorHeader('sup_nrpe_cfg_error');
     $viewData->error = 'No Supplemental NRPE Config File Found';
     $this->sendError('generic_error', $viewData);
 }
Example #5
0
    $nrpeCfgInfo = RevDeploy::getDeploymentSupNRPECfg($deployment, $deployRev);
    $plugins = RevDeploy::getCommonMergedDeploymentSupNRPEPluginsMetaData($deployment, $deployRev);
    if (empty($nrpeCfgInfo) && empty($plugins)) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to detect supplemental nrpe config information for deployment: {$deployment}");
        $app->halt(403, $apiResponse->returnJson());
    }
    $apiResponse = new APIViewData(0, $deployment, false);
    if (empty($nrpeCfgInfo) && !empty($plugins)) {
        $apiResponse->setExtraResponseData('plugins', $plugins);
    } elseif (!empty($nrpeCfgInfo) && empty($plugins)) {
        $config = NRPECreate::buildSupNRPEFile($deployment, $deployRev, $nrpeCfgInfo);
        $apiResponse->setExtraResponseData('contents', base64_encode($config));
        $apiResponse->setExtraResponseData('location', $nrpeCfgInfo['location']);
        $apiResponse->setExtraResponseData('md5', md5($config));
    } else {
        $config = NRPECreate::buildSupNRPEFile($deployment, $deployRev, $nrpeCfgInfo);
        $apiResponse->setExtraResponseData('contents', base64_encode($config));
        $apiResponse->setExtraResponseData('location', $nrpeCfgInfo['location']);
        $apiResponse->setExtraResponseData('md5', md5($config));
        $apiResponse->setExtraResponseData('plugins', $plugins);
    }
    $apiResponse->printJson();
})->name('saigon-api-consumer-supplemental-nrpe-config');
/*
 * Saigon NRPE Plugin Routines
 */
$app->get('/sapi/consumer/nrpeplugin/:deployment/:plugins', function ($deployment, $plugins) use($app) {
    check_deployment_exists($app, $deployment);
    $deployRev = RevDeploy::getDeploymentRev($deployment);
    if (preg_match('/,/', $plugins)) {
        $tmpplugins = preg_split('/,/', $plugins);
Example #6
0
        $app->halt(404, $apiResponse->returnJson());
    } elseif (!isset($nrpeCfgInfo['allowed_hosts']) || empty($nrpeCfgInfo['allowed_hosts'])) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to detect allowed_hosts parameter (hosts allowed to connect to service)");
        $app->halt(404, $apiResponse->returnJson());
    } elseif (!isset($nrpeCfgInfo['cmds']) || empty($nrpeCfgInfo['cmds'])) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to detect cmds parameter (commands to activate in nrpe config)");
        $app->halt(404, $apiResponse->returnJson());
    }
    // Param manipulation depending on what is detected
    if (is_array($nrpeCfgInfo['cmds'])) {
        $nrpeCfgInfo['cmds'] = implode(',', $nrpeCfgInfo['cmds']);
    }
    if (!isset($nrpeCfgInfo['include_dir']) || empty($nrpeCfgInfo['include_dir'])) {
        unset($nrpeCfgInfo['include_dir']);
    }
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentNRPECfg($deployment, $deployRev) === true) {
        RevDeploy::modifyDeploymentNRPECfg($deployment, $nrpeCfgInfo, $deployRev);
        $msg = "Successfully Modified NRPE Config";
    } else {
        RevDeploy::createDeploymentNRPECfg($deployment, $nrpeCfgInfo, $deployRev);
        $msg = "Successfully Created NRPE Config";
    }
    unset($nrpeCfgInfo);
    $nrpeCfgInfo = RevDeploy::getDeploymentNRPECfg($deployment, $deployRev);
    $fileContents = NRPECreate::buildNRPEFile($deployment, $deployRev, $nrpeCfgInfo);
    $apiResponse = new APIViewData(0, $deployment, $msg);
    $apiResponse->setExtraResponseData('md5', md5($fileContents));
    $apiResponse->printJson();
})->name('saigon-api-create-nrpe-cfg');