コード例 #1
0
ファイル: Service.php プロジェクト: rk4an/centreon
 /**
  * Constructor
  *
  * @param int $serviceId The service ID
  * @param int $startTime The start time for graph
  * @param int $endTime The end time for graph
  */
 public function __construct($serviceId, $startTime, $endTime)
 {
     $di = Di::getDefault();
     $dbconn = $di->get('db_centreon');
     /* Get the list of metrics */
     $query = "SELECT i.index_id, i.service_description, m.metric_id, m.metric_name, m.unit_name, m.warn, m.warn_low, m.crit, m.crit_low, m.min, m.max\n            FROM rt_index_data i, rt_metrics m\n            WHERE i.service_id = :service_id\n                AND i.index_id = m.index_id\n                AND m.hidden = '0'";
     $stmt = $dbconn->prepare($query);
     $stmt->bindParam(':service_id', $serviceId);
     $stmt->execute();
     /* List of service template */
     $svcTmpls = ServiceRepository::getListTemplates($serviceId);
     /* Get the graph template */
     $graphInfos = null;
     foreach ($svcTmpls as $svcTmplId) {
         $graphInfos = GraphTemplate::getByServiceTemplate($svcTmplId);
         if (count($graphInfos) > 0) {
             break;
         }
     }
     while ($row = $stmt->fetch()) {
         $metric = array('id' => $row['metric_id'], 'unit' => $row['unit_name'], 'color' => null, 'legend' => $row['metric_name'], 'is_negative' => false, 'graph_type' => 'line');
         if (count($graphInfos) > 0 && isset($graphInfos['metrics'][$row['metric_name']])) {
             $metric = array_merge($metric, $graphInfos['metrics'][$row['metric_name']]);
         }
         $this->metrics[] = $metric;
     }
     parent::__construct($startTime, $endTime);
 }
コード例 #2
0
ファイル: CircularDependency.php プロジェクト: rk4an/centreon
 /**
  * 
  */
 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
ファイル: TagsRepository.php プロジェクト: rk4an/centreon
 /**
  * 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);
 }