/**
  * write - write resource config information to datastore 
  * 
  * @access public
  * @return void
  */
 public function write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('resource_cfg_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $cfgDelete = $this->getParam('delete');
     if ($cfgDelete == 1) {
         RevDeploy::deleteDeploymentResourceCfg($deployment, $modrevision);
         $viewData->deployment = $deployment;
         $this->sendResponse('resource_cfg_delete', $viewData);
     }
     $resources = array();
     for ($i = 1; $i <= 32; $i++) {
         $key = "USER" . $i;
         $value = $this->getParam($key);
         if ($value !== false) {
             $resources[$key] = base64_encode($value);
         }
     }
     RevDeploy::writeDeploymentResourceCfg($deployment, $resources, $modrevision);
     $viewData->deployment = $deployment;
     $this->sendResponse('resource_cfg_write', $viewData);
 }
 /**
  * menu - display menu of site based on deployment specified
  * 
  * @access public
  * @return void
  */
 public function menu()
 {
     $viewData = new ViewData();
     $deployment = $this->getParam('deployment');
     if ($deployment === false) {
         $viewData->header = $this->getErrorHeader('site_error');
         $viewData->error = 'Unable to detect deployment to present menu for selected option ' . $deployment;
         $this->sendError('generic_error', $viewData);
     } else {
         if ($deployment == '----') {
             exit;
         } else {
             if ($deployment == 'common') {
                 if (($return = $this->checkGroupAuth(SUPERMEN, true)) === false) {
                     $viewData->header = $this->getErrorHeader('site_error');
                     $viewData->error = 'Access Prohibited: Unable to display deployment information for common.';
                     $this->sendError('generic_error', $viewData);
                 }
             } else {
                 if (($return = $this->checkGroupAuth($deployment, true)) === false) {
                     $viewData->header = $this->getErrorHeader('site_error');
                     $viewData->error = 'Access Prohibited: Unable to display deployment information for ' . $deployment;
                     $this->sendError('generic_error', $viewData);
                 }
             }
         }
     }
     $viewData->superuser = $this->checkGroupAuth(SUPERMEN, true);
     $viewData->deployment = $deployment;
     $viewData->deploysettings = RevDeploy::getDeploymentMiscSettings($deployment);
     $this->sendResponse('site_menu', $viewData);
 }
