/**
  * Get the problem data for the summary
  *
  * @return array|null
  */
 public function getSummary()
 {
     if (!$this->isCurrentlyRunning()) {
         return array('problems' => 1, 'title' => sprintf(mt('monitoring', 'Monitoring backend %s is not running'), MonitoringBackend::instance()->getName()));
     }
     return null;
 }
 /**
  * {@inheritdoc}
  */
 public function getCount()
 {
     if ($this->count === null) {
         try {
             $count = 0;
             $programStatus = $this->isCurrentlyRunning();
             $titles = array();
             if (!(bool) $programStatus->notifications_enabled) {
                 $count = 1;
                 $this->state = static::STATE_WARNING;
                 $titles[] = mt('monitoring', 'Notifications are disabled');
             }
             if (!(bool) $programStatus->is_currently_running) {
                 $count = 1;
                 $this->state = static::STATE_CRITICAL;
                 array_unshift($titles, sprintf(mt('monitoring', 'Monitoring backend %s is not running'), MonitoringBackend::instance()->getName()));
             }
             $this->count = $count;
             $this->title = implode('. ', $titles);
         } catch (Exception $_) {
             $this->count = 1;
         }
     }
     return $this->count;
 }
 public function toLegacyConfigString()
 {
     $settings = array();
     if ($this->hasTitle()) {
         $settings['Title'] = $this->getTitle();
     }
     // TODO: backendName?
     if ($this->backend) {
         $settings['Backend'] = $this->backend->getName();
     }
     $settings['Statetype'] = $this->usesSoftStates() ? 'soft' : 'hard';
     if (false) {
         $settings['SLA Hosts'] = implode(', ', array());
     }
     $conf = "### Business Process Config File ###\n#\n";
     foreach ($settings as $key => $value) {
         $conf .= sprintf("# %-9s : %s\n", $key, $value);
     }
     $conf .= "#\n###################################\n\n";
     $rendered = array();
     foreach ($this->getChildren() as $child) {
         $conf .= $child->toLegacyConfigString($rendered);
         $rendered[(string) $child] = true;
     }
     foreach ($this->getUnboundNodes() as $node) {
         $conf .= $node->toLegacyConfigString($rendered);
         $rendered[(string) $node] = true;
     }
     return $conf . "\n";
 }
 protected static function summary($column = null)
 {
     if (self::$summary === null) {
         $summary = MonitoringBackend::instance()->select()->from('statussummary', array('hosts_down_unhandled', 'services_critical_unhandled'));
         static::applyRestriction('monitoring/filter/objects', $summary);
         self::$summary = $summary->fetchRow();
     }
     if ($column === null) {
         return self::$summary;
     } elseif (isset(self::$summary->{$column})) {
         return self::$summary->{$column};
     } else {
         return null;
     }
 }
 /**
  * Checks whether the monitoring backend is running or not
  *
  * @return mixed
  */
 protected function isCurrentlyRunning()
 {
     return MonitoringBackend::instance()->select()->from('programstatus', array('is_currently_running'))->getQuery()->fetchRow()->is_currently_running;
 }
 /**
  * The tooltip title
  *
  * @return string
  * @throws \Icinga\Exception\ConfigurationError
  */
 public function getTitle()
 {
     return sprintf(mt('monitoring', 'Monitoring backend %s is not running'), MonitoringBackend::instance()->getName());
 }
Example #7
0
 /**
  * @deprecated
  */
 public static function fromParams(UrlParams $params)
 {
     if ($params->has('service') && $params->has('host')) {
         return new Service(MonitoringBackend::instance(), $params->get('host'), $params->get('service'));
     } elseif ($params->has('host')) {
         return new Host(MonitoringBackend::instance(), $params->get('host'));
     }
     return null;
 }
 /**
  * Fetch the dataview from the database or access cache
  *
  * @param   string  $view
  *
  * @return  object
  */
 protected static function summary($view)
 {
     if (!isset(self::$summaries[$view])) {
         $summary = MonitoringBackend::instance()->select()->from($view, self::$dataViews[$view]);
         static::applyRestriction('monitoring/filter/objects', $summary);
         self::$summaries[$view] = $summary->fetchRow();
     }
     return self::$summaries[$view];
 }
Example #9
0
 /**
  * Create view from params
  *
  * @param   array $params
  * @param   array $columns
  *
  * @return  static
  */
 public static function fromParams(array $params, array $columns = null)
 {
     $view = new static(MonitoringBackend::instance($params['backend']), $columns);
     foreach ($params as $key => $value) {
         if ($view->isValidFilterTarget($key)) {
             $view->where($key, $value);
         }
     }
     if (isset($params['sort'])) {
         $order = isset($params['order']) ? $params['order'] : null;
         if ($order !== null) {
             if (strtolower($order) === 'desc') {
                 $order = self::SORT_DESC;
             } else {
                 $order = self::SORT_ASC;
             }
         }
         $view->sort($params['sort'], $order);
     }
     return $view;
 }
Example #10
0
 /**
  * Get the scheduled downtimes
  *
  * @return type
  */
 public function getScheduledDowntimes()
 {
     return $this->backend->select()->from('downtime')->applyFilter($this->filter);
 }
Example #11
0
 /**
  * Return all dynamic filter columns such as custom variables
  *
  * @return  array
  */
 public function getDynamicFilterColumns()
 {
     $columns = array();
     if (!$this->query->allowsCustomVars()) {
         return $columns;
     }
     $query = MonitoringBackend::instance()->select()->from('customvar', array('varname', 'object_type'))->where('is_json', 0)->where('object_type_id', array(1, 2))->getQuery()->group(array('varname', 'object_type'));
     foreach ($query as $row) {
         if ($row->object_type === 'host') {
             $label = t('Host') . ' ' . ucwords(str_replace('_', ' ', $row->varname));
             $columns[$label] = '_host_' . $row->varname;
         } else {
             // $row->object_type === 'service'
             $label = t('Service') . ' ' . ucwords(str_replace('_', ' ', $row->varname));
             $columns[$label] = '_service_' . $row->varname;
         }
     }
     return $columns;
 }
Example #12
0
 protected function moduleInit()
 {
     $this->backend = Backend::createBackend();
 }