Exemple #1
0
 /**
  * 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);
 }
 /**
  * Render the html input
  *
  * @param array $element The element to render
  * @return array
  */
 public static function renderHtmlInput(array $element)
 {
     $di = Di::getDefault();
     /* Add javascript file for clone */
     $tpl = $di->get('template');
     $tpl->addJs('centreon-clone.js')->addJs('component/customcurvegraph.js')->addJs('spectrum.js');
     $tpl->addCss('spectrum.css');
     /* Load default values */
     $listMetrics = array();
     if (isset($element['label_extra']) && isset($element['label_extra']['id'])) {
         $graphTmplId = $element['label_extra']['id'];
         $listMetrics = GraphTemplateRepository::getMetrics($graphTmplId);
     }
     $tpl->assign('currentMetrics', $listMetrics);
     $tpl->assign('element', $element);
     return array('html' => $tpl->fetch('file:[Core]/form/component/customcurvegraph.tpl'));
 }
 /**
  *
  */
 protected function formatDatas(&$resultSet)
 {
     foreach ($resultSet as &$currentResultSet) {
         $tplStr = null;
         $tplArr = ServiceRepository::getMyServiceTemplateModels($currentResultSet['svc_tmpl_id']);
         if (false === is_null($tplArr)) {
             $currentResultSet['svc_tmpl_id'] = $tplArr['description'];
             $currentResultSet['DT_RowData']['name'] = $tplArr['description'];
         }
         $metrics = GraphTemplate::getMetrics($currentResultSet['graph_template_id']);
         $tplStr = '';
         foreach ($metrics as $metric) {
             $tplStr .= '<span style="color: ' . $metric['color'] . '">' . $metric['metric_name'] . '</span>&nbsp;';
         }
         $currentResultSet['metrics'] = $tplStr;
     }
 }
 /**
  * Update the graph template
  *
  * @method post
  * @route /configuration/graphtemplate/update
  */
 public function updateAction()
 {
     $givenParameters = clone $this->getParams('post');
     $listMetrics = array();
     if (isset($givenParameters['metric_name'])) {
         foreach ($givenParameters['metric_name'] as $key => $value) {
             if (!empty($value)) {
                 $listMetrics[$key]['metric_name'] = $value;
                 if (isset($givenParameters['metric_fill'][$key])) {
                     $listMetrics[$key]['metric_fill'] = '1';
                 } else {
                     $listMetrics[$key]['metric_fill'] = '0';
                 }
                 if (isset($givenParameters['metric_negative'][$key])) {
                     $listMetrics[$key]['metric_negative'] = '1';
                 } else {
                     $listMetrics[$key]['metric_negative'] = '0';
                 }
                 if (isset($givenParameters['metric_color'][$key])) {
                     $listMetrics[$key]['metric_color'] = $givenParameters['metric_color'][$key];
                 } else {
                     $listMetrics[$key]['metric_color'] = '#000000';
                 }
             }
         }
     }
     try {
         GraphTemplateRepository::saveMetrics($givenParameters['object_id'], 'update', $listMetrics);
     } catch (\Exception $ex) {
         $errorMessage = $ex->getMessage();
         $this->router->response()->json(array('success' => false, 'error' => $errorMessage));
     }
     parent::updateAction();
 }