Beispiel #1
0
 /**
  * Display the configuration snapshot of a host
  * with template inheritance
  *
  * @method get
  * @route /host/snapshotslide/[i:id]
  */
 public function snapshotslideAction()
 {
     $params = $this->getParams();
     $data = HostRepository::getInheritanceValues($params['id'], true);
     $host = Host::get($params['id'], 'host_name');
     $data['host_name'] = $host['host_name'];
     $data['icon'] = HostRepository::getIconImage($data['host_name']);
     $hostConfiguration = HostRepository::formatDataForSlider($data);
     $aDataRealTime = HostRealtime::get($params['id']);
     $hostReal = HostRepository::formatDataForSlider($aDataRealTime);
     $servicesStatus = ServiceRealTimeRepository::countAllStatusForHost($params['id']);
     $edit_url = $this->router->getPathFor("/centreon-configuration/host/" . $params['id']);
     $this->router->response()->json(array('hostConfig' => $hostConfiguration, 'hostReal' => $hostReal, 'servicesStatus' => $servicesStatus, 'edit_url' => $edit_url, 'success' => true));
 }
Beispiel #2
0
 /**
  * Get scheduling informations for a specific host
  *
  * @method get
  * @route /host/[i:id]/scheduling-infos
  */
 public function schedulingInfosHostAction()
 {
     $params = $this->getParams();
     $schedulingInfos = HostRealtime::get($params['id'], array('execution_time', 'latency'));
     $poller = HostConf::get($params['id'], 'poller_id');
     $schedulingInfos['poller_name'] = !is_null($poller['poller_id']) ? Poller::get($poller['poller_id'], 'name') : "";
     unset($schedulingInfos['poller_id']);
     $this->router->response()->json(array('scheduling_infos' => $schedulingInfos, 'success' => true));
 }
Beispiel #3
0
 /**
  * Deploy services by host templates
  *
  * @param int $hostId
  * @param int $hostTemplateId
  */
 public static function deployServices($hostId, $hostTemplateId = null)
 {
     static $deployedServices = array();
     $db = Di::getDefault()->get('db_centreon');
     $hid = is_null($hostTemplateId) ? $hostId : $hostTemplateId;
     $services = HostServiceRelation::getMergedParameters(array(), array('service_id', 'service_description', 'service_alias'), -1, 0, null, 'ASC', array(HostServiceRelation::getFirstKey() => $hid), 'AND');
     foreach ($services as $service) {
         if (is_null($hostTemplateId)) {
             $deployedServices[$hostId][$service['service_description']] = true;
         } elseif (!isset($deployedServices[$hostId][$service['service_alias']])) {
             $oRepositorie = "CentreonConfiguration\\Repository\\ServiceRepository";
             $oSlugify = new CentreonSlugify(self, $oRepositorie);
             if (!empty($service['service_alias'])) {
                 $sData = $service['service_alias'];
             } else {
                 $sData = $service['service_description'];
             }
             $sHostName = Host::get($hostId, 'host_name');
             $sString = $sHostName['host_name'] . " " . $sData;
             $sSlug = $oSlugify->slug($sString);
             $serviceId = Service::insert(array('service_slug' => $sSlug, 'service_description' => $sData, 'service_template_model_stm_id' => $service['service_id'], 'service_register' => 1, 'service_activate' => 1));
             HostServiceRelation::insert($hostId, $serviceId);
             $deployedServices[$hostId][$service['service_alias']] = true;
         }
     }
     $templates = HostHosttemplateRelation::getTargetIdFromSourceId('host_tpl_id', 'host_host_id', $hid);
     foreach ($templates as $tplId) {
         self::deployServices($hostId, $tplId);
     }
 }
Beispiel #4
0
 public function testGet()
 {
     $testResult = array('host_id' => '1', 'host_template_model_htm_id' => null, 'command_command_id' => '2', 'command_command_id_arg1' => '1!2', 'timeperiod_tp_id' => '1', 'timeperiod_tp_id2' => '1', 'command_command_id2' => '3', 'command_command_id_arg2' => '80!90', 'host_name' => 'Template host', 'host_alias' => 'Template host', 'host_address' => null, 'display_name' => 'Template host', 'host_max_check_attempts' => '5', 'host_check_interval' => '5', 'host_retry_check_interval' => '5', 'host_active_checks_enabled' => '2', 'host_passive_checks_enabled' => '2', 'host_checks_enabled' => '2', 'initial_state' => 'u', 'host_obsess_over_host' => '2', 'host_check_freshness' => '2', 'host_freshness_threshold' => '5', 'host_event_handler_enabled' => '2', 'host_low_flap_threshold' => '5', 'host_high_flap_threshold' => '5', 'host_flap_detection_enabled' => '2', 'flap_detection_options' => 'f', 'host_process_perf_data' => '2', 'host_retain_status_information' => '2', 'host_retain_nonstatus_information' => '2', 'host_notification_interval' => '300', 'host_notification_options' => '$HOSTNAME$', 'host_notifications_enabled' => '2', 'contact_additive_inheritance' => '1', 'cg_additive_inheritance' => '1', 'host_first_notification_delay' => '0', 'host_snmp_community' => 'public', 'host_snmp_version' => '2c', 'host_location' => '0', 'host_comment' => 'Host template', 'host_register' => '0', 'host_activate' => '1', 'organization_id' => '1', 'environment_id' => null, 'poller_id' => null);
     $result = Host::get(1);
     $this->assertEquals($testResult, $result);
     $testResult = array('host_name' => 'Host 1');
     $result = Host::get(2, 'host_name');
     $this->assertEquals($testResult, $result);
     $testResult = array('host_name' => 'Host 1', 'host_comment' => 'First host');
     $result = Host::get(2, array('host_name', 'host_comment'));
     $this->assertEquals($testResult, $result);
     $this->setExpectedException('\\Centreon\\Internal\\Exception', $this->errMsg, 0);
     Host::get(42);
 }
