Ejemplo n.º 1
0
 /**
  * Prepare the HTML for the graph
  * @return string
  */
 public function createHTML($server_id)
 {
     // Archive all records for this server to make sure we have up-to-date stats
     $archive = new ArchiveManager($this->db);
     $archive->archive($server_id);
     $now = new \DateTime();
     $last_week = new \DateTime('-1 week 0:0:0');
     $last_year = new \DateTime('-1 year -1 week 0:0:0');
     $graphs = array(0 => $this->generateGraphUptime($server_id, $last_week, $now), 1 => $this->generateGraphHistory($server_id, $last_year, $last_week));
     $info_fields = array('latency_avg' => '%01.4f', 'uptime' => '%01.3f%%');
     foreach ($graphs as $i => &$graph) {
         // add subarray for info fields
         $graph['info'] = array();
         foreach ($info_fields as $field => $format) {
             if (!isset($graph[$field])) {
                 continue;
             }
             $graph['info'][] = array('label' => psm_get_lang('servers', $field), 'value' => sprintf($format, $graph[$field]));
         }
     }
     $tpl_data = array('graphs' => $graphs, 'label_server' => psm_get_lang('servers', 'server'), 'day_format' => psm_get_lang('servers', 'chart_day_format'), 'long_date_format' => psm_get_lang('servers', 'chart_long_date_format'), 'short_date_format' => psm_get_lang('servers', 'chart_short_date_format'), 'short_time_format' => psm_get_lang('servers', 'chart_short_time_format'));
     return $this->twig->render('module/server/history.tpl.html', $tpl_data);
 }
Ejemplo n.º 2
0
 /**
  * Go :-)
  *
  * @param boolean $skip_perms if TRUE, no user permissions will be taken in account and all servers will be updated
  */
 public function run($skip_perms = false)
 {
     // check if we need to restrict the servers to a certain user
     $sql_join = '';
     if (!$skip_perms && $this->container->get('user')->getUserLevel() > PSM_USER_ADMIN) {
         // restrict by user_id
         $sql_join = "JOIN `" . PSM_DB_PREFIX . "users_servers` AS `us` ON (\n\t\t\t\t\t\t`us`.`user_id`={$this->container->get('user')->getUserId()}\n\t\t\t\t\t\tAND `us`.`server_id`=`s`.`server_id`\n\t\t\t\t\t\t)";
     }
     $sql = "SELECT `s`.`server_id`,`s`.`ip`,`s`.`port`,`s`.`label`,`s`.`type`,`s`.`pattern`,`s`.`status`,`s`.`active`,`s`.`email`,`s`.`sms`,`s`.`pushover`\n\t\t\t\tFROM `" . PSM_DB_PREFIX . "servers` AS `s`\n\t\t\t\t{$sql_join}\n\t\t\t\tWHERE `active`='yes' ";
     $servers = $this->container->get('db')->query($sql);
     $updater = new Updater\StatusUpdater($this->container->get('db'));
     $notifier = new Updater\StatusNotifier($this->container->get('db'));
     foreach ($servers as $server) {
         $status_old = $server['status'] == 'on' ? true : false;
         $status_new = $updater->update($server['server_id']);
         // notify the nerds if applicable
         $notifier->notify($server['server_id'], $status_old, $status_new);
     }
     // clean-up time!! archive all records
     $archive = new ArchiveManager($this->container->get('db'));
     $archive->archive();
     $archive->cleanup();
 }