Exemple #3
0
function check_deployment_exists($app, $deployment)
{
    if (RevDeploy::existsDeployment($deployment) === false) {
        $apiResponse = new APIViewData(1, false, "Unable to detect deployment specified: {$deployment}");
        $app->halt(404, $apiResponse->returnJson());
    }
    return true;
}
 public static function init()
 {
     /* Initial Redis Information */
     if (self::$init === false) {
         NagRedis::init();
         self::$log = new NagLogger();
         self::$init = true;
     }
     return;
 }
 public function checkAuth($deployment)
 {
     $ldapGroup = RevDeploy::getDeploymentAuthGroup($deployment);
     $supermen = SUPERMEN;
     if (!isset($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_USER'])) {
         return false;
     } elseif (!isset($_SERVER['PHP_AUTH_PW']) || empty($_SERVER['PHP_AUTH_PW'])) {
         return false;
     }
     $user = $_SERVER['PHP_AUTH_USER'];
     $pass = $_SERVER['PHP_AUTH_PW'];
     $return = false;
     if (preg_match('/,/', $ldapGroup)) {
         $return = $this->inGroup($user, $pass, $ldapGroup, 'people');
         if ($return === true) {
             return true;
         }
         // Check to see if they are a service account
         $return = $this->inGroup($user, $pass, $ldapGroup, 'service accounts');
         if ($return === true) {
             return true;
         }
         // Check and see if they are a super user
         $groups = preg_split('/\\s?,\\s?/', $ldapGroup);
         if (!in_array($supermen, $groups)) {
             $return = $this->inGroup($user, $pass, $supermen, 'people');
             if ($return === true) {
                 return true;
             }
             return false;
         }
         return false;
     } else {
         $return = $this->inGroup($user, $pass, $ldapGroup, 'people');
         if ($return === true) {
             return true;
         }
         // Check to see if they are a service account
         $return = $this->inGroup($user, $pass, $ldapGroup, 'service accounts');
         if ($return === true) {
             return true;
         }
         // Check and see if they are a super user
         if ($ldapGroup != $supermen) {
             $return = $this->inGroup($user, $pass, $supermen, 'people');
             if ($return === true) {
                 return true;
             }
             return false;
         }
         return false;
     }
 }
 /**
  * buildNRPECmdLines 
  * 
  * @param mixed $deployment 
  * @param mixed $revision 
  * @param array $cherrypick 
  * @static
  * @access public
  * @return void
  */
 public static function buildNRPECmdLines($deployment, $revision, array $cherrypick = array())
 {
     $nrpecmds = RevDeploy::getCommonMergedDeploymentNRPECmds($deployment, $revision);
     if (!empty($nrpecmds)) {
         $results = array();
         if (empty($cherrypick)) {
             foreach ($nrpecmds as $nrpecmd => $nrpecmdInfo) {
                 $cmdline = "command[{$nrpecmd}]=" . base64_decode($nrpecmdInfo['cmd_line']);
                 $results[$nrpecmd] = $cmdline;
             }
         } else {
             foreach ($nrpecmds as $nrpecmd => $nrpecmdInfo) {
                 if (!in_array($nrpecmd, $cherrypick)) {
                     continue;
                 }
                 $cmdline = "command[{$nrpecmd}]=" . base64_decode($nrpecmdInfo['cmd_line']);
                 $results[$nrpecmd] = $cmdline;
             }
         }
         ksort($results);
         return $results;
     }
     return array();
 }
    } elseif (preg_match_all('/[^\\w.-\\s]/s', $serviceGroupsInfo['alias'], $forbidden)) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to use service groups alias specified, detected forbidden characters " . implode('', array_unique($forbidden[0])));
        $app->halt(404, $apiResponse->returnJson());
    }
    $serviceGroupsInfo = servicegroup_validate($app, $deployment, $serviceGroupsInfo);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentSvcGroup($deployment, $serviceGroupsInfo['name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentSvcGroup($deployment, $serviceGroupsInfo['name'], $serviceGroupsInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Service Group " . $serviceGroupsInfo['name']);
    } else {
        RevDeploy::createDeploymentSvcGroup($deployment, $serviceGroupsInfo['name'], $serviceGroupsInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Service Group " . $serviceGroupsInfo['name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-service-groups');
$app->delete('/sapi/servicegroup/:deployment/:servicegroup', function ($deployment, $servicegroup) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $servicegroup)) {
        $servicegroups = preg_split('/\\s?,\\s?/', $servicegroup);
        foreach ($servicegroups as $stemp) {
            RevDeploy::deleteDeploymentSvcGroup($deployment, $stemp, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentSvcGroup($deployment, $servicegroup, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Service Groups: {$servicegroup}");
    $apiResponse->printJson();
})->name('saigon-api-delete-service-groups');
Exemple #8
0
            case "sleep_time":
                validateInterval($app, $deployment, $key, $nagiosConfigInfo[$key], 0, 5);
                break;
            case "host_perfdata_file_mode":
            case "service_perfdata_file_mode":
                validateOptions($app, $deployment, $key, $nagiosConfigInfo[$key], array('w', 'a', 'p'));
                break;
            default:
                break;
        }
    }
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentNagiosCfg($deployment, $deployRev) === true) {
        RevDeploy::modifyDeploymentNagiosCfg($deployment, $nagiosConfigInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Nagios Config");
    } else {
        RevDeploy::createDeploymentNagiosCfg($deployment, $nagiosConfigInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Nagios Config");
    }
    $apiResponse->printJson();
})->name('saigon-api-create-nagios-config');
$app->delete('/sapi/configs/:deployment/nagios', function ($deployment) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    RevDeploy::deleteDeploymentNagiosCfg($deployment, $deployRev);
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Nagios Config");
    $apiResponse->printJson();
})->name('saigon-api-delete-nagios-config');
Exemple #9
0
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect an appropriate contact parameter, email or pager");
            $app->halt(404, $apiResponse->returnJson());
        }
    }
    $contactInfo = contact_validate($app, $deployment, $contactInfo);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentContact($deployment, $contactInfo['contact_name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentContact($deployment, $contactInfo['contact_name'], $contactInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Contact  " . $contactInfo['contact_name']);
    } else {
        RevDeploy::createDeploymentContact($deployment, $contactInfo['contact_name'], $contactInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Contact  " . $contactInfo['contact_name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-contact');
$app->delete('/sapi/contact/:deployment/:contact', function ($deployment, $contact) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $contact)) {
        $contacts = preg_split('/\\s?,\\s?/', $contact);
        foreach ($contacts as $ctemp) {
            RevDeploy::deleteDeploymentContact($deployment, $ctemp, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentContact($deployment, $contact, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Contact(s): {$contact}");
    $apiResponse->printJson();
})->name('saigon-api-delete-contact');
 private static function copyNagiosPlugins($deployment, $revision, array $nagiosPlugins)
 {
     if (self::$init === false) {
         self::init();
     }
     foreach ($nagiosPlugins as $plugin => $pArray) {
         RevDeploy::createDeploymentNagiosPlugin($deployment, $plugin, $pArray, $revision);
     }
 }
 public function write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('nagios_cfg_error');
     $this->checkGroupAuth(SUPERMEN);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $cfgDelete = $this->getParam('delete');
     if ($cfgDelete == 1) {
         RevDeploy::deleteDeploymentNagiosCfg($deployment, $modrevision);
         $viewData->deployment = $deployment;
         $this->sendResponse('nagios_cfg_delete', $viewData);
     }
     $cfgInfo = $this->fetchConfigInfo($deployment);
     if (isset($_SESSION[$deployment]['brokermods']) && is_array($_SESSION[$deployment]['brokermods'])) {
         $i = 0;
         foreach ($_SESSION[$deployment]['brokermods'] as $md5 => $b64) {
             $cfgInfo['broker_module_' . $i] = $b64;
             $i++;
         }
     }
     RevDeploy::writeDeploymentNagiosCfg($deployment, $cfgInfo, $modrevision);
     unset($_SESSION[$deployment]['brokermods']);
     $viewData->deployment = $deployment;
     $this->sendResponse('nagios_cfg_write', $viewData);
 }
                $app->halt(404, $apiResponse->returnJson());
            }
        }
    }
    $serviceTemplateInfo = servicetemplate_validate($app, $deployment, $serviceTemplateInfo);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentSvcTemplate($deployment, $serviceTemplateInfo['name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentSvcTemplate($deployment, $serviceTemplateInfo['name'], $serviceTemplateInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Service Template " . $serviceTemplateInfo['name']);
    } else {
        RevDeploy::createDeploymentSvcTemplate($deployment, $serviceTemplateInfo['name'], $serviceTemplateInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Service Template " . $serviceTemplateInfo['name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-service-template');
$app->delete('/sapi/servicetemplate/:deployment/:servicetemplate', function ($deployment, $servicetemplate) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $servicetemplate)) {
        $servicetemplates = preg_split('/\\s?,\\s?/', $servicetemplate);
        foreach ($servicetemplates as $stemp) {
            RevDeploy::deleteDeploymentSvcTemplate($deployment, $stemp, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentSvcTemplate($deployment, $servicetemplate, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Service Template(s): {$servicetemplate}");
    $apiResponse->printJson();
})->name('saigon-api-delete-service-template');
    $serviceDependencyInfo = servicedependency_validate($app, $deployment, $serviceDependencyInfo);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentSvcDependency($deployment, $serviceDependencyInfo['name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentSvcDependency($deployment, $serviceDependencyInfo['name'], $serviceDependencyInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Service Dependency " . $serviceDependencyInfo['name']);
    } else {
        RevDeploy::createDeploymentSvcDependency($deployment, $serviceDependencyInfo['name'], $serviceDependencyInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Service Dependency " . $serviceDependencyInfo['name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-service-dependency');
$app->delete('/sapi/servicedependency/:deployment/:servicedependency', function ($deployment, $servicedependency) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $servicedependency)) {
        $servicedependencys = preg_split('/\\s?,\\s?/', $servicedependency);
        foreach ($servicedependencys as $stemp) {
            RevDeploy::deleteDeploymentSvcDependency($deployment, $stemp, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentSvcDependency($deployment, $servicedependency, $deployRev);
    }
    if (preg_match('/,/', $servicedependency)) {
        $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Service Dependencies: {$servicedependency}");
    } else {
        $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Service Dependency: {$servicedependency}");
    }
    $apiResponse->printJson();
})->name('saigon-api-delete-service-dependency');
Exemple #14
0
            $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);
    if (preg_match('/,/', $nrpeCmd)) {
        $results = array();
        $cmds = preg_split('/\\s?,\\s?/', $nrpeCmd);
        foreach ($cmds as $cmd) {
            RevDeploy::deleteDeploymentNRPECmd($deployment, $cmd, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentNRPECmd($deployment, $nrpeCmd, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed NRPE Command(s): {$nrpeCmd}");
    $apiResponse->printJson();
})->name('saigon-api-delete-nrpe-cmd');
Exemple #15
0
            $commandData = RevDeploy::getCommonMergedDeploymentCommand($deployment, $command, $deployRev);
        } else {
            $commandData = RevDeploy::getDeploymentCommand($deployment, $command, $deployRev);
        }
        if ($commandData !== false) {
            $apiResponse = new APIViewData(0, $deployment, false);
            $apiResponse->setExtraResponseData('command', $commandData);
            $apiResponse->printJson();
        } else {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect command specified: {$command}");
            $app->halt(404, $apiResponse->returnJson());
        }
    }
})->name('saigon-api-get-command');
$app->delete('/sapi/command/:deployment/:command', function ($deployment, $command) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $command)) {
        $results = array();
        $cmds = preg_split('/\\s?,\\s?/', $command);
        foreach ($cmds as $cmd) {
            RevDeploy::deleteDeploymentCommand($deployment, $cmd, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentCommand($deployment, $command, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Command(s): {$command}");
    $apiResponse->printJson();
})->name('saigon-api-delete-command');
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('timeperiod_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $timeName = $this->getParam('tpName');
     $tpArray = $_SESSION[$deployment]['timeperiods'];
     $timeInfo = $this->fetchTimeperiodInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentTimeperiod($deployment, $timeName, $modrevision) === true) {
         $viewData->error = 'Timeperiod information exists for ' . $timeName . ' in ' . $deployment . ' Deployment';
         $viewData->timeInfo = $timeInfo;
         $viewData->action = 'copy_write';
         $this->sendResponse('timeperiod_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentTimeperiod($deployment, $timeName, $timeInfo, $tpArray, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('timeperiod_error');
         $viewData->error = 'Unable to write timeperiod information for ' . $timeName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     unset($_SESSION[$deployment]['timeperiods']);
     $viewData->deployment = $deployment;
     $viewData->timeperiod = $timeName;
     $this->sendResponse('timeperiod_write', $viewData);
 }
 public function sup_import_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('sup_nrpe_cfg_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $filelocation = $this->getParam('location');
     if ($filelocation === false) {
         $viewData->header = $this->getErrorHeader('sup_nrpe_cfg_error');
         $viewData->error = 'Unable to read file location, please ensure file location was specified';
         $this->sendError('generic_error', $viewData);
     }
     $filecontents = $this->fetchUploadedFile('file');
     if ($filecontents === false) {
         $viewData->header = $this->getErrorHeader('sup_nrpe_cfg_error');
         $viewData->error = 'Unable to read imported file, please ensure file was appended';
         $this->sendError('generic_error', $viewData);
     }
     $filemeta = NagImport::processSupNRPECfg($filecontents);
     if (empty($filemeta)) {
         $viewData->header = $this->getErrorHeader('sup_nrpe_cfg_error');
         $viewData->error = 'Unable to read imported file, problem parsing command information';
         $this->sendError('generic_error', $viewData);
     }
     RevDeploy::importDeploymentSupNRPECfg($deployment, $modrevision, $filelocation, $filemeta);
     $viewData->deployment = $deployment;
     $this->sendResponse('sup_nrpe_cfg_import_write', $viewData);
 }
Exemple #18
0
    } else {
        $plugindata = RevDeploy::getDeploymentNagiosPlugin($deployment, $plugins, $deployrev);
        if (empty($plugindata)) {
            $commonrev = RevDeploy::getDeploymentRev('common');
            $plugindata = RevDeploy::getDeploymentNagiosPlugin('common', $plugins, $commonrev);
            if (empty($plugindata)) {
                $apiResponse = new APIViewData(1, $deployment, "Unable to detect specified nagios plugin: {$plugins}");
                $app->halt(403, $apiResponse->returnJson());
            }
        }
        unset($plugindata['deployment']);
        unset($plugindata['desc']);
        $results[$plugins] = $plugindata;
        echo json_encode($results);
        return;
    }
})->via('GET', 'POST');
$app->map('/api/getNagiosPlugins/:deployment', function ($deployment) use($app) {
    check_deployment_exists($app, $deployment);
    $deployrev = RevDeploy::getDeploymentRev($deployment);
    $plugindata = RevDeploy::getCommonMergedDeploymentNagiosPluginsMetaData($deployment, $deployrev);
    if (empty($plugindata)) {
        $apiResponse = new APIViewData(1, $deployment, "Unable to fetch plugins for {$deployment}");
        $app->halt(403, $apiResponse->returnJson());
    }
    foreach ($plugindata as $plugin => $pArray) {
        unset($plugindata[$plugin]['deployment']);
    }
    echo json_encode($plugindata);
    return;
})->via('GET', 'POST');
Exemple #19
0
 /**
  * _getPlugins - get plugins for nagios / nrpe and return their contents 
  * 
  * @param mixed $mode       mode driving where the plugins are fetched from
  * @param mixed $deployment deployment we are referencing
  * @param mixed $revision   revision we are referencing
  * @param mixed $plugins    plugins we are referencing
  *
  * @static
  * @access private
  * @return void
  */
 private static function _getPlugins($mode, $deployment, $revision, $plugins)
 {
     $results = array();
     foreach ($plugins as $plugin) {
         if ($mode == 'nrpe-core') {
             $tmpInfo = RevDeploy::getDeploymentNRPEPluginFileContents($deployment, $plugin, $revision);
         } elseif ($mode == 'nrpe-sup') {
             $tmpInfo = RevDeploy::getDeploymentSupNRPEPluginFileContents($deployment, $plugin, $revision);
         } elseif ($mode == 'nagios') {
             $tmpInfo = RevDeploy::getDeploymentNagiosPluginFileContents($deployment, $plugin, $revision);
         }
         if ($tmpInfo !== false) {
             $results[$plugin] = base64_decode($tmpInfo);
         } else {
             $results[$plugin] = "";
         }
     }
     return $results;
 }
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect required parameter {$rkey} " . serviceescalation_rkeyMessage($rkey));
            $app->halt(404, $apiResponse->returnJson());
        }
    }
    $serviceEscalationInfo = serviceescalation_validate($app, $deployment, $serviceEscalationInfo);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentSvcEscalation($deployment, $serviceEscalationInfo['name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentSvcEscalation($deployment, $serviceEscalationInfo['name'], $serviceEscalationInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Service Escalation " . $serviceEscalationInfo['name']);
    } else {
        RevDeploy::createDeploymentSvcEscalation($deployment, $serviceEscalationInfo['name'], $serviceEscalationInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Service Escalation " . $serviceEscalationInfo['name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-service-escalation');
$app->delete('/sapi/serviceescalation/:deployment/:serviceescalation', function ($deployment, $serviceescalation) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $serviceescalation)) {
        $serviceescalations = preg_split('/\\s?,\\s?/', $serviceescalation);
        foreach ($serviceescalations as $stemp) {
            RevDeploy::deleteDeploymentSvcEscalation($deployment, $stemp, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentSvcEscalation($deployment, $serviceescalation, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Service Escalation(s): {$serviceescalation}");
    $apiResponse->printJson();
})->name('saigon-api-delete-service-escalation');
            $app->halt(404, $apiResponse->returnJson());
        }
    } else {
        $pluginData = RevDeploy::getDeploymentNagiosPlugin($deployment, $nagiosPlugin, $deployRev);
        if ($pluginData !== false) {
            $apiResponse = new APIViewData(0, $deployment, false);
            $apiResponse->setExtraResponseData('plugin', $pluginData);
            $apiResponse->printJson();
        } else {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect nagios plugin specified: {$nagiosPlugin}");
            $app->halt(404, $apiResponse->returnJson());
        }
    }
})->name('saigon-api-get-nagios-plugin');
$app->delete('/sapi/nagiosplugin/:deployment/:nagiosplugin', function ($deployment, $nagiosPlugin) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $nagiosPlugin)) {
        $results = array();
        $plugins = preg_split('/\\s?,\\s?/', $nagiosPlugin);
        foreach ($plugins as $plugin) {
            RevDeploy::deleteDeploymentNagiosPlugin($deployment, $plugin, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentNagiosPlugin($deployment, $nagiosPlugin, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Nagios Plugin(s): {$nagiosPlugin}");
    $apiResponse->printJson();
})->name('saigon-api-delete-nagios-plugin');
            $app->halt(404, $apiResponse->returnJson());
        }
    } else {
        $pluginData = RevDeploy::getDeploymentNRPEPlugin($deployment, $nrpePlugin, $deployRev);
        if ($pluginData !== false) {
            $apiResponse = new APIViewData(0, $deployment, false);
            $apiResponse->setExtraResponseData('plugin', $pluginData);
            $apiResponse->printJson();
        } else {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect nrpe plugin specified: {$nrpePlugin}");
            $app->halt(404, $apiResponse->returnJson());
        }
    }
})->name('saigon-api-get-nrpe-plugin');
$app->delete('/sapi/nrpeplugin/:deployment/:nrpeplugin', function ($deployment, $nrpePlugin) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $nrpePlugin)) {
        $results = array();
        $plugins = preg_split('/\\s?,\\s?/', $nrpePlugin);
        foreach ($plugins as $plugin) {
            RevDeploy::deleteDeploymentNRPEPlugin($deployment, $plugin, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentNRPEPlugin($deployment, $nrpePlugin, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed NRPE Plugin(s): {$nrpePlugin}");
    $apiResponse->printJson();
})->name('saigon-api-delete-nrpe-plugin');
 /**
  * write - issue cgi config write to datastore 
  * 
  * @access public
  * @return void
  */
 public function write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('cgi_cfg_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $cfgDelete = $this->getParam('delete');
     if ($cfgDelete == 1) {
         RevDeploy::deleteDeploymentCgiCfg($deployment, $modrevision);
         $viewData->deployment = $deployment;
         $this->sendResponse('cgi_cfg_delete', $viewData);
     }
     $cfgInfo = $this->_fetchConfigInfo($deployment, $modrevision);
     ksort($cfgInfo);
     RevDeploy::writeDeploymentCgiCfg($deployment, $cfgInfo, $modrevision);
     $viewData->deployment = $deployment;
     $this->sendResponse('cgi_cfg_write', $viewData);
 }
 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);
 }
    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');
                $app->halt(404, $apiResponse->returnJson());
            }
        }
    }
    $contactTemplateInfo = contacttemplate_validate($app, $deployment, $contactTemplateInfo);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentContactTemplate($deployment, $contactTemplateInfo['name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentContactTemplate($deployment, $contactTemplateInfo['name'], $contactTemplateInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Contact Template " . $contactTemplateInfo['name']);
    } else {
        RevDeploy::createDeploymentContactTemplate($deployment, $contactTemplateInfo['name'], $contactTemplateInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Contact Template " . $contactTemplateInfo['name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-contact-template');
$app->delete('/sapi/contacttemplate/:deployment/:contacttemplate', function ($deployment, $contacttemplate) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $contacttemplate)) {
        $contacttemplates = preg_split('/\\s?,\\s?/', $contacttemplate);
        foreach ($contacttemplates as $cttemp) {
            RevDeploy::deleteDeploymentContactTemplate($deployment, $cttemp, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentContactTemplate($deployment, $contacttemplate, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Contact Template(s): {$contacttemplate}");
    $apiResponse->printJson();
})->name('saigon-api-delete-contact-template');
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('svc_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $svcName = $this->getParam('svcName');
     $svcInfo = $this->fetchSvcInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentSvc($deployment, $svcName, $modrevision) === true) {
         $viewData->error = 'Service template information exists for ' . $svcName . ' into ' . $deployment . ' Deployment';
         $viewData->action = 'copy_write';
         $viewData->deployment = $deployment;
         $viewData->svctemplates = RevDeploy::getCommonMergedDeploymentSvcTemplates($deployment, $modrevision);
         $viewData->svcgroups = RevDeploy::getCommonMergedDeploymentSvcGroups($deployment, $modrevision);
         $viewData->svcchkcmds = RevDeploy::getCommonMergedDeploymentCommands($deployment, $modrevision);
         $viewData->timeperiods = RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $modrevision);
         $viewData->contacts = RevDeploy::getCommonMergedDeploymentContacts($deployment, $modrevision);
         $viewData->contactgroups = RevDeploy::getCommonMergedDeploymentContactGroups($deployment, $modrevision);
         $viewData->svcInfo = $svcInfo;
         $this->sendResponse('svc_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentSvc($deployment, $svcName, $svcInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('svc_error');
         $viewData->error = 'Unable to write service tempalte information for ' . $svcName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->svc = $svcName;
     $this->sendResponse('svc_write', $viewData);
 }
 public static function buildDeployment($deployment, $revision = false, $diff = false, $forcebuild = false, $shardposition = false)
 {
     self::checkPerms($deployment);
     self::$deployment = $deployment;
     self::$m_logger = new NagLogger();
     self::deleteDeployment();
     if ($revision === false) {
         /* 
             No revision means we are dealing with a request from a consumer
             so we will fetch Deployment information from Nagios Configurator API
         */
         $response = NagRequest::fetchDeploymentData($deployment, self::getSubDeployment());
         $responseObj = json_decode($response);
         $helper = new NagHelpers();
         $helper->setAliasTemplate($responseObj->miscsettings->aliastemplate);
         $helper->setGlobalNegate($responseObj->miscsettings->deploynegate);
         if (SHARDING === true && $responseObj->miscsettings->ensharding == 'on') {
             $helper->enableSharding($responseObj->miscsettings->shardkey, $responseObj->miscsettings->shardcount, SHARDING_POSITION);
         }
     } else {
         /* 
             A revision means we are dealing with a request from the UI
             so we will fetch Deployment information from Redis store directly
         */
         $response = RevDeploy::getDeploymentData($deployment, $revision, true);
         $responseObj = json_decode($response);
         $helper = new NagHelpers(true);
         $helper->setAliasTemplate($responseObj->miscsettings->aliastemplate);
         $helper->setGlobalNegate($responseObj->miscsettings->deploynegate);
         if ($shardposition !== false) {
             $deploymentInfo = RevDeploy::getDeploymentInfo($deployment);
             $helper->enableSharding($deploymentInfo['shardkey'], $deploymentInfo['shardcount'], $shardposition);
         }
     }
     /* Create Initial Files for Nagios */
     if (!empty($responseObj->timeperiods)) {
         self::createTimeperiodFile($responseObj->timeperiods);
     }
     if (!empty($responseObj->commands)) {
         self::createCommandFile($responseObj->commands);
     }
     if (!empty($responseObj->contacttemplates)) {
         self::createContactTemplateFile($responseObj->contacttemplates);
     }
     if (!empty($responseObj->contacts)) {
         self::createContactFile($responseObj->contacts);
     }
     if (!empty($responseObj->contactgroups)) {
         self::createContactGroupFile($responseObj->contactgroups);
     }
     if (!empty($responseObj->hosttemplates)) {
         self::createHostTemplateFile($responseObj->hosttemplates);
     }
     if (!empty($responseObj->hostgroups)) {
         self::createHostGroupFile($responseObj->hostgroups);
     }
     if (!empty($responseObj->servicetemplates)) {
         self::createServiceTemplateFile($responseObj->servicetemplates);
     }
     if (!empty($responseObj->servicegroups)) {
         self::createServiceGroupFile($responseObj->servicegroups);
     }
     if (!empty($responseObj->resourcecfg)) {
         self::createResourceConfigFile($responseObj->resourcecfg);
     }
     if (!empty($responseObj->cgicfg)) {
         self::createCgiConfigFile($responseObj->cgicfg);
     }
     if (!empty($responseObj->modgearmancfg)) {
         self::createModgearmanConfigFile($responseObj->modgearmancfg);
     }
     if (!empty($responseObj->nagioscfg)) {
         self::createNagiosConfigFile($responseObj->nagioscfg);
     }
     /* Initialize Helper object for storing information for hosts and services */
     if (!empty($responseObj->hostsearches)) {
         if ($diff === true && !empty(self::$m_localcache)) {
             foreach (self::$m_localcache as $module => $items) {
                 foreach ($items as $host => $hostData) {
                     $helper->importHost($host, $hostData);
                 }
             }
         } else {
             foreach ($responseObj->hostsearches as $md5Key => $hsObj) {
                 if (($subdeployment = self::getSubDeployment()) !== false) {
                     if (isset($hsObj->subdeployment) && $hsObj->subdeployment != $subdeployment) {
                         continue;
                     }
                 }
                 $module = $hsObj->location;
                 if (preg_match("/^RS-(\\w+)-(\\w+)\$/", $module)) {
                     $modObj = new RightScale();
                 } elseif (preg_match("/^AWSEC2-(\\w+)-(\\w+)\$/", $module)) {
                     $modObj = new AWSEC2();
                 } else {
                     $modObj = new $module();
                 }
                 $hostInfo = $modObj->getSearchResults($hsObj);
                 if (empty($hostInfo)) {
                     self::$m_logger->addToLog("Empty Results Detected for {$hsObj->location} : {$hsObj->srchparam}");
                     continue;
                 }
                 foreach ($hostInfo as $host => $hostData) {
                     $helper->importHost($host, $hostData);
                     if ($diff === true) {
                         if (!isset(self::$m_localcache[$module]) || !is_array(self::$m_localcache[$module])) {
                             self::$m_localcache[$module] = array();
                         }
                         self::$m_localcache[$module][$host] = $hostData;
                     }
                 }
             }
         }
     }
     if (!empty($responseObj->statichosts)) {
         foreach ($responseObj->statichosts as $encIP => $tmpObj) {
             if (($subdeployment = self::getSubDeployment()) !== false) {
                 if (isset($tmpObj->subdeployment) && $tmpObj->subdeployment != $subdeployment) {
                     continue;
                 }
             }
             $helper->importStaticHost(NagMisc::recursive_object_to_array($tmpObj));
         }
     }
     /* Import Service and Node => Service Pointer Data */
     if ($forcebuild === false) {
         if (empty($responseObj->services)) {
             return "Initial Service Data was Empty";
         } elseif (empty($responseObj->nodetemplates)) {
             return "Initial NodeTemplate Data was Empty";
         }
     }
     $helper->scrubHosts();
     if (!empty($responseObj->services)) {
         $helper->importServices($responseObj->services);
     }
     if (!empty($responseObj->nodetemplates)) {
         $helper->importNodeTemplate($responseObj->nodetemplates, self::getSubDeployment());
     }
     if (!empty($responseObj->servicedependencies)) {
         $helper->importServiceDependencies($responseObj->servicedependencies);
     }
     if (!empty($responseObj->serviceescalations)) {
         $helper->importServiceEscalations($responseObj->serviceescalations);
     }
     $hostCache = $helper->returnHosts();
     $serviceCache = $helper->returnServices($hostCache);
     $serviceDependencyCache = $helper->returnServiceDependencies($hostCache);
     $serviceEscalationsCache = $helper->returnServiceEscalations($hostCache);
     /* Create core host / service nagios config files */
     if ($forcebuild === false) {
         if (empty($hostCache)) {
             return "Host Cache is Empty, unable to create Host File";
         } elseif (empty($serviceCache)) {
             return "Service Cache is Empty, unable to create Services File";
         }
     }
     if (!empty($hostCache)) {
         self::createHostFile($hostCache);
     }
     if (!empty($serviceCache)) {
         self::createServiceFile($serviceCache);
     }
     if (!empty($serviceDependencyCache)) {
         self::createServiceDependencyFile($serviceDependencyCache);
     }
     if (!empty($serviceEscalationsCache)) {
         self::createServiceEscalationsFile($serviceEscalationsCache);
     }
     return true;
 }
Exemple #29
0
                $app->halt(404, $apiResponse->returnJson());
            }
        }
    }
    $serviceInfo = service_validate($app, $deployment, $serviceInfo);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentSvc($deployment, $serviceInfo['name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentSvc($deployment, $serviceInfo['name'], $serviceInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Service " . $serviceInfo['name']);
    } else {
        RevDeploy::createDeploymentSvc($deployment, $serviceInfo['name'], $serviceInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Service " . $serviceInfo['name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-service');
$app->delete('/sapi/service/:deployment/:service', function ($deployment, $service) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $service)) {
        $services = preg_split('/\\s?,\\s?/', $service);
        foreach ($services as $stemp) {
            RevDeploy::deleteDeploymentSvc($deployment, $stemp, $deployRev);
        }
    } else {
        RevDeploy::deleteDeploymentSvc($deployment, $service, $deployRev);
    }
    $apiResponse = new APIViewData(0, $deployment, "Successfully Removed Service(s): {$service}");
    $apiResponse->printJson();
})->name('saigon-api-delete-service');
 public function view_dynamic_matches()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('ngnt_error');
     $regex = $this->getParam('regex');
     if ($regex === false) {
         $viewData->header = $this->getErrorHeader('ngnt_error');
         $viewData->error = 'Unable to detect regex specified in post params';
         $this->sendError('generic_error', $viewData);
     }
     $nregex = $this->getParam('nregex');
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $hosts = RevDeploy::getDeploymentHosts($deployment);
     $globalnegate = RevDeploy::getDeploymentGlobalNegate($deployment);
     $resulthosts = array();
     foreach ($hosts as $host => $hArray) {
         if ($globalnegate !== false && preg_match("/{$globalnegate}/", $host)) {
             continue;
         }
         if (preg_match("/{$regex}/", $host)) {
             if ($nregex !== false) {
                 if (!preg_match("/{$nregex}/", $host)) {
                     array_push($resulthosts, $host);
                 }
             } else {
                 array_push($resulthosts, $host);
             }
         }
     }
     sort($resulthosts);
     $viewData = $resulthosts;
     $this->sendResponse('ngnt_view_dynamic_matches', $viewData);
 }