Beispiel #5
0
 /**
  * Deploy services by host templates
  *
  * @param int $hostId
  * @param int $hostTemplateId
  */
 public static function deployServices($hostId, $hostTemplateId = null)
 {
     static $deployedServices = array();
     $aServices = array();
     $db = Di::getDefault()->get('db_centreon');
     //get host template
     $aHostTemplates = HostRepository::getTemplateChain($hostId, array(), -1);
     // get host services
     $aHostServices = HostServiceRelation::getMergedParameters(array('host_id'), array('service_id', 'service_description', 'service_alias', 'inherited'), -1, 0, null, "ASC", array('host_id' => $hostId), "OR");
     // get all service templates linked to a host by its host templates
     $aHostServiceTemplates = array();
     foreach ($aHostTemplates as $oHostTemplate) {
         $aHostTemplateServiceTemplates = HostTemplateServiceTemplateRelation::getMergedParameters(array('host_id'), array('service_id', 'service_description', 'service_alias'), -1, 0, null, "ASC", array('host_id' => $oHostTemplate['id']), "OR");
         // Remove services with same description
         foreach ($aHostTemplateServiceTemplates as $oHostTemplateServiceTemplate) {
             if (!isset($aHostServiceTemplates[$oHostTemplateServiceTemplate['service_alias']])) {
                 $aHostServiceTemplates[$oHostTemplateServiceTemplate['service_alias']] = $oHostTemplateServiceTemplate;
             }
         }
     }
     // get services linked to the host
     $aServicesDescription = array_values(array_column($aHostServices, 'service_description'));
     $repository = "CentreonConfiguration\\Repository\\ServiceRepository";
     $repository::setRelationMap(array("service_hosts" => "\\CentreonConfiguration\\Models\\Relation\\Service\\Host", "service_parents" => "\\CentreonConfiguration\\Models\\Relation\\Service\\Serviceparents", "service_children" => "\\CentreonConfiguration\\Models\\Relation\\Service\\Servicechildren"));
     $repository::setObjectName("Service");
     $repository::setObjectClass("\\CentreonConfiguration\\Models\\Service");
     $oModel = "CentreonConfiguration\\Models\\Service";
     $oSlugify = new CentreonSlugify($oModel, $repository);
     $db->beginTransaction();
     $aTemplateServicesDescription = array_keys($aHostServiceTemplates);
     foreach ($aHostServices as $service) {
         if ($service['inherited'] == 1 && !in_array($service['service_description'], $aTemplateServicesDescription)) {
             Service::delete($service['service_id']);
         }
     }
     // create services which don't yet exist
     foreach ($aHostServiceTemplates as $oHostServiceTemplate) {
         if (!in_array($oHostServiceTemplate['service_alias'], $aServicesDescription)) {
             $sHostName = Host::get($hostId, 'host_name');
             if (isset($sHostName['host_name'])) {
                 $sString = $sHostName['host_name'] . " " . $oHostServiceTemplate['service_alias'];
             } else {
                 $sString = $oHostServiceTemplate['service_alias'];
             }
             $sSlug = $oSlugify->slug($sString);
             if (!empty($oHostServiceTemplate['service_alias'])) {
                 $sData = $oHostServiceTemplate['service_alias'];
             } else {
                 $sData = $oHostServiceTemplate['service_description'];
             }
             $newService['service_slug'] = $sSlug;
             $newService['service_description'] = $sData;
             $newService['service_template_model_stm_id'] = $oHostServiceTemplate['service_id'];
             $newService['service_register'] = 1;
             $newService['service_activate'] = 1;
             $newService['organization_id'] = Di::getDefault()->get('organization');
             $newService['inherited'] = 1;
             $serviceId = Service::insert($newService);
             HostServiceRelation::insert($hostId, $serviceId);
             ServiceHostTemplateRelation::insert($serviceId, $oHostServiceTemplate['host_id']);
         }
     }
     $db->commit();
 }
 /**
  * Generic update function
  * 
  * @param type $givenParameters
  * @param type $origin
  * @param type $route
  * @param type $validate
  * @param type $validateMandatory
  * 
  * @throws \Centreon\Internal\Exception
  */
 public static function update($givenParameters, $origin = "", $route = "", $validate = true, $validateMandatory = true)
 {
     $id = null;
     $db = Di::getDefault()->get('db_centreon');
     $class = static::$objectClass;
     $pk = $class::getPrimaryKey();
     $columns = $class::getColumns();
     if (isset($givenParameters['service_hosts'])) {
         $sField = $class::getUniqueLabelField();
         $aHostId = explode(",", $givenParameters['service_hosts']);
         $aHostId = array_filter($aHostId, 'strlen');
         if (count($aHostId) > 0) {
             $sHostName = Host::get(current($aHostId), 'host_name');
             if (isset($sField) && isset($givenParameters[$sField]) && !is_null($class::getSlugField()) && (isset($givenParameters[$class::getSlugField()]) && is_null($givenParameters[$class::getSlugField()]) or !isset($givenParameters[$class::getSlugField()]))) {
                 $oSlugify = new CentreonSlugify($class, get_called_class());
                 $sString = $sHostName['host_name'] . " " . $givenParameters[$sField];
                 $sSlug = $oSlugify->slug($sString);
                 $givenParameters[$class::getSlugField()] = $sSlug;
             }
         }
     }
     parent::update($givenParameters, $origin, $route, $validate, $validateMandatory);
 }