/**
  * 
  */
 public function validate($value, $params = array(), $sContext = 'server')
 {
     if (isset($params['extraParams']['host_active_checks_enabled']) && $params['extraParams']['host_active_checks_enabled'] == "0") {
         $reponse = array('success' => true, 'error' => '');
         return $reponse;
     }
     if (!isset($value) || $value === " " || $value == "") {
         // case : UI or API with host-templates params
         if (isset($params['extraParams']['host_hosttemplates']) && $params['extraParams']['host_hosttemplates'] != " ") {
             $tplIds = explode(',', $params['extraParams']['host_hosttemplates']);
             foreach ($tplIds as $tplId) {
                 if (!empty($tplId)) {
                     $template = Hosttemplate::get($tplId);
                     $childTemplates = HostRepository::getTemplateChain($tplId, array(), -1, true);
                     if (!empty($template['command_command_id'])) {
                         $reponse = array('success' => true, 'error' => '');
                         return $reponse;
                     }
                     foreach ($childTemplates as $childTemplate) {
                         if (!empty($childTemplate['command_command_id'])) {
                             $reponse = array('success' => true, 'error' => '');
                             return $reponse;
                         }
                     }
                 }
             }
         } else {
             if (isset($params['object_id'])) {
                 // case : Only UI without host-templates params
                 $childTemplates = HostRepository::getTemplateChain($params['object_id'], array(), -1, true);
                 foreach ($childTemplates as $childTemplate) {
                     if (!empty($childTemplate['command_command_id']) || $childTemplate['command_command_id'] == "0") {
                         $reponse = array('success' => true, 'error' => '');
                         return $reponse;
                     }
                 }
             }
         }
         $reponse = array('success' => false, 'error' => 'No check command set on the host and its templates');
     } else {
         $reponse = array('success' => true, 'error' => '');
     }
     return $reponse;
 }
示例#2
0
 /**
  * 
  */
 public function validate($value, $params = array(), $sContext = 'server')
 {
     $result = true;
     $resultError = _("Circular redundancy detected");
     if (isset($params['object']) && ($params['object'] === 'host' || $params['object'] === 'hosttemplate')) {
         $objectStack = explode(',', trim($value));
         foreach ($objectStack as $hostId) {
             if (isset($params['object_id']) && $hostId == $params['object_id']) {
                 $result = false;
             }
             $listHostId = HostRepository::getTemplateChain($hostId, array(), -1);
             foreach ($listHostId as $hostTemplateId) {
                 if (isset($params['object_id']) && $hostTemplateId['id'] == $params['object_id']) {
                     $result = false;
                 }
             }
         }
     } else {
         if (isset($params['object']) && ($params['object'] === 'service' || $params['object'] === 'servicetemplate')) {
             $serviceId = $value;
             $listServiceId = ServiceRepository::getListTemplates($serviceId);
             if (isset($params['object_id']) && $serviceId == $params['object_id']) {
                 $result = false;
             }
             foreach ($listServiceId as $serviceTemplateId) {
                 if (isset($params['object_id']) && $serviceTemplateId == $params['object_id']) {
                     $result = false;
                 }
             }
         }
     }
     if ($sContext == 'client') {
         $reponse = $result;
     } else {
         $reponse = array('success' => $result, 'error' => $resultError);
     }
     return $reponse;
 }
示例#3
0
 /**
  * 
  * @param array $resultSet
  */
 protected function formatDatas(&$resultSet)
 {
     $router = Di::getDefault()->get('router');
     foreach ($resultSet as &$myHostSet) {
         $myHostSet['host_name'] = '<span class="icoListing">' . HostRepository::getIconImage($myHostSet['host_name']) . '</span>' . $myHostSet['host_name'];
         /* Templates */
         $myHostSet['host_template'] = "";
         $templates = HostRepository::getTemplateChain($myHostSet['host_id'], array(), 1);
         foreach ($templates as $template) {
             $myHostSet['host_template'] .= '<a href="' . $router->getPathFor("/centreon-configuration/hosttemplate/[i:id]", array('id' => $template['id'])) . '"><i class="icon-template ico-20"></i></a>';
         }
         /* Display human readable the check/retry interval */
         $myHostSet['host_check_interval'] = HumanReadable::convert($myHostSet['host_check_interval'], 's', $units, null, true);
         $myHostSet['host_retry_check_interval'] = HumanReadable::convert($myHostSet['host_retry_check_interval'], 's', $units, null, true);
         $sideMenuCustom = new SlideMenu($myHostSet['host_id']);
         $events = Di::getDefault()->get('events');
         $events->emit('centreon-configuration.slide.menu.host.template', array($sideMenuCustom));
         //$myHostSet['DT_RowData']['right_side_details'] = $router->getPathFor('/centreon-configuration/host/snapshot/').$myHostSet['host_id'];
         $myHostSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu();
         $myHostSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu();
         /* Get personal tags */
         $myHostSet['tagname'] = '';
         $aTagUsed = array();
         $aTags = TagsRepository::getList('host', $myHostSet['host_id'], 0, 0);
         foreach ($aTags as $oTags) {
             if (!in_array($oTags['id'], $aTagUsed)) {
                 $aTagUsed[] = $oTags['id'];
                 $myHostSet['tagname'] .= TagsRepository::getTag('host', $myHostSet['host_id'], $oTags['id'], $oTags['text'], $oTags['user_id'], 1);
             }
         }
         $myHostSet['tagname'] .= TagsRepository::getAddTag('host', $myHostSet['host_id']);
     }
 }
