Exemplo n.º 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');
Exemplo n.º 2
0
 public static function copyDeploymentRevision($deployment, $fromrev, $torev)
 {
     if (self::$init === false) {
         self::init();
     }
     self::$m_commonrepo = RevDeploy::getDeploymentCommonRepo($deployment);
     $results = array();
     $results['timeperiods'] = RevDeploy::getCommonMergedDeploymentTimeperiodswData($deployment, $fromrev);
     $results['commands'] = RevDeploy::getCommonMergedDeploymentCommands($deployment, $fromrev, false);
     $results['contacttemplates'] = RevDeploy::getCommonMergedDeploymentContactTemplates($deployment, $fromrev);
     $results['contactgroups'] = RevDeploy::getCommonMergedDeploymentContactGroups($deployment, $fromrev);
     $results['contacts'] = RevDeploy::getCommonMergedDeploymentContacts($deployment, $fromrev);
     $results['hosttemplates'] = RevDeploy::getCommonMergedDeploymentHostTemplates($deployment, $fromrev);
     $results['hostgroups'] = RevDeploy::getCommonMergedDeploymentHostGroups($deployment, $fromrev);
     $results['servicetemplates'] = RevDeploy::getCommonMergedDeploymentSvcTemplates($deployment, $fromrev);
     $results['servicegroups'] = RevDeploy::getCommonMergedDeploymentSvcGroups($deployment, $fromrev);
     $results['servicedependencies'] = RevDeploy::getCommonMergedDeploymentSvcDependencies($deployment, $fromrev);
     $results['serviceescalations'] = RevDeploy::getDeploymentSvcEscalationswInfo($deployment, $fromrev);
     $results['services'] = RevDeploy::getCommonMergedDeploymentSvcs($deployment, $fromrev);
     $results['nodetemplates'] = RevDeploy::getDeploymentNodeTemplateswInfo($deployment, $fromrev);
     $results['resourcecfg'] = RevDeploy::getDeploymentResourceCfg($deployment, $fromrev);
     $results['cgicfg'] = RevDeploy::getDeploymentCgiCfg($deployment, $fromrev);
     $results['modgearmancfg'] = RevDeploy::getDeploymentModgearmanCfg($deployment, $fromrev);
     $results['nagioscfg'] = RevDeploy::getDeploymentNagiosCfg($deployment, $fromrev);
     $results['nrpecmds'] = RevDeploy::getDeploymentNRPECmdswInfo($deployment, $fromrev);
     $results['nrpecfg'] = RevDeploy::getDeploymentNRPECfg($deployment, $fromrev);
     $results['nrpeplugins'] = RevDeploy::getDeploymentNRPEPluginswData($deployment, $fromrev);
     $results['supnrpecfg'] = RevDeploy::getDeploymentSupNRPECfg($deployment, $fromrev);
     $results['supnrpeplugins'] = RevDeploy::getDeploymentSupNRPEPluginswData($deployment, $fromrev);
     $results['nagiosplugins'] = RevDeploy::getDeploymentNagiosPluginswData($deployment, $fromrev);
     foreach ($results as $key => $value) {
         if (empty($value)) {
             continue;
         }
         switch ($key) {
             case 'timeperiods':
                 self::copyTimeperiods($deployment, $torev, $results['timeperiods']);
                 break;
             case 'commands':
                 self::copyCommands($deployment, $torev, $results['commands']);
                 break;
             case 'contacttemplates':
                 self::copyContactTemplates($deployment, $torev, $results['contacttemplates']);
                 break;
             case 'contactgroups':
                 self::copyContactGroups($deployment, $torev, $results['contactgroups']);
                 break;
             case 'contacts':
                 self::copyContacts($deployment, $torev, $results['contacts']);
                 break;
             case 'hosttemplates':
                 self::copyHostTemplates($deployment, $torev, $results['hosttemplates']);
                 break;
             case 'hostgroups':
                 self::copyHostGroups($deployment, $torev, $results['hostgroups']);
                 break;
             case 'servicetemplates':
                 self::copyServiceTemplates($deployment, $torev, $results['servicetemplates']);
                 break;
             case 'servicegroups':
                 self::copyServiceGroups($deployment, $torev, $results['servicegroups']);
                 break;
             case 'servicedependencies':
                 self::copyServiceDependencies($deployment, $torev, $results['servicedependencies']);
                 break;
             case 'serviceescalations':
                 self::copyServiceEscalations($deployment, $torev, $results['serviceescalations']);
                 break;
             case 'services':
                 self::copyServices($deployment, $torev, $results['services']);
                 break;
             case 'nodetemplates':
                 self::copyNodeTemplates($deployment, $torev, $results['nodetemplates']);
                 break;
             case 'resourcecfg':
                 self::copyResourceCfg($deployment, $torev, $results['resourcecfg']);
                 break;
             case 'cgicfg':
                 self::copyCGICfg($deployment, $torev, $results['cgicfg']);
                 break;
             case 'modgearmancfg':
                 self::copyModgearmanCfg($deployment, $torev, $results['modgearmancfg']);
                 break;
             case 'nagioscfg':
                 self::copyNagiosCfg($deployment, $torev, $results['nagioscfg']);
                 break;
             case 'nrpecmds':
                 self::copyNRPECmds($deployment, $torev, $results['nrpecmds']);
                 break;
             case 'nrpecfg':
                 self::copyNRPECfg($deployment, $torev, $results['nrpecfg']);
                 break;
             case 'nrpeplugins':
                 self::copyNRPEPlugins($deployment, $torev, $results['nrpeplugins']);
                 break;
             case 'supnrpecfg':
                 self::copySupNRPECfg($deployment, $torev, $results['supnrpecfg']);
                 break;
             case 'supnrpeplugins':
                 self::copySupNRPEPlugins($deployment, $torev, $results['supnrpeplugins']);
                 break;
             case 'nagiosplugins':
                 self::copyNagiosPlugins($deployment, $torev, $results['nagiosplugins']);
                 break;
             default:
                 break;
         }
     }
 }
