示例#1
0
 public function __construct()
 {
     $viewData = new stdClass();
     $viewData->title = 'Nagf - wmflabs';
     $viewData->status = null;
     $viewData->project = null;
     $viewData->hosts = null;
     $viewData->hostGraphsConfig = $this->getHostGraphsConfig();
     if (isset($_GET['project'])) {
         $project = $_GET['project'];
         $hosts = Graphite::getHostsForProject($project);
         if ($hosts) {
             $viewData->project = $project;
             $viewData->hosts = $hosts;
         } else {
             $viewData->title = 'Project not found - Nagf';
             $viewData->status = array(404, 'Project not found');
         }
     }
     // NB: Keywords must be compatible with Graphites "from" param (See NagfView::getProjectPage)
     $ranges = array('day', 'week', 'month', 'year');
     // Filter out invalid ranges and ensure we have at least one of them selected
     $cookieRange = isset($_COOKIE['nagf-range']) ? explode('!', $_COOKIE['nagf-range']) : array();
     $checked = array_intersect($ranges, $cookieRange) ?: array('day');
     $viewData->ranges = array();
     foreach ($ranges as $range) {
         $viewData->ranges[$range] = in_array($range, $checked);
     }
     $this->view = new NagfView($viewData);
 }