示例#4
0
 /**
  * Get the list of inhereted tags
  * @param string $resourceName
  * @param int $resourceId
  * @return array
  */
 public static function getHeritedTags($resourceName, $resourceId)
 {
     $resourceName = self::convertResource($resourceName);
     if (!in_array($resourceName, static::$resourceType)) {
         throw new Exception("This resource type does not support tags.");
     }
     if (empty($resourceId)) {
         return array();
     }
     $aTagUsed = array();
     $aTags = array();
     if ($resourceName == 'host') {
         $templates = HostRepository::getTemplateChain($resourceId, array(), -1);
         foreach ($templates as $template) {
             $aTagsInHost = TagsRepository::getList('host', $template['id'], 1, 0);
             foreach ($aTagsInHost as $oTags) {
                 if (!in_array($oTags['id'], $aTagUsed)) {
                     $aTagUsed[] = $oTags['id'];
                     $aTags[] = $oTags['text'];
                 }
             }
         }
     } elseif ($resourceName == 'service') {
         $templates = ServiceRepository::getListTemplates($resourceId, array(), -1);
         foreach ($templates as $template) {
             $aTagsInSvc = TagsRepository::getList('service', $template, 1, 0);
             foreach ($aTagsInSvc as $oTags) {
                 if (!in_array($oTags['id'], $aTagUsed)) {
                     $aTagUsed[] = $oTags['id'];
                     $aTags[] = $oTags['text'];
                 }
             }
         }
     }
     return array('success' => true, 'values' => $aTags);
 }
示例#5
0
 /**
  * 
  * @param array $resultSet
  */
 protected function formatDatas(&$resultSet)
 {
     foreach ($resultSet as $key => &$myHostSet) {
         $sideMenuCustom = new SlideMenu($myHostSet['host_id']);
         $events = Di::getDefault()->get('events');
         $events->emit('centreon-realtime.slide.menu.host', array($sideMenuCustom));
         $myHostSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu();
         $myHostSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu();
         $aTagUsed = array();
         // @todo remove virtual hosts and virtual services
         if ($myHostSet['name'] === '_Module_BAM') {
             unset($resultSet[$key]);
             continue;
         }
         // Set host_name
         $myHostSet['name'] = '<span class="icoListing">' . HostConfigurationRepository::getIconImage($myHostSet['name']) . '</span>' . $myHostSet['name'];
         if ($myHostSet['state'] != '0' && $myHostSet['state'] != '4') {
             $acknowledgement = HostRealtimeRepository::getAcknowledgementInfos($myHostSet['host_id']);
             if (count($acknowledgement) > 0) {
                 $myHostSet['name'] .= ' <i class="fa fa-thumb-tack"></i>';
             }
         }
         $myHostSet['duration'] = Datetime::humanReadable(time() - $myHostSet['duration'], Datetime::PRECISION_FORMAT, 2);
         $myHostSet['last_check'] = Datetime::humanReadable(time() - $myHostSet['last_check'], Datetime::PRECISION_FORMAT, 2);
         /* Tags */
         $myHostSet['tagname'] = "";
         /*
                     $aTags = TagsRepository::getList('host', $myHostSet['host_id'], 2, 0);
                     foreach ($aTags as $oTags) {
            $myHostSet['tagname'] .= TagsRepository::getTag('host', $myHostSet['host_id'], $oTags['id'], $oTags['text'], $oTags['user_id'], $oTags['template_id']);
                     }
         * 
         */
         $aTags = TagsRepository::getList('host', $myHostSet['host_id'], 2, 0);
         foreach ($aTags as $oTags) {
             if (!in_array($oTags['id'], $aTagUsed)) {
                 $aTagUsed[] = $oTags['id'];
                 $myHostSet['tagname'] .= TagsRepository::getTag('host', $myHostSet['host_id'], $oTags['id'], $oTags['text'], $oTags['user_id'], $oTags['template_id']);
             }
         }
         //Get tags affected by the template
         $templates = HostConfigurationRepository::getTemplateChain($myHostSet['host_id'], array(), -1);
         foreach ($templates as $template) {
             $aTags = TagsRepository::getList('host', $template['id'], 2, 0);
             foreach ($aTags as $oTags) {
                 if (!in_array($oTags['id'], $aTagUsed)) {
                     $aTagUsed[] = $oTags['id'];
                     $myHostSet['tagname'] .= TagsRepository::getTag('host', $template['id'], $oTags['id'], $oTags['text'], $oTags['user_id'], 1);
                 }
             }
         }
         $myHostSet['tagname'] .= TagsRepository::getAddTag('host', $myHostSet['host_id']);
     }
     $resultSet = array_values($resultSet);
 }
示例#6
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();
 }
示例#7
0
 /**
  * Get the value from template
  *
  * @param int $hostId The host template Id
  * @param bool $isBase If the host template id is the base for get values
  * @return array
  */
 public static function getInheritanceValues($hostId, $isBase = false, $columns = array())
 {
     $values = array();
     $templates = HostRepository::getTemplateChain($hostId, array(), -1);
     if ($isBase) {
         array_unshift($templates, array('id' => $hostId));
     }
     foreach ($templates as $template) {
         if (count($columns) > 0) {
             $inheritanceValues = static::getInheritanceValues($template['id'], false, $columns);
             $tmplValues = Hosttemplate::getParameters($template['id'], $columns);
         } else {
             $inheritanceValues = static::getInheritanceValues($template['id']);
             $tmplValues = Hosttemplate::getParameters($template['id'], self::$inheritanceColumns);
         }
         $tmplValues = array_filter($tmplValues, function ($value) {
             return !is_null($value);
         });
         $tmplValues = array_merge($inheritanceValues, $tmplValues);
         $values = array_merge($tmplValues, $values);
     }
     return $values;
 }