Exemplo n.º 3
0
        }
    }
    foreach ($viewData['servicedependencies'] as $key => $infoArray) {
        $inspect = array('execution_failure_criteria', 'notification_failure_criteria');
        foreach ($inspect as $ikey) {
            if (isset($infoArray[$ikey]) && !empty($infoArray[$ikey])) {
                $viewData['servicedependencies'][$key][$ikey] = implode(',', $viewData['servicedependencies'][$key][$ikey]);
            }
        }
    }
    echo json_encode($viewData);
});
$app->map('/api/getNRPECfg/:deployment', function ($deployment) use($app) {
    check_deployment_exists($app, $deployment);
    $deployrev = RevDeploy::getDeploymentRev($deployment);
    $nrpeCfgInfo = RevDeploy::getDeploymentNRPECfg($deployment, $deployrev);
    $plugins = RevDeploy::getCommonMergedDeploymentNRPEPluginsMetaData($deployment, $deployrev);
    $viewData = new ViewData();
    if (empty($nrpeCfgInfo) && empty($plugins)) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to detect nrpe config information for deployment: {$deployment}");
        $app->halt(403, $apiResponse->returnJson());
    } elseif (empty($nrpeCfgInfo) && !empty($plugins)) {
        foreach ($plugins as $plugin => $pArray) {
            unset($plugins[$plugin]['desc']);
            unset($plugins[$plugin]['deployment']);
        }
        $viewData->b64 = "";
        $viewData->location = "";
        $viewData->md5 = "";
        $viewData->plugins = $plugins;
    } elseif (!empty($nrpeCfgInfo) && empty($plugins)) {
Exemplo n.º 4
0
 /**
  * _getNRPECfg - get core nrpe config file 
  * 
  * @param mixed $deployment deployment we are referencing
  * @param mixed $revision   revision we are referencing
  *
  * @static
  * @access private
  * @return void
  */
 private static function _getNRPECfg($deployment, $revision)
 {
     $results = "";
     if (RevDeploy::existsDeploymentNRPECfg($deployment, $revision) !== false) {
         $nrpecfgInfo = RevDeploy::getDeploymentNRPECfg($deployment, $revision);
         $results = NRPECreate::buildNRPEFile($deployment, $revision, $nrpecfgInfo);
         return $results;
     }
     return $results;
 }
 public function show()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('nrpe_cfg_error');
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     if (RevDeploy::existsDeploymentNRPECfg($deployment, $modrevision) !== false) {
         $nrpecfgInfo = RevDeploy::getDeploymentNRPECfg($deployment, $modrevision);
         $filecontents = NRPECreate::buildNRPEFile($deployment, $modrevision, $nrpecfgInfo);
         $viewData->deployment = $deployment;
         $viewData->md5 = md5($filecontents);
         $viewData->location = $nrpecfgInfo['location'];
         $viewData->msg = $filecontents;
         $this->sendResponse('nrpe_cfg_output', $viewData);
     }
     $viewData->header = $this->getErrorHeader('nrpe_cfg_error');
     $viewData->error = 'NRPE Config File for Deployment Specified Does not Exist';
     $this->sendError('generic_error', $viewData);
 }