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);
 }
Exemple #2
0
    check_deployment_exists($app, $deployment);
    $request = $app->request();
    $commonMerge = $request->get('common');
    if ($staged == 1) {
        $revs = RevDeploy::getDeploymentRevs($deployment);
        if ($revs['currrev'] == $revs['nextrev']) {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect staged revision to reference");
            $app->halt(404, $apiResponse->returnJson());
        }
        $deployRev = $revs['nextrev'];
    } else {
        $deployRev = RevDeploy::getDeploymentRev($deployment);
    }
    $apiResponse = new APIViewData(0, $deployment, false);
    if ($commonMerge == 1) {
        $apiResponse->setExtraResponseData('contacts', RevDeploy::getCommonMergedDeploymentContacts($deployment, $deployRev));
    } else {
        $apiResponse->setExtraResponseData('contacts', RevDeploy::getDeploymentContactswInfo($deployment, $deployRev));
    }
    $apiResponse->printJson();
})->name('saigon-api-get-contacts');
$app->get('/sapi/contact/:deployment/:contact(/:staged)', function ($deployment, $contact, $staged = false) use($app) {
    check_deployment_exists($app, $deployment);
    if ($staged == 1) {
        $revs = RevDeploy::getDeploymentRevs($deployment);
        if ($revs['currrev'] == $revs['nextrev']) {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect staged revision to reference");
            $app->halt(404, $apiResponse->returnJson());
        }
        $deployRev = $revs['nextrev'];
    } else {
 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;
         }
     }
 }
 /**
  * stage - load up staging web view
  * 
  * @access public
  * @return void
  */
 public function stage()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('cgi_cfg_error');
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     if (($return = RevDeploy::existsDeploymentCgiCfg($deployment, $modrevision)) === true) {
         $viewData->cgicfg = RevDeploy::getDeploymentCgiCfg($deployment, $modrevision);
     } else {
         $cfg = array();
         $cfg['main_config_file'] = base64_encode('/usr/local/nagios/etc/nagios.cfg');
         $cfg['physical_html_path'] = base64_encode('/usr/local/nagios/share');
         $cfg['url_html_path'] = base64_encode('/nagios');
         $cfg['show_context_help'] = 0;
         $cfg['use_pending_states'] = 1;
         $cfg['use_authentication'] = 1;
         $cfg['use_ssl_authentication'] = 0;
         $cfg['authorized_for_system_information'] = "*";
         $cfg['authorized_for_configuration_information'] = "*";
         $cfg['authorized_for_system_commands'] = "*";
         $cfg['authorized_for_all_services'] = "*";
         $cfg['authorized_for_all_hosts'] = "*";
         $cfg['authorized_for_all_service_commands'] = "*";
         $cfg['authorized_for_all_host_commands'] = "*";
         $cfg['authorized_for_read_only'] = "";
         $cfg['default_statusmap_layout'] = 5;
         $cfg['default_statuswrl_layout'] = 4;
         $cfg['ping_syntax'] = base64_encode('/bin/ping -n -U -c 5 $HOSTADDRESS$');
         $cfg['refresh_rate'] = 90;
         $cfg['escape_html_tags'] = 1;
         $cfg['action_url_target'] = '_blank';
         $cfg['notes_url_target'] = '_blank';
         $cfg['lock_author_names'] = 1;
         $cfg['enable_splunk_integration'] = 0;
         $cfg['splunk_url'] = base64_encode('http://127.0.0.1:8000/');
         $viewData->cgicfg = $cfg;
     }
     $viewData->contacts = RevDeploy::getCommonMergedDeploymentContacts($deployment, $modrevision);
     $viewData->deployment = $deployment;
     $this->sendResponse('cgi_cfg_stage', $viewData);
 }
 public function stage()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('nagios_cfg_error');
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     if (!isset($_SESSION[$deployment]) || !is_array($_SESSION[$deployment])) {
         $_SESSION[$deployment] = array();
     }
     $_SESSION[$deployment]['brokermods'] = array();
     if (RevDeploy::existsDeploymentNagiosCfg($deployment, $modrevision) === true) {
         $viewData->nagcfg = RevDeploy::getDeploymentNagiosCfg($deployment, $modrevision);
         foreach ($viewData->nagcfg as $key => $value) {
             if (preg_match('/^broker_module_/', $key)) {
                 $_SESSION[$deployment]['brokermods'][md5($value)] = $value;
             }
         }
     } else {
         $cfg = array();
         $cfg['accept_passive_host_checks'] = 1;
         $cfg['accept_passive_service_checks'] = 1;
         $cfg['cached_host_check_horizon'] = 15;
         $cfg['cached_service_check_horizon'] = 15;
         $cfg['cfg_dir'] = base64_encode('/usr/local/nagios/etc/objects');
         $cfg['check_external_commands'] = 1;
         $cfg['check_for_orphaned_hosts'] = 1;
         $cfg['check_for_orphaned_services'] = 1;
         $cfg['check_host_freshness'] = 1;
         $cfg['check_result_path'] = base64_encode('/usr/local/nagios/var/spool/checkresults');
         $cfg['check_result_reaper_frequency'] = 10;
         $cfg['check_service_freshness'] = 1;
         $cfg['command_check_interval'] = -1;
         $cfg['command_file'] = base64_encode('/usr/local/nagios/var/rw/nagios.cmd');
         $cfg['enable_event_handlers'] = 1;
         $cfg['enable_notifications'] = 1;
         $cfg['enable_predictive_host_dependency_checks'] = 1;
         $cfg['enable_predictive_service_dependency_checks'] = 1;
         $cfg['event_broker_options'] = -1;
         $cfg['event_handler_timeout'] = 30;
         $cfg['execute_host_checks'] = 1;
         $cfg['execute_service_checks'] = 1;
         $cfg['external_command_buffer_slots'] = 4096;
         $cfg['host_check_timeout'] = 30;
         $cfg['host_freshness_check_interval'] = 60;
         $cfg['illegal_macro_output_chars'] = base64_encode('`~$&|\'"<>');
         $cfg['illegal_object_name_chars'] = base64_encode('`~!$%^&*|\'"<>?,()=');
         $cfg['lock_file'] = base64_encode('/usr/local/nagios/var/nagios.lock');
         $cfg['log_archive_path'] = base64_encode('/usr/local/nagios/var/archives');
         $cfg['log_event_handlers'] = 1;
         $cfg['log_external_commands'] = 1;
         $cfg['log_file'] = base64_encode('/usr/local/nagios/var/nagios.log');
         $cfg['log_host_retries'] = 1;
         $cfg['log_initial_states'] = 0;
         $cfg['log_notifications'] = 1;
         $cfg['log_passive_checks'] = 1;
         $cfg['log_rotation_method'] = 'd';
         $cfg['log_service_retries'] = 1;
         $cfg['max_check_result_file_age'] = 3600;
         $cfg['max_check_result_reaper_time'] = 30;
         $cfg['nagios_group'] = 'nagios';
         $cfg['nagios_user'] = '******';
         $cfg['notification_timeout'] = 30;
         $cfg['object_cache_file'] = base64_encode('/usr/local/nagios/var/objects.cache');
         $cfg['precached_object_file'] = base64_encode('/usr/local/nagios/var/objects.precache');
         $cfg['resource_file'] = base64_encode('/usr/local/nagios/etc/resource.cfg');
         $cfg['retain_state_information'] = 1;
         $cfg['retention_update_interval'] = 60;
         $cfg['service_check_timeout'] = 60;
         $cfg['service_freshness_check_interval'] = 60;
         $cfg['soft_state_dependencies'] = 0;
         $cfg['state_retention_file'] = base64_encode('/usr/local/nagios/var/retention.dat');
         $cfg['status_file'] = base64_encode('/usr/local/nagios/var/status.dat');
         $cfg['status_update_interval'] = 10;
         $cfg['temp_file'] = base64_encode('/usr/local/nagios/var/nagios.tmp');
         $cfg['temp_path'] = base64_encode('/tmp');
         $cfg['use_large_installation_tweaks'] = 0;
         $cfg['use_retained_program_state'] = 1;
         $cfg['use_retained_scheduling_info'] = 1;
         $cfg['use_syslog'] = 1;
         $cfg['additional_freshness_latency'] = 15;
         $cfg['admin_email'] = 'nagios@localhost';
         $cfg['admin_pager'] = 'pagenagios@localhost';
         $cfg['auto_reschedule_checks'] = 0;
         $cfg['auto_rescheduling_interval'] = 30;
         $cfg['auto_rescheduling_window'] = 180;
         $cfg['bare_update_check'] = 0;
         $cfg['check_for_updates'] = 1;
         $cfg['daemon_dumps_core'] = 0;
         $cfg['date_format'] = 'us';
         $cfg['debug_file'] = base64_encode('/usr/local/nagios/var/nagios.debug');
         $cfg['debug_level'] = 0;
         $cfg['debug_verbosity'] = 1;
         $cfg['enable_embedded_perl'] = 1;
         $cfg['enable_environment_macros'] = 0;
         $cfg['enable_flap_detection'] = 0;
         $cfg['high_host_flap_threshold'] = 20.0;
         $cfg['high_service_flap_threshold'] = 20.0;
         $cfg['host_inter_check_delay_method'] = 's';
         $cfg['interval_length'] = 60;
         $cfg['low_host_flap_threshold'] = 5.0;
         $cfg['low_service_flap_threshold'] = 5.0;
         $cfg['max_concurrent_checks'] = 0;
         $cfg['max_host_check_spread'] = 30;
         $cfg['max_service_check_spread'] = 30;
         $cfg['max_debug_file_size'] = 1000000;
         $cfg['obsess_over_hosts'] = 0;
         $cfg['obsess_over_services'] = 0;
         $cfg['ocsp_timeout'] = 5;
         $cfg['ochp_timeout'] = 5;
         $cfg['p1_file'] = base64_encode('/usr/local/nagios/bin/p1.pl');
         $cfg['passive_host_checks_are_soft'] = 0;
         $cfg['retained_contact_host_attribute_mask'] = 0;
         $cfg['retained_contact_service_attribute_mask'] = 0;
         $cfg['retained_host_attribute_mask'] = 0;
         $cfg['retained_process_host_attribute_mask'] = 0;
         $cfg['retained_process_service_attribute_mask'] = 0;
         $cfg['retained_service_attribute_mask'] = 0;
         $cfg['service_inter_check_delay_method'] = 's';
         $cfg['service_interleave_factor'] = 's';
         $cfg['sleep_time'] = 0.25;
         $cfg['translate_passive_host_checks'] = 0;
         $cfg['use_aggressive_host_checking'] = 0;
         $cfg['use_embedded_perl_implicitly'] = 1;
         $cfg['use_regexp_matching'] = 0;
         $cfg['use_true_regexp_matching'] = 0;
         $cfg['process_performance_data'] = 0;
         $cfg['perfdata_timeout'] = 5;
         $cfg['host_perfdata_command'] = base64_encode('process-host-perfdata');
         $cfg['service_perfdata_command'] = base64_encode('process-service-perfdata');
         $cfg['host_perfdata_file'] = base64_encode('/tmp/host-perfdata');
         $cfg['service_perfdata_file'] = base64_encode('/tmp/service-perfdata');
         $cfg['host_perfdata_file_template'] = base64_encode('[HOSTPERFDATA]\\t$TIMET$\\t$HOSTNAME$\\t$HOSTEXECUTIONTIME$\\t$HOSTOUTPUT$\\t$HOSTPERFDATA$');
         $cfg['service_perfdata_file_template'] = base64_encode('[SERVICEPERFDATA]\\t$TIMET$\\t$HOSTNAME$\\t$SERVICEDESC$\\t$SERVICEEXECUTIONTIME$\\t$SERVICELATENCY$\\t$SERVICEOUTPUT$\\t$SERVICEPERFDATA$');
         $cfg['host_perfdata_file_mode'] = 'a';
         $cfg['service_perfdata_file_mode'] = 'a';
         $cfg['host_perfdata_file_processing_interval'] = 0;
         $cfg['service_perfdata_file_processing_interval'] = 0;
         $cfg['host_perfdata_file_processing_command'] = base64_encode('process-host-perfdata-file');
         $cfg['service_perfdata_file_processing_command'] = base64_encode('process-service-perfdata-file');
         $viewData->nagcfg = $cfg;
     }
     $viewData->contacts = RevDeploy::getCommonMergedDeploymentContacts($deployment, $modrevision);
     $viewData->deployment = $deployment;
     $this->sendResponse('nagios_cfg_stage', $viewData);
 }
 public function stage()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('contact_error');
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $viewData->contacts = RevDeploy::getCommonMergedDeploymentContacts($deployment, $modrevision);
     $viewData->deployment = $deployment;
     $this->sendResponse('contact_stage', $viewData);
 }
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('contact_group_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $cgName = $this->getParam('cgName');
     $cgInfo = $this->fetchContactInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentContactGroup($deployment, $cgName, $modrevision) === true) {
         $viewData->error = 'Contact information exists for ' . $cgName . ' in ' . $deployment . ' Deployment';
         $viewData->contactInfo = $cgInfo;
         $viewData->contactgroups = RevDeploy::getCommonMergedDeploymentContactGroups($deployment, $modrevision);
         $viewData->contacts = RevDeploy::getCommonMergedDeploymentContacts($deployment, $modrevision);
         $viewData->action = 'copy_write';
         $this->sendResponse('contact_group_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentContactGroup($deployment, $cgName, $cgInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('contact_group_error');
         $viewData->error = 'Unable to write contact information for ' . $cgName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->contact = $cgName;
     $this->sendResponse('contact_group_write', $viewData);
 }