예제 #1
0
 /**
  * Get information for a incident for display graph
  *
  * @route /incident/graph
  * @method POST
  */
 public function getIncidentGraphInfoAction()
 {
     $di = Di::getDefault();
     $router = $di->get('router');
     $response = array();
     $action = $router->request()->param('action', null);
     $incidentId = $router->request()->param('incident_id', null);
     if (is_null($incidentId)) {
         $router->response()->code(400);
         return;
     }
     switch ($action) {
         case 'get_info':
             $incident = IncidentsRepository::getIncident($incidentId);
             $fullname = $incident['name'];
             if (false === is_null($incident['description'])) {
                 $fullname .= ' - ' . $incident['description'];
             }
             $response = array('id' => $incident['issue_id'], 'name' => $fullname, 'status' => self::getCssStatus($incident['state']), 'output' => $incident['output'], 'last_update' => Datetime::format($incident['last_state_change']), 'has_children' => $incident['nb_children'] > 0 ? true : false, 'has_parent' => $incident['nb_parents'] > 0 ? true : false, 'parents' => array_map(function ($values) {
                 $parent = array();
                 $parent['id'] = $values['issue_id'];
                 $fullname = $values['name'];
                 if (!is_null($values['description'])) {
                     $fullname .= ' - ' . $values['description'];
                 }
                 $parent['name'] = $fullname;
                 return $parent;
             }, $incident['parents']));
             break;
         case 'getChildren':
             $listChildren = IncidentsRepository::getChildren($incidentId);
             $response = array();
             foreach ($listChildren as $child) {
                 $fullname = $child['name'];
                 if (false === is_null($child['description'])) {
                     $fullname .= ' - ' . $child['description'];
                 }
                 $response[] = array('id' => $child['issue_id'], 'name' => $fullname, 'status' => self::getCssStatus($child['state']), 'output' => $child['output'], 'last_update' => Datetime::format($child['last_state_change']), 'has_children' => $child['nb_children'] > 0 ? true : false, 'has_parent' => $child['nb_parents'] > 0 ? true : false);
             }
             break;
         case 'get_extended_info':
             $status = IncidentsRepository::getListStatus($incidentId);
             $statusList = array();
             foreach ($status as $tmp) {
                 if (false === is_null($tmp['service_id'])) {
                     $statusType = Status::TYPE_SERVICE;
                 } else {
                     $statusType = Status::TYPE_HOST;
                 }
                 $statusList[] = array('id' => $tmp['state'], 'text' => Status::numToString($tmp['state'], $statusType, true), 'datetime' => $tmp['start_time']);
             }
             $response = array('status' => array(array('id' => 2, 'text' => 'Critical', 'datetime' => '2014-05-12 01:03:11'), array('id' => 2, 'text' => 'Critical', 'datetime' => '2014-05-12 01:03:11'), array('id' => 2, 'text' => 'Critical', 'datetime' => '2014-05-12 01:03:11'), array('id' => 2, 'text' => 'Critical', 'datetime' => '2014-05-12 01:03:11')));
             break;
         default:
             $router->response()->code(400);
             return;
     }
     $router->response()->json($response);
 }