Merge branch 'feature/ido-doc-4663'

resolves #4663
This commit is contained in:
Eric Lippmann 2013-10-09 09:20:25 +02:00
commit ba77713af0
54 changed files with 1681 additions and 1467 deletions

View File

@ -38,6 +38,7 @@ use \Icinga\Exception\ProgrammingError;
use \Icinga\Application\DbAdapterFactory;
use \Icinga\Exception\ConfigurationError;
use \Icinga\Util\DateTimeFactory;
use Icinga\Data\ResourceFactory;
/**
* This class bootstraps a thin Icinga application layer
@ -388,10 +389,11 @@ abstract class ApplicationBootstrap
*
* @return self
*/
protected function setupResourceFactories()
protected function setupResourceFactory()
{
$config = Config::app('resources');
DbAdapterFactory::setConfig($config);
ResourceFactory::setConfig($config);
return $this;
}

View File

@ -28,14 +28,14 @@
namespace Icinga\Application\Modules;
use \Icinga\Application\ApplicationBootstrap;
use \Icinga\Application\Icinga;
use \Icinga\Application\Logger;
use \Icinga\Data\ArrayDatasource;
use \Icinga\Data\ArrayQuery;
use \Icinga\Exception\ConfigurationError;
use \Icinga\Exception\SystemPermissionException;
use \Icinga\Exception\ProgrammingError;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Icinga;
use Icinga\Application\Logger;
use Icinga\Data\DataArray\Datasource as ArrayDatasource;
use Icinga\Data\DataArray\Query as ArrayQuery;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\SystemPermissionException;
use Icinga\Exception\ProgrammingError;
/**
* Module manager that handles detecting, enabling and disabling of modules

View File

@ -103,7 +103,7 @@ class Web extends ApplicationBootstrap
{
return $this->setupConfig()
->setupErrorHandling()
->setupResourceFactories()
->setupResourceFactory()
->setupUser()
->setupTimezone()
->setupRequest()

View File

@ -175,7 +175,6 @@ abstract class AbstractQuery implements QueryInterface
$dir = self::SORT_ASC;
}
}
$this->order_columns[] = array($col, $dir);
return $this;
}

View File

@ -28,14 +28,11 @@
namespace Icinga\Data\Db;
use \PDO;
use \Zend_Config;
use \Zend_Db;
use \Zend_Db_Adapter_Abstract;
use \Icinga\Application\DbAdapterFactory;
use \Icinga\Data\DatasourceInterface;
use \Icinga\Exception\ConfigurationError;
use \Icinga\Application\Logger;
use PDO;
use Zend_Config;
use Zend_Db;
use Icinga\Data\DatasourceInterface;
use Icinga\Exception\ConfigurationError;
/**
* Encapsulate database connections and query creation
@ -43,25 +40,33 @@ use \Icinga\Application\Logger;
class Connection implements DatasourceInterface
{
/**
* Database connection
*
* @var Zend_Db_Adapter_Abstract
*/
protected $db;
/**
* Backend configuration
* Connection config
*
* @var Zend_Config
*/
protected $config;
private $config;
/**
* Database type
*
* @var string
*/
protected $dbType;
private $dbType;
private $conn;
private $tablePrefix = '';
private static $genericAdapterOptions = array(
Zend_Db::AUTO_QUOTE_IDENTIFIERS => false,
Zend_Db::CASE_FOLDING => Zend_Db::CASE_LOWER
);
private static $driverOptions = array(
PDO::ATTR_TIMEOUT => 2,
PDO::ATTR_CASE => PDO::CASE_LOWER,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
/**
* Create a new connection object
@ -109,22 +114,69 @@ class Connection implements DatasourceInterface
*/
private function connect()
{
$resourceName = $this->config->get('resource');
$this->db = DbAdapterFactory::getDbAdapter($resourceName);
if ($this->db->getConnection() instanceof PDO) {
$this->dbType = $this->db->getConnection()->getAttribute(PDO::ATTR_DRIVER_NAME);
} else {
$this->dbType = strtolower(get_class($this->db->getConnection()));
$genericAdapterOptions = self::$genericAdapterOptions;
$driverOptions = self::$driverOptions;
$adapterParamaters = array(
'host' => $this->config->host,
'username' => $this->config->username,
'password' => $this->config->password,
'dbname' => $this->config->dbname,
'options' => & $genericAdapterOptions,
'driver_options' => & $driverOptions
);
$this->dbType = strtolower($this->config->get('db', 'mysql'));
switch ($this->dbType) {
case 'mysql':
$adapter = 'Pdo_Mysql';
/*
* Set MySQL server SQL modes to behave as closely as possible to Oracle and PostgreSQL. Note that the
* ONLY_FULL_GROUP_BY mode is left on purpose because MySQL requires you to specify all non-aggregate columns
* in the group by list even if the query is grouped by the master table's primary key which is valid
* ANSI SQL though. Further in that case the query plan would suffer if you add more columns to the group by
* list.
*/
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] =
'SET SESSION SQL_MODE=\'STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,'
. 'NO_AUTO_CREATE_USER,ANSI_QUOTES,PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\';';
$adapterParamaters['port'] = $this->config->get('port', 3306);
break;
case 'pgsql':
$adapter = 'Pdo_Pgsql';
$adapterParamaters['port'] = $this->config->get('port', 5432);
break;
// case 'oracle':
// if ($this->dbtype === 'oracle') {
// $attributes['persistent'] = true;
// }
// $this->db = ZfDb::factory($adapter, $attributes);
// if ($adapter === 'Oracle') {
// $this->db->setLobAsString(false);
// }
// break;
default:
throw new ConfigurationError(
sprintf(
'Backend "%s" is not supported', $this->dbType
)
);
}
$this->db->setFetchMode(Zend_Db::FETCH_OBJ);
$this->conn = Zend_Db::factory($adapter, $adapterParamaters);
$this->conn->setFetchMode(Zend_Db::FETCH_OBJ);
}
if ($this->dbType === null) {
Logger::warn('Could not determine database type');
}
public function getConnection()
{
return $this->conn;
}
if ($this->dbType === 'oci') {
$this->dbType = 'oracle';
}
public function getTablePrefix()
{
return $this->tablePrefix;
}
public function setTablePrefix($prefix)
{
$this->tablePrefix = $prefix;
return $this;
}
}

View File

@ -40,7 +40,7 @@ class Query extends AbstractQuery
protected function init()
{
$this->db = $this->ds->getConnection()->getDb();
$this->db = $this->ds->getConnection();
$this->baseQuery = $this->db->select();
}

View File

@ -0,0 +1,48 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Data;
use Zend_Config;
use Icinga\Util\ConfigAwareFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\Data\Db\Connection as DbConnection;
use Icinga\Protocol\Statusdat\Reader as StatusdatReader;
class ResourceFactory implements ConfigAwareFactory
{
/**
* @var Zend_Config
*/
private static $resources;
public static function setConfig($config)
{
self::$resources = $config;
}
public static function getResourceConfig($resourceName)
{
if (($resourceConfig = self::$resources->get($resourceName)) === null) {
throw new ConfigurationError('BLUBB?!');
}
return $resourceConfig;
}
public static function createResource(Zend_Config $config)
{
switch (strtolower($config->type)) {
case 'db':
$resource = new DbConnection($config);
break;
case 'statusdat':
$resource = new StatusdatReader($config);
break;
default:
throw new ConfigurationError('BLUBB2?!');
}
return $resource;
}
}

View File

@ -18,6 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
@ -39,9 +40,10 @@ use \Icinga\Module\Monitoring\Backend;
use \Icinga\Web\Widget\SortBox;
use \Icinga\Application\Config as IcingaConfig;
/**
* Controller for listing views
*/
use Icinga\Module\Monitoring\DataView\Notification as NotificationView;
use Icinga\Module\Monitoring\DataView\Downtime as DowntimeView;
use Icinga\Module\Monitoring\DataView\HostAndServiceStatus as HostAndServiceStatusView;
class Monitoring_ListController extends ActionController
{
/**
@ -67,7 +69,7 @@ class Monitoring_ListController extends ActionController
*/
public function init()
{
$this->backend = Backend::getInstance($this->_getParam('backend'));
$this->backend = Backend::createBackend($this->_getParam('backend'));
$this->view->grapher = Hook::get('grapher');
$this->createTabs();
$this->view->activeRowHref = $this->getParam('detail');
@ -88,10 +90,9 @@ class Monitoring_ListController extends ActionController
*/
public function hostsAction()
{
Benchmark::measure("hostsAction::query()");
$this->compactView = "hosts-compact";
$this->view->hosts = $this->query(
'status',
$this->compactView = 'hosts-compact';
$query = HostAndServiceStatusView::fromRequest(
$this->_request,
array(
'host_icon_image',
'host_name',
@ -110,9 +111,13 @@ class Monitoring_ListController extends ActionController
'host_unhandled_service_count',
'host_action_url',
'host_notes_url',
'host_last_comment'
'host_last_comment',
'host_active_checks_enabled',
'host_passive_checks_enabled'
)
);
)->getQuery();
$this->view->hosts = $query->paginate();
$this->setupSortControl(array(
'host_last_check' => 'Last Host Check',
'host_severity' => 'Host Severity',
@ -121,6 +126,7 @@ class Monitoring_ListController extends ActionController
'host_address' => 'Address',
'host_state' => 'Hard State'
));
$this->handleFormatRequest($query);
}
/**
@ -128,36 +134,40 @@ class Monitoring_ListController extends ActionController
*/
public function servicesAction()
{
$this->compactView = "services-compact";
$this->view->services = $this->query('status', array(
'host_name',
'host_state',
'host_state_type',
'host_last_state_change',
'host_address',
'host_handled',
'service_description',
'service_display_name',
'service_state' => 'service_state',
'service_in_downtime',
'service_acknowledged',
'service_handled',
'service_output',
'service_last_state_change' => 'service_last_state_change',
'service_icon_image',
'service_long_output',
'service_is_flapping',
'service_state_type',
'service_handled',
'service_severity',
'service_last_check',
'service_notifications_enabled',
'service_action_url',
'service_notes_url',
'service_last_comment'
));
$this->compactView = 'services-compact';
$query = HostAndServiceStatusView::fromRequest(
$this->_request,
array(
'host_name',
'host_state',
'host_state_type',
'host_last_state_change',
'host_address',
'host_handled',
'service_description',
'service_display_name',
'service_state' => 'service_state',
'service_in_downtime',
'service_acknowledged',
'service_handled',
'service_output',
'service_last_state_change' => 'service_last_state_change',
'service_icon_image',
'service_long_output',
'service_is_flapping',
'service_state_type',
'service_handled',
'service_severity',
'service_last_check',
'service_notifications_enabled',
'service_action_url',
'service_notes_url',
'service_last_comment',
'service_active_checks_enabled',
'service_passive_checks_enabled'
)
)->getQuery();
$this->view->services = $query->paginate();
$this->setupSortControl(array(
'service_last_check' => 'Last Service Check',
'service_severity' => 'Severity',
@ -169,7 +179,8 @@ class Monitoring_ListController extends ActionController
'host_name' => 'Host Name',
'host_address' => 'Host Address',
'host_last_check' => 'Last Host Check'
));
));
$this->handleFormatRequest($query);
}
/**
@ -177,24 +188,26 @@ class Monitoring_ListController extends ActionController
*/
public function downtimesAction()
{
$this->setDefaultSortColumn('downtime_is_in_effect');
$this->view->downtimes = $this->query('downtime', array(
'host_name',
'object_type',
'service_description',
'downtime_entry_time',
'downtime_internal_downtime_id',
'downtime_author_name',
'downtime_comment_data',
'downtime_duration',
'downtime_scheduled_start_time',
'downtime_scheduled_end_time',
'downtime_is_fixed',
'downtime_is_in_effect',
'downtime_triggered_by_id',
'downtime_trigger_time'
));
$query = DowntimeView::fromRequest(
$this->_request,
array(
'host_name',
'object_type',
'service_description',
'downtime_entry_time',
'downtime_internal_downtime_id',
'downtime_author_name',
'downtime_comment_data',
'downtime_duration',
'downtime_scheduled_start_time',
'downtime_scheduled_end_time',
'downtime_is_fixed',
'downtime_is_in_effect',
'downtime_triggered_by_id',
'downtime_trigger_time'
)
)->getQuery();
$this->view->downtimes = $query->paginate();
$this->setupSortControl(array(
'downtime_is_in_effect' => 'Is In Effect',
'object_type' => 'Service/Host',
@ -208,7 +221,8 @@ class Monitoring_ListController extends ActionController
'downtime_trigger_time' => 'Trigger Time',
'downtime_internal_downtime_id' => 'Downtime ID',
'downtime_duration' => 'Duration',
));
));
$this->handleFormatRequest($query);
}
/**
@ -216,9 +230,8 @@ class Monitoring_ListController extends ActionController
*/
public function notificationsAction()
{
$this->setDefaultSortColumn('notification_start_time', 'DESC');
$this->view->notifications = $this->query(
'notification',
$query = NotificationView::fromRequest(
$this->_request,
array(
'host_name',
'service_description',
@ -229,39 +242,12 @@ class Monitoring_ListController extends ActionController
'notification_information',
'notification_command'
)
);
)->getQuery();
$this->view->notifications = $query->paginate();
$this->setupSortControl(array(
'notification_start_time' => 'Notification Start'
));
}
/**
* Create query
*
* @param string $view
* @param array $columns
*
* @return Query
*/
private function query($view, $columns)
{
$extra = preg_split(
'~,~',
$this->_getParam('extracolumns', ''),
-1,
PREG_SPLIT_NO_EMPTY
);
if (empty($extra)) {
$cols = $columns;
} else {
$cols = array_merge($columns, $extra);
}
$this->view->extraColumns = $extra;
$query = $this->backend->select()
->from($view, $cols)
->applyRequest($this->_request);
$this->handleFormatRequest($query);
return $query->paginate();
}
/**
@ -278,7 +264,7 @@ class Monitoring_ListController extends ActionController
if ($this->_getParam('format') === 'sql'
&& IcingaConfig::app()->global->get('environment', 'production') === 'development') {
echo '<pre>'
. htmlspecialchars(wordwrap($query->getQuery()->dump()))
. htmlspecialchars(wordwrap($query->dump()))
. '</pre>';
exit;
}
@ -296,19 +282,6 @@ class Monitoring_ListController extends ActionController
}
}
/**
* Set the default sort column for this action if none is provided
*
* @param string $column The column to use for sorting
* @param string $dir The direction ('ASC' or 'DESC')
*/
private function setDefaultSortColumn($column, $dir = 'DESC')
{
$this->setParam('sort', $this->getParam('sort', $column));
$this->setParam('dir', $this->getParam('dir', $dir));
}
/**
* Create a sort control box at the 'sortControl' view parameter
*

View File

@ -57,7 +57,7 @@ class Monitoring_ShowController extends ActionController
{
$host = $this->_getParam('host');
$service = $this->_getParam('service');
$this->backend = Backend::getInstance($this->_getParam('backend'));
$this->backend = Backend::createBackend($this->_getParam('backend'));
$object = null;
// TODO: Do not allow wildcards in names!
if ($host !== null) {
@ -70,13 +70,6 @@ class Monitoring_ShowController extends ActionController
}
}
$this->backend = Backend::getInstance($this->_getParam('backend'));
if ($service !== null && $service !== '*') {
$this->view->service = $this->backend->fetchService($host, $service, true);
}
if ($host !== null) {
$this->view->host = $this->backend->fetchHost($host, true);
}
$this->view->compact = $this->_getParam('view') === 'compact';
if ($object === null) {
// TODO: Notification, not found
@ -92,114 +85,9 @@ class Monitoring_ShowController extends ActionController
*/
public function serviceAction()
{
Benchmark::measure('Entered service action');
$this->view->active = 'service';
if ($grapher = Hook::get('grapher')) {
if ($grapher->hasGraph(
$this->view->service->host_name,
$this->view->service->service_description
)
) {
$this->view->preview_image = $grapher->getPreviewImage(
$this->view->service->host_name,
$this->view->service->service_description
);
}
}
$this->view->servicegroups = $this->backend->select()
->from(
'servicegroup',
array(
'servicegroup_name',
'servicegroup_alias'
)
)
->where('host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description)
->fetchPairs();
$this->view->contacts = $this->backend->select()
->from(
'contact',
array(
'contact_name',
'contact_alias',
'contact_email',
'contact_pager',
)
)
->where('service_host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description)
->fetchAll();
$this->view->contactgroups = $this->backend->select()
->from(
'contactgroup',
array(
'contactgroup_name',
'contactgroup_alias',
)
)
->where('service_host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description)
->fetchAll();
$this->view->comments = $this->backend->select()
->from(
'comment',
array(
'comment_timestamp',
'comment_author',
'comment_data',
'comment_type',
)
)
->where('service_host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description)
->fetchAll();
$this->view->downtimes = $this->backend->select()
->from(
'downtime',
array(
'host_name',
'service_description',
'downtime_type',
'downtime_author_name',
'downtime_comment_data',
'downtime_is_fixed',
'downtime_duration',
'downtime_scheduled_start_time',
'downtime_scheduled_end_time',
'downtime_actual_start_time',
'downtime_was_started',
'downtime_is_in_effect',
'downtime_internal_downtime_id'
)
)
->where('host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description)
->where('object_type','service')
->fetchAll();
$this->view->customvars = $this->backend->select()
->from(
'customvar',
array(
'varname',
'varvalue'
)
)
->where('varname', '-*PW*,-*PASS*')
->where('host_name', $this->view->host->host_name)
->where('service_description', $this->view->service->service_description)
->where('object_type', 'service')
->fetchPairs();
Benchmark::measure('Service action done');
$object = $this->view->object->prefetch();
$this->view->object->prefetch();
$this->view->object->eventHistory = $this->view->object->eventHistory->limit(10)->fetchAll();
$this->view->preserve = array();
}
/**
@ -207,98 +95,9 @@ class Monitoring_ShowController extends ActionController
*/
public function hostAction()
{
$this->view->active = 'host';
if ($grapher = Hook::get('grapher')) {
if ($grapher->hasGraph($this->view->host->host_name)) {
$this->view->preview_image = $grapher->getPreviewImage(
$this->view->host->host_name
);
}
}
$this->view->hostgroups = $this->backend->select()
->from(
'hostgroup',
array(
'hostgroup_name',
'hostgroup_alias'
)
)
->where('host_name', $this->view->host->host_name)
->fetchPairs();
$this->view->contacts = $this->backend->select()
->from(
'contact',
array(
'contact_name',
'contact_alias',
'contact_email',
'contact_pager',
)
)
->where('host_name', $this->view->host->host_name)
->fetchAll();
$this->view->contactgroups = $this->backend->select()
->from(
'contactgroup',
array(
'contactgroup_name',
'contactgroup_alias',
)
)
->where('host_name', $this->view->host->host_name)
->fetchAll();
$this->view->comments = $this->backend->select()
->from(
'comment',
array(
'comment_timestamp',
'comment_author',
'comment_data',
'comment_type',
)
)
->where('host_name', $this->view->host->host_name)
->fetchAll();
$this->view->downtimes = $this->backend->select()
->from(
'downtime',
array(
'host_name',
'downtime_type',
'downtime_author_name',
'downtime_comment_data',
'downtime_is_fixed',
'downtime_duration',
'downtime_scheduled_start_time',
'downtime_scheduled_end_time',
'downtime_actual_start_time',
'downtime_was_started',
'downtime_is_in_effect',
'downtime_internal_downtime_id'
)
)
->where('host_name', $this->view->host->host_name)
->where('object_type','host')
->fetchAll();
$this->view->customvars = $this->backend->select()
->from(
'customvar',
array(
'varname',
'varvalue'
)
)
->where('varname', '-*PW*,-*PASS*')
->where('host_name', $this->view->host->host_name)
->where('object_type', 'host')
->fetchPairs();
$this->view->object->prefetch();
$this->view->object->eventHistory = $this->view->object->eventHistory->limit(10)->fetchAll();
$this->view->preserve = array();
}
/**
@ -333,27 +132,6 @@ class Monitoring_ShowController extends ActionController
$this->view->preserve = $this->view->history->getAppliedFilter()->toParams();
}
/**
* Service overview
*/
public function servicesAction()
{
$this->_setParam('service', null);
// Ugly and slow:
$this->view->services = $this->view->action(
'services',
'list',
'monitoring',
array(
'host_name' => $this->view->host->host_name,
//'sort', 'service_description'
)
);
$this->view->services = $this->view->action('services', 'list', 'monitoring', array(
'view' => 'compact'
));
}
/**
* Creating tabs for this controller
* @return Tabs

View File

@ -25,59 +25,40 @@
*/
// {{{ICINGA_LICENSE_HEADER}}}
/*use Icinga\Module\Monitoring\Object\AbstractObject;*/
/**
* Class Zend_View_Helper_MonitoringFlags
*
* Rendering helper for flags depending on objects
* Rendering helper for object's properties which may be either enabled or disabled
*/
class Zend_View_Helper_MonitoringFlags extends Zend_View_Helper_Abstract
{
/**
* Key of flags without prefix (e.g. host or service)
* Object's properties which may be either enabled or disabled and their human readable description
*
* @var string[]
*/
private static $keys = array(
'passive_checks_enabled' => 'Passive Checks',
'active_checks_enabled' => 'Active Checks',
'obsessing' => 'Obsessing',
'notifications_enabled' => 'Notifications',
'event_handler_enabled' => 'Event Handler',
'flap_detection_enabled' => 'Flap Detection',
private static $flags = array(
'passive_checks_enabled' => 'Passive Checks',
'active_checks_enabled' => 'Active Checks',
'obsessing' => 'Obsessing',
'notifications_enabled' => 'Notifications',
'event_handler_enabled' => 'Event Handler',
'flap_detection_enabled' => 'Flap Detection',
);
/**
* Type prefix
* @param array $vars
* @return string
* Retrieve flags as array with either true or false as value
*
* @param AbstractObject $object
*
* @return array
*/
private function getObjectType(array $vars)
public function monitoringFlags(/*AbstractObject*/$object)
{
$keys = array_keys($vars);
$firstKey = array_shift($keys);
$keyParts = explode('_', $firstKey, 2);
return array_shift($keyParts);
}
/**
* Build all existing flags to a readable array
* @param stdClass $object
* @return array
*/
public function monitoringFlags(\stdClass $object)
{
$vars = (array)$object;
$type = $this->getObjectType($vars);
$out = array();
foreach (self::$keys as $key => $name) {
$value = false;
if (array_key_exists(($realKey = $type. '_'. $key), $vars)) {
$value = $vars[$realKey] === '1' ? true : false;
}
$out[$name] = $value;
$flags = array();
foreach (self::$flags as $column => $description) {
$flags[$description] = (bool) $object->{$column};
}
return $out;
return $flags;
}
}

View File

@ -3,6 +3,8 @@
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Module\Monitoring\Object\AbstractObject;
/**
* Class Zend_View_Helper_MonitoringProperties
*/
@ -47,10 +49,8 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
*/
private static $keys = array(
'buildAttempt' => 'Current Attempt',
'last_check' => 'Last Check Time',
'buildCheckType' => 'Check Type',
'buildLatency' => 'Check Latency / Duration',
'buildNextCheck' => 'Next Scheduled Active Check',
'buildLastStateChange' => 'Last State Change',
'buildLastNotification' => 'Last Notification',
'buildFlapping' => 'Is This %s Flapping?',
@ -76,7 +76,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return mixed
*/
private function getObjectType(stdClass $object)
private function getObjectType($object)
{
$keys = array_keys(get_object_vars($object));
$keyParts = explode('_', array_shift($keys), 2);
@ -89,7 +89,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param $type
* @return object
*/
private function dropObjectType(stdClass $object, $type)
private function dropObjectType($object, $type)
{
$vars = get_object_vars($object);
$out = array();
@ -105,7 +105,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildAttempt(stdClass $object)
private function buildAttempt($object)
{
return sprintf(
'%s/%s (%s state)',
@ -130,7 +130,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildCheckType(stdClass $object)
private function buildCheckType($object)
{
if ($object->passive_checks_enabled === '1' && $object->active_checks_enabled === '0') {
return self::CHECK_PASSIVE;
@ -146,7 +146,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildLatency(stdClass $object)
private function buildLatency($object)
{
$val = '';
if ($this->buildCheckType($object) === self::CHECK_PASSIVE) {
@ -169,7 +169,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildNextCheck(stdClass $object)
private function buildNextCheck($object)
{
if ($this->buildCheckType($object) === self::CHECK_PASSIVE) {
return self::VALUE_NA;
@ -183,7 +183,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildLastStateChange(stdClass $object)
private function buildLastStateChange($object)
{
return strftime('%Y-%m-%d %H:%M:%S', $object->last_state_change);
}
@ -193,7 +193,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildLastNotification(stdClass $object)
private function buildLastNotification($object)
{
$val = '';
@ -213,7 +213,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildFlapping(stdClass $object)
private function buildFlapping($object)
{
$val = '';
@ -233,7 +233,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return string
*/
private function buildScheduledDowntime(stdClass $object)
private function buildScheduledDowntime($object)
{
if ($object->in_downtime === '1') {
return self::VALUE_YES;
@ -248,13 +248,12 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
* @param stdClass $object
* @return array
*/
public function monitoringProperties(stdClass $object)
public function monitoringProperties($object)
{
$type = $this->getObjectType($object);
$object = $this->dropObjectType($object, $type);
//$object = $this->dropObjectType($object, $type);
$out = array();
foreach (self::$keys as $property => $label) {
$label = sprintf($label, ucfirst($type));
if (is_callable(array(&$this, $property))) {
@ -267,7 +266,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
return $out;
}
public function getNotificationType(stdClass $notification)
public function getNotificationType($notification)
{
$reason = intval($notification->notification_reason);
if (!isset(self::$notificationReasons[$reason])) {

View File

@ -22,7 +22,7 @@ function formatDateString($self,$dateString){
</div>
<div>
<?= $this->paginationControl(
$downtimes,
$this->downtimes,
null,
array(
'mixedPagination.phtml',
@ -114,4 +114,4 @@ function formatDateString($self,$dateString){
<?php endforeach ?>
</table>
</div>
</div>
</div>

View File

@ -4,6 +4,7 @@
$viewHelper = $this->getHelper('MonitoringState');
?>
<h1>Hosts Status</h1>
<div data-icinga-component="app/mainDetailGrid">
<?= $this->sortControl->render($this); ?>
@ -12,7 +13,7 @@ $viewHelper = $this->getHelper('MonitoringState');
<table class="table table-condensed">
<thead>
<tr>
<th colspan="2">Status</th>
<th colspan="3">Status</th>
<th>Host</th>
<th>Output</th>
</tr>
@ -24,67 +25,102 @@ $viewHelper = $this->getHelper('MonitoringState');
<tr <?= ($this->activeRowHref === $hostLink) ? 'class="active"' : ''; ?> >
<td>
<a style="visibility:hidden" href="<?= $hostLink; ?>"></a>
<div>
<form class="reschedule">
</form>
<?php if ($host->host_icon_image) : ?>
<?php if ($host->host_icon_image) : ?>
<img src="<?= $host->host_icon_image; ?>"/>
<?php endif; ?>
</div>
<?php endif; ?>
</td>
<td>
<div>
<?php if (!$host->host_handled && $host->host_state > 0): ?>
<a href="#" title="<?= 'Unhandled host' ?>">
<i>{{UNHANDLED_ICON}}</i>
</a>
<?php endif; ?>
<?php if (!$host->host_handled && $host->host_state > 0): ?>
<a href="#" title="Unhandled">
<i>{{UNHANDLED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($host->host_acknowledged && !$host->host_in_downtime): ?>
<a href="#" title="<?= 'Acknowledged' ?>">
<i>{{ACKNOWLEDGED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($host->host_acknowledged && !$host->host_in_downtime): ?>
<a href="#" title="Acknowledged">
<i>{{ACKNOWLEDGED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($host->host_is_flapping): ?>
<a href="#" title="<?= 'Flapping' ?>">
<i>{{FLAPPING_ICON}}</i>
</a>
<?php if ($host->host_is_flapping): ?>
<a href="#" title="Flapping">
<i>{{FLAPPING_ICON}}</i>
</a>
<?php endif; ?>
<?php if (!$host->host_notifications_enabled): ?>
<a href="#" title="Notifications Disabled">
<i>{{NOTIFICATIONS_DISABLED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($host->host_in_downtime): ?>
<a href="#" title="In Downtime">
<i>{{IN_DOWNTIME_ICON}}</i>
</a>
<?php endif; ?>
<?php if (!$host->host_active_checks_enabled): ?>
<?php if (!$host->host_passive_checks_enabled): ?>
<a href="#" title="Active And Passive Checks Disabled">
<i>{{ACTIVE_PASSIVE_CHECKS_DISABLED_ICON}}</i>
</a>
<?php else: ?>
<a href="#" title="Active Checks Disabled">
<i>{{ACTIVE_CHECKS_DISABLED_ICON}}</i>
</a>
<?php endif; ?>
</div>
</td>
<td>
<?php endif; ?>
<?php if ($host->host_last_comment !== null): ?>
<a href="#" title="<?= 'Comments' ?>">
<a href="#" title="Comments">
<i>{{COMMENT_ICON}}</i>
</a>
<?php endif; ?>
</td>
<a href="<?= $hostLink ?>">
<b> <?= $host->host_name ?></b><br/>
<i> <?= $host->host_address ?></i>
<td title="<?= $viewHelper->getStateTitle($host, 'host'); ?>">
<div>
<?php if ($host->host_state_type == 0): ?>
<a href="#" title="Soft State">
<i>{{SOFTSTATE_ICON}}</i>
</a>
<?php endif; ?>
<b><?= ucfirst($viewHelper->monitoringState($host, 'host')); ?></b>
Since&nbsp;
<?= $this->timeSince($host->host_last_state_change); ?>
</div>
</td>
<td>
<?php if ($host->host_unhandled_service_count): ?>
<span class="badge pull-right">
<a href="<?= $this->href('monitoring/list/services', array('host' => $host->host_name, 'service_problems' => 1)); ?>">
<?= $host->host_unhandled_service_count; ?>
</a>
</span>
<?php endif; ?>
<a href="<?= $this->href('monitoring/list/services', array('host' => $host->host_name)) ?>">
<b><?= $host->host_name ?></b><br/>
<i><?= $host->host_address ?></i>
</a>
<?php if ($host->host_action_url != ""): ?>
<?php if (!empty($host->host_action_url)): ?>
<a href="<?= $host->host_action_url; ?>">Action</a>
<?php endif; ?>
<?php if ($host->host_notes_url != ""): ?>
<a href="<?= $host->host_notes_url; ?>">Notes</a>
<?php if (!empty($host->host_notes_url)): ?>
<a href="<?= $host->host_notes_url; ?>">Notes</a>
<?php endif; ?>
</td>
<td>
<?= $this->escape(substr(strip_tags($host->host_output), 0, 10000)); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?= $this->paginationControl($hosts, null, null, array('preserve' => $this->preserve)); ?>
<?= $this->paginationControl($hosts, null, null, array('preserve' => $this->preserve)); ?>
</div>

View File

@ -3,10 +3,12 @@
<?php
$viewHelper = $this->getHelper('MonitoringState');
?>
<h1>Services Status</h1>
<div data-icinga-component="app/mainDetailGrid">
<?= $this->sortControl->render($this); ?>
<?= $this->paginationControl($this->services, null, null, array('preserve' => $this->preserve)) ?>
<?= $this->sortControl->render($this); ?>
<?= $this->paginationControl($this->services, null, null, array('preserve' => $this->preserve)); ?>
<table class="table table-condensed">
<thead>
@ -30,100 +32,106 @@ $viewHelper = $this->getHelper('MonitoringState');
'host' => $service->host_name,
)
);
?>
?>
<tr <?= ($this->activeRowHref === $serviceLink) ? 'class="active"' : ''; ?>>
<td>
<a style="visibility:hidden" href="<?= $serviceLink; ?>"></a>
<div>
<?php if ($service->service_icon_image) : ?>
<?php if ($service->service_icon_image) : ?>
<img src="<?= $service->service_icon_image; ?>"/>
<?php endif; ?>
</div>
<?php endif; ?>
</td>
<td>
<div>
<?php if (!$service->service_handled && $service->service_state > 0): ?>
<a href="#" title="<?= 'Unhandled service' ?>">
<i>{{UNHANDLED_ICON}}</i>
</a>
<?php endif; ?>
<?php if (!$service->service_handled && $service->service_state > 0): ?>
<a href="#" title="Unhandled">
<i>{{UNHANDLED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($service->service_acknowledged && !$service->service_in_downtime): ?>
<a href="#" title="<?= 'Acknowledged' ?>">
<i>{{ACKNOWLEDGED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($service->service_acknowledged && !$service->service_in_downtime): ?>
<a href="#" title="Acknowledged">
<i>{{ACKNOWLEDGED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($service->service_is_flapping): ?>
<a href="#" title="<?= 'Flapping' ?>">
<i>{{FLAPPING_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($service->service_is_flapping): ?>
<a href="#" title="Flapping">
<i>{{FLAPPING_ICON}}</i>
</a>
<?php endif; ?>
<?php if (!$service->service_notifications_enabled): ?>
<a href="#" title="<?= 'Notifications disabled' ?>">
<i>{{NOTIFICATIONS_DISABLED_ICON}}</i>
</a>
<?php endif; ?>
<?php if (!$service->service_notifications_enabled): ?>
<a href="#" title="Notifications Disabled">
<i>{{NOTIFICATIONS_DISABLED_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($service->service_in_downtime): ?>
<a href="#" title="<?= 'In downtime' ?>">
<i>{{IN_DOWNTIME_ICON}}</i>
</a>
<?php endif; ?>
<?php if ($service->service_in_downtime): ?>
<a href="#" title="In Downtime">
<i>{{IN_DOWNTIME_ICON}}</i>
</a>
<?php endif; ?>
</div>
</td>
<td title="<?= $viewHelper->getStateTitle($service, 'service'); ?>">
<div>
<b><?= ucfirst($viewHelper->monitoringState($service, 'service')); ?></b>
<div> Since&nbsp;
<?= $this->timeSince($service->service_last_state_change); ?>
<?php if ($service->service_state_type == 0): ?>
<a href="#" title="<?= 'Soft state' ?>">
<i>{{SOFTSTATE_ICON}}</i>
<?php if (!$service->service_active_checks_enabled): ?>
<?php if (!$service->service_passive_checks_enabled): ?>
<a href="#" title="Active And Passive Checks Disabled">
<i>{{ACTIVE_PASSIVE_CHECKS_DISABLED_ICON}}</i>
</a>
<?php else: ?>
<a href="#" title="Active Checks Disabled">
<i>{{ACTIVE_CHECKS_DISABLED_ICON}}</i>
</a>
<?php endif; ?>
</div>
</div>
</td>
<?php endif; ?>
<td>
<?php if ($service->service_last_comment !== null): ?>
<a href="#" title="<?= 'Comments' ?>">
<a href="#" title="Comments">
<i>{{COMMENT_ICON}}</i>
</a>
<?php endif; ?>
<a href="<?= $serviceLink; ?>">
</td>
<td title="<?= $viewHelper->getStateTitle($service, 'service'); ?>">
<div>
<?php if ($service->service_state_type == 0): ?>
<a href="#" title="Soft State">
<i>{{SOFTSTATE_ICON}}</i>
</a>
<?php endif; ?>
<b><?= ucfirst($viewHelper->monitoringState($service, 'service')); ?></b>
Since&nbsp;
<?= $this->timeSince($service->service_last_state_change); ?>
</div>
</td>
<td>
<!--<a href="<?= $serviceLink; ?>">-->
<b> <?= $service->service_display_name; ?></b>
</a>
<!--</a>-->
<br/>
<?php if ($service->service_action_url != ""): ?>
<?php if (!empty($service->service_action_url)): ?>
<a href="<?= $service->service_action_url; ?>">Action</a>
<?php endif; ?>
<?php if ($service->service_notes_url != ""): ?>
<?php if (!empty($service->service_notes_url)): ?>
<a href="<?= $service->service_notes_url; ?>">Notes</a>
<?php endif; ?>
</td>
<td title="<?= $viewHelper->getStateTitle($service, 'host'); ?>">
<a href="<?= $hostLink; ?>">
<?= $service->host_name; ?>
<?php if (!$service->host_handled && $service->host_state > 0): ?>
<a href="#" title="Unhandled Host">
<i>{{UNHANDLED_ICON}}</i>
</a>
<?php endif; ?>
<a href="<?= $this->href('monitoring/list/services', array('host' => $service->host_name)) ?>">
<b><?= $service->host_name; ?></b>
<?php if ($service->host_state != 0): ?>
(<?= ucfirst($viewHelper->monitoringState($service, 'host')); ?>)
<?php endif; ?>
<br /><?= $service->host_address ?>
</a>
<div>
(<?= ucfirst($viewHelper->monitoringState($service, 'host')); ?>)
</div>
<span>
<?= $service->host_address ?>
</span>
</td>
<td>
@ -133,4 +141,5 @@ $viewHelper = $this->getHelper('MonitoringState');
<?php endforeach; ?>
</tbody>
</table>
</div>
<?= $this->paginationControl($this->services, null, null, array('preserve' => $this->preserve)); ?>
</div>

View File

@ -1,7 +1,27 @@
<?php
$commandParts = preg_split('|!|', $object->check_command);
$commandName = array_shift($commandParts);
?>
<div class="panel panel-default">
<div class="panel-heading">
{{CHECK_COMMAND_ICON}}
<span>Check Command</span>
</div>
{{COMMAND_ICON}} <b>Command:</b> <?= $commandName; ?>
<?= $this->commandArguments($object->check_command); ?>
<div class="panel-body">
<table>
<tr>
<td>Command</td>
<td>
<?php
$explodedCommand = explode('!', $this->object->check_command, 2);
$command = array_shift($explodedCommand);
echo $command;
?>
</td>
</tr>
<tr>
<td>Arguments</td>
<td>
<?= $this->commandArguments($this->object->check_command); ?>
</td>
</tr>
</table>
</div>
</div>

View File

@ -1,18 +1,9 @@
<?php if (! empty($this->comments)): ?>
<?php if (!empty($object->comments)): ?>
<?
$list = array();
foreach ($this->comments as $comment) {
if ($this->ticket_pattern) {
$text = preg_replace(
$this->ticket_pattern,
$this->ticket_link,
$this->escape($comment->comment_data)
);
} else {
$text = $this->escape($comment->comment_data);
}
$list[] = sprintf(
$commets = array();
foreach ($object->comments as $comment) {
$text = $this->escape($comment->comment_data);
$commets[] = sprintf(
'[%s] %s (%s): %s',
$this->escape($comment->comment_author),
$this->format()->timeSince($comment->comment_timestamp),
@ -21,13 +12,18 @@ foreach ($this->comments as $comment) {
);
}
?>
<div class="panel">
<?php endif; ?>
<div class="panel panel-default ">
<div class="panel-heading">
<span>{{COMMENT_ICON}} Comments</span>
</div>
<div class="panel-body">
<blockquote> <?= implode('<br />', $list) ?></blockquote>
<a href="#" class="button">{{COMMENT_COMMAND_BUTTON}}</a>
<a href="#" class="button">{{NOTIFICATION_COMMAND_BUTTON}}</a><br/>
<?php if (!empty($object->comments)): ?>
<blockquote> <?= implode('<br />', $commets); ?><a href="#" class="button">{{REMOVE_COMMENT_COMMAND}}</a></blockquote>
<?php else: ?>
No comments
<?php endif; ?>
</div>
</div>
<?php endif; ?>

View File

@ -1,31 +1,51 @@
<?php if (!empty($object->contacts)): ?>
<?php
if (!empty($this->contacts)) {
$contactList = array();
foreach ($this->contacts as $contact) {
$contactList[] = '<a href="' . $this->href(
'monitoring/show/contact',
array(
$contacts = array();
foreach ($object->contacts as $contact) {
$contacts[] = '<a href="'
. $this->href(
'monitoring/show/contact',
array(
'contact_name' => $contact->contact_name
)
) . '">' . $contact->contact_alias . '</a>';
}
echo '<strong>{{CONTACT_ICON}} Contacts:</strong> ';
echo implode(', ', $contactList);
}
if (!empty($this->contactgroups)) {
$contactGroupList = array();
foreach ($this->contactgroups as $contactgroup) {
$contactGroupList[] = '<a href="' . $this->href(
'monitoring/show/contactgroup',
array(
'contactgroup_name' => $contactgroup->contactgroup_name
)
) . '">' . $contactgroup->contactgroup_alias . '</a>';
}
echo '<strong>{{CONTACTGROUP_ICON}} Contactgroups:</strong> ';
echo implode(', ', $contactGroupList);
}
)
)
. '">'
. $contact->contact_alias
. '</a>';
}
?>
<div class="panel panel-default">
<div class="panel-heading">
{{CONTACT_ICON}} <span>Contacts</span>
</div>
<div class="panel-body">
<?= implode(', ', $contacts); ?>
</div>
</div>
<?php endif; ?>
<?php if (!empty($object->contactgroups)): ?>
<?php
$contactgroups = array();
foreach ($object->contactgroups as $contactgroup) {
$contactgroups[] = '<a href="'
. $this->href(
'monitoring/show/contactgroup',
array(
'contactgroup_name' => $contactgroup->contactgroup_name
)
)
. '">'
. $contactgroup->contactgroup_alias
. '</a>';
}
?>
<div class="panel panel-default">
<div class="panel-heading">
{{CONTACTGROUP_ICON}} <span>Contactgroups</span>
</div>
<div class="panel-body">
<?= implode(', ', $contactgroups); ?>
</div>
</div>
<?php endif; ?>

View File

@ -1,22 +1,23 @@
<?php if (isset($this->customvars) && count($this->customvars)) { ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>Customvariables</span>
</div>
<div class="panel-body">
<?php if (isset($object->customvars) && count($object->customvars)) { ?>
<table>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<?php foreach ($this->customvars as $name => $value) { ?>
<?php foreach ($object->customvars as $name => $value) { ?>
<tr>
<td><?= $this->escape($name) ?></td>
<td><?= $this->escape($value) ?></td>
</tr>
<?php } ?>
</table>
<?php } ?>
</div>
</div>
<?php } ?>

View File

@ -27,17 +27,21 @@
$list[] = '<td>'. implode('</td><td>', $row). '</td>';
}
?>
<?php endif; ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>{{IN_DOWNTIME_ICON}} Downtimes</span>
{{IN_DOWNTIME_ICON}}<span>Downtimes</span>
</div>
<div class="panel-body">
<a href="#" class="button">{{SCHEDULE_DOWNTIME_COMMAND_BUTTON}}</a><br/>
<?php if (!empty($this->downtimes)): ?>
<table>
<tr>
<?= implode('</tr><tr>', $list); ?>
<?= implode('</tr><tr>', $list); ?>
</tr>
</table>
<?php else: ?>
Not in downtime
<?php endif; ?>
</div>
</div>
<?php endif; ?>

View File

@ -0,0 +1,103 @@
<?php if (!empty($object->eventHistory)): ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>History</span>
</div>
<div class="panel-body">
<table class="table table-condensed">
<tbody>
<?php foreach ($object->eventHistory as $event): ?>
<tr>
<td><?= date('d.m. H:i', $event->timestamp); ?></td>
<td>
<?php if ($object instanceof Icinga\Module\Monitoring\Object\Service): ?>
<a href="<?= $this->href('monitoring/show/service', array(
'host' => $object->host_name,
'service' => $event->service_description
)); ?>">
<?= $event->service_description ?>
</a>
<?php else: ?>
<a href="<?= $this->href('monitoring/show/host', array(
'host' => $object->host_name
)); ?>">
<?= $event->host_name ?>
</a>
<?php endif; ?>
</td>
<td>
<?php
switch ($event->type) {
case 'notify':
$icon = '{{NOTIFICATION_ICON}}';
$title = 'Notification';
$msg = $event->output;
break;
case 'comment':
$icon = '{{COMMENT_ICON}}';
$title = 'Comment';
$msg = $event->output;
break;
case 'ack':
$icon = '{{ACKNOWLEDGEMENT_ICON}}';
$title = 'Acknowledgement';
$msg = '';
break;
case 'dt_comment':
$icon = '{{IN_DOWNTIME_ICON}}';
$title = 'In Downtime';
$msg = $event->output;
break;
case 'flapping':
$icon = '{{FLAPPING_ICON}}';
$title = 'Flapping';
$msg = '';
break;
case 'hard_state':
$icon = '{{HARDSTATE_ICON}}';
$title = 'Hard State';
$msg = '[' . $event->attempt . '/' . $event->max_attempts . ']';
break;
case 'soft_state':
$icon = '{{SOFTSTATE_ICON}}';
$title = 'Soft State';
$msg = '[' . $event->attempt . '/' . $event->max_attempts . ']';
break;
case 'dt_start':
$icon = '{{DOWNTIME_START_ICON}}';
$title = 'Downtime Start';
$msg = $event->output;
break;
case 'dt_end':
$icon = '{{DOWNTIME_END_ICON}}';
$title = 'Downtime End';
$msg = $event->output;
break;
}
?>
<a href="#" title="<?= $title ?>"><i><?= $icon ?></i></a>
<?php if (!empty($msg)) { echo $msg; } ?>
</td>
</tr>
<? endforeach; ?>
</tbody>
</table>
<?php if ($object instanceof Icinga\Module\Monitoring\Object\Service): ?>
<a href="<?= $this->href('monitoring/list/eventhistory', array(
'host' => $object->host_name,
'service' => $object->service_description
)); ?>">
All events for <?= $event->service_description ?>
</a>
<?php else: ?>
<a href="<?= $this->href('monitoring/list/eventhistory', array(
'host' => $object->host_name
)); ?>">
All events for <?= $event->host_name ?>
</a>
<?php endif; ?>
</div>
</div>
<?php endif; ?>

View File

@ -1,25 +1,22 @@
<?php
$object = null;
if (isset($this->service)) {
$object = $this->service;
} elseif (isset($this->host)) {
$object = $this->host;
}
$flags = $this->monitoringFlags($object);
?>
<table class="table table-condensed">
<?php foreach ($flags as $name => $value): ?>
<tr>
<th><?= $name; ?></th>
<td>
<?php if ($value === true): ?>
<span>{{ENABLED_ICON}} ENABLED</span>
<?php else: ?>
<span>{{DISABLED_ICON}} DISABLED</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<div class="panel panel-default">
<div class="panel-heading">Heading</div>
<div class="panel-body">
<table class="table table-condensed">
<?php foreach ($this->monitoringFlags($object) as $flag => $enabled): ?>
<tr>
<th><?= $flag; ?></th>
<td>
<?php if ($enabled === true): ?>
<span>{{ENABLED_ICON}} ENABLED</span>
<?php else: ?>
<span>{{DISABLED_ICON}} DISABLED</span>
<?php endif; ?>
</td>
<td>
<a class="button" href="#">{{{ENABLE_OR_DISABLE_COMMAND}}}</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>

View File

@ -0,0 +1,18 @@
<?php if (!empty($object->hostgroups)): ?>
<?php
$hostgroups = array();
foreach ($object->hostgroups as $name => $alias) {
$hostgroups[] = '<a href="' . $this->href('monitoring/list/hosts', array('hostgroups' => $name)) . '">'
. $alias
. '</a>';
}
?>
<div class="panel panel-default">
<div class="panel-heading">
{{HOSTGROUP_ICON}} <span>Hostgroups</span>
</div>
<div class="panel-body">
<?= implode(', ', $hostgroups); ?>
</div>
</div>
<?php endif; ?>

View File

@ -1,19 +1,15 @@
<?php
$object = null;
if (isset($this->service)) {
$object = $this->service;
} elseif (isset($this->host)) {
$object = $this->host;
}
$properties = $this->monitoringProperties($object);
?>
<table class="table table-bordered">
<?php foreach ($properties as $label => $value): ?>
<tr>
<th><?= $label ?></th>
<td><?= $value ?></td>
</tr>
<?php endforeach; ?>
</table>
<div class="panel panel-default">
<div class="panel-heading">
<span>Properties</span>
</div>
<div class="panel-body">
<table class="table table-bordered">
<?php foreach ($this->monitoringProperties($object) as $label => $value): ?>
<tr>
<th><?= $label ?></th>
<td><?= $value ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>

View File

@ -1,12 +1,18 @@
<?php if (!empty($object->servicegroups)): ?>
<?php
if (empty($object->servicegroups)) return;
$list = array();
$servicegroups = array();
foreach ($object->servicegroups as $name => $alias) {
$list[] = '<a href="' . $this->href('monitoring/list/service', array('servicegroups' => $name)) . '">'
. $alias
. '</a>';
$servicegroups[] = '<a href="' . $this->href('monitoring/list/service', array('servicegroups' => $name)) . '">'
. $alias
. '</a>';
}
echo '{{SERVICEGROUP_ICON}} <b>Servicegroups:</b> ' . implode(', ', $list) . "<br />\n";
?>
<div class="panel panel-default">
<div class="panel-heading">
{{SERVICEGROUP_ICON}} <span>Servicegroups</span>
</div>
<div class="panel-body">
<?= implode(', ', $servicegroups); ?>
</div>
</div>
<?php endif; ?>

View File

@ -20,12 +20,7 @@ if (!$this->compact) {
<div>
<?php if ($inlineCommands === true): ?>
<div class="pull-right">
<?=
$this->monitoringCommands(
($showService === true) ? $this->service : $this->host,
'small'
);
?>
</div>
<?php endif; ?>
@ -33,43 +28,43 @@ if (!$this->compact) {
<tr>
<td>
{{HOST_ICON}}
<?php if ($this->host->host_icon_image): ?>
<?php if ($this->object->host_icon_image): ?>
<div>
<img src="<?= $this->host->host_icon_image; ?>" alt="Host image"/>
<img src="<?= $this->object->host_icon_image; ?>" alt="Host image"/>
</div>
<?php endif; ?>
<strong>
<?= $this->escape($this->host->host_name); ?>
<?php if ($this->host->host_address && $this->host->host_address !== $this->host->host_name): ?>
(<?= $this->escape($this->host->host_address); ?>)
<?= $this->escape($this->object->host_name); ?>
<?php if ($this->object->host_address && $this->object->host_address !== $this->object->host_name): ?>
(<?= $this->escape($this->object->host_address); ?>)
<?php endif; ?>
</strong>
<?php if (isset($this->host->host_alias) && $this->host->host_alias !== $this->host->host_name): ?>
<?php if (isset($this->object->host_alias) && $this->object->host_alias !== $this->object->host_name): ?>
<br/>
<sup>(<?= $this->host->host_alias; ?>)</sup>
<sup>(<?= $this->object->host_alias; ?>)</sup>
<?php endif; ?>
</td>
<td
<?= $showService ? '' : ' rowspan="2"'; ?>
<?= $this->util()->getHostStateName($this->host->host_state); ?>
since <?= $this->timeSince($this->host->host_last_state_change); ?>
<?php if ($this->host->host_acknowledged === '1'): ?>
<?= $this->util()->getHostStateName($this->object->host_state); ?>
since <?= $this->timeSince($this->object->host_last_state_change); ?>
<?php if ($this->object->host_acknowledged === '1'): ?>
(Has been acknowledged)
<?php endif; ?>
</td>
</tr>
<?php if ($this->host->host_action_url || $this->host->host_notes_url): ?>
<?php if ($this->object->host_action_url || $this->object->host_notes_url): ?>
<tr>
<td rowspan="2">
<?php if ($this->host->host_action_url): ?>
<?php if ($this->object->host_action_url): ?>
{{EXTERNAL_LINK_ICON}}
<a target="_new" href='<?= $this->host->host_notes_url ?>'>Host actions </a>
<a target="_new" href='<?= $this->object->host_notes_url ?>'>Host actions </a>
<?php endif; ?>
<?php if ($this->host->host_notes_url): ?>
<?php if ($this->object->host_notes_url): ?>
{{EXTERNAL_LINK_ICON}}
<a target="_new" href='<?= $this->host->host_notes_url ?>'>Host notes </a>
<a target="_new" href='<?= $this->object->host_notes_url ?>'>Host notes </a>
<?php endif; ?>
</td>
</tr>
@ -116,4 +111,4 @@ if (!$this->compact) {
<?php endif; ?>
</table>
<div class="clearfix"></div>
</div>
</div>

View File

@ -4,83 +4,4 @@ $history->limit(10);
$hhistory = $this->history->paginate();
?>
<?php if (empty($hhistory)): ?>
There are no matching history entries right now
<?php else: ?>
<?= $this->paginationControl($hhistory, null, null, array('preserve' => $preserve)); ?>
<table class="table table-condensed">
<tbody>
<?php foreach ($hhistory as $event): ?>
<?php
if ($event->object_type == 'host') {
$states = array('up', 'down', 'unreachable', 'unknown', 99 => 'pending', null => 'pending');
} else {
$states = array('ok', 'warning', 'critical', 'unknown', 99 => 'pending', null => 'pending');
}
?>
<tr>
<td><?= date('d.m. H:i', $event->timestamp ) ?></td>
<? if (! $object): ?>
<td><?= $this->escape($event->host_name) ?></td>
<? endif ?>
<? if (! $object instanceof Icinga\Module\Monitoring\Object\Service): ?>
<td>
<? if ($object): ?>
<a href="<?= $this->href('monitoring/show/service',array(
'host' => $object->host_name,
'service' => $event->service_description
)); ?>"><?php $event->service_description; ?></a>
</a>
<? else: ?>
<?= $this->escape($event->service_description) ?>
<? endif ?>
</td>
<? endif ?>
<td>
<?php
switch ($event->type) {
case 'notify':
echo 'NOTIFICATION_ICON';
break;
case 'comment':
echo 'COMMENT_ICON';
break;
case 'ack':
echo 'ACKNOWLEDGEMENT_ICON';
break;
case 'dt_comment':
echo 'IN_DOWNTIME_ICON';
break;
case 'flapping':
echo 'FLAPPING_ICON';
break;
case 'hard_state':
echo 'HARDSTATE_ICON';
break;
case 'soft_state':
echo 'SOFTSTATE_ICON';
break;
case 'dt_start':
echo 'DOWNTIME_START_ICON';
echo ' Downtime start';
break;
case 'dt_end':
echo 'DOWNTIME_END_ICON';
echo ' Downtime end';
break;
}
?>
<? if ($event->attempt !== null): ?>
[ <?= $event->attempt ?>/<?=$event->max_attempts ?> ]
<? endif ?>
</td>
</tr>
<? endforeach ?>
</tbody>
</table>
<? endif ?>

View File

@ -1,107 +1,119 @@
<?php
$hostgroupLinkList = array();
if (!empty($this->hostgroups)) {
foreach ($this->hostgroups as $name => $alias) {
$hostgroupLinkList[] = '<a href="' . $this->href(
'monitoring/list/hosts',
array(
'hostgroups' => $name
)
) . '">'.$alias. '</a>';
}
}
?>
<?=
$this->partial(
'show/header.phtml',
array(
'host' => $this->host,
'service' => $this->service,
'tabs' => $this->tabs,
'compact' => $this->compact
)
);
?>
<?= $this->preview_image ?>
<br/>
<div class="panel panel-default">
<div class="panel-heading">
<span>Plugin Output</span>
</div>
<div class="panel-body">
<?= $this->pluginOutput($this->host->host_output); ?>
<?= $this->pluginOutput($this->host->host_long_output); ?>
</div>
<div class="panel-heading">
<?php if ($this->object->host_icon_image): ?>
<img src="<?= $this->object->host_icon_image; ?>" alt="Host image" />
<?php else: ?>
{{HOST_ICON}}
<?php endif; ?>
<h1>Host Status <?= $this->escape($this->object->host_name); ?></h1>
</div>
<div class="panel-body">
<table>
<tr>
<?php if (!$object->host_handled && $object->host_state > 0): ?>
<td>
<a href="#" title="Unhandled">
<i>{{UNHANDLED_ICON}}</i>
</a>
<a href="#" title="Acknowledge">
<i>{{ACKNOWLEDGE_COMMAND}}</i>
</a>
</td>
<?php endif; ?>
<?php if ($object->service_acknowledged && !$object->service_in_downtime): ?>
<td>
<a href="#" title="Acknowledged">
<i>{{ACKNOWLEDGED_ICON}}</i>
</a>
</td>
<?php else: ?>
<td>
Status
</td>
<?php endif; ?>
<td>
<?= $this->util()->getHostStateName($this->object->host_state); ?>
since <?= $this->timeSince($this->object->host_last_state_change); ?>
</td>
<td><a class="button" href="#">{{RECHECK_COMMAND_BUTTON}</a></td>
</tr>
<tr>
<td>Last Check</td>
<td><?= $object->last_check ?></td>
</tr>
<tr>
<td>Next Check</td>
<td><?= $object->next_check ?></td>
<td><a href="#" class="button">{{RESCHEDULE_COMMAND_BUTTON}}</a></td>
</tr>
<?php if ($this->object->host_address && $this->object->host_address !== $this->object->host_name): ?>
<tr>
<td>Host Address</td>
<td><?= $this->escape($this->object->host_address); ?></td>
</tr>
<?php endif; ?>
<?php if (isset($this->object->host_alias) && $this->object->host_alias !== $this->object->host_name): ?>
<tr>
<td>Alias</td>
<td><?= $this->object->host_alias; ?></td>
<?php endif; ?>
<?php if ($this->object->host_action_url || $this->object->host_notes_url): ?>
<tr>
<td rowspan="2">
<?php if ($this->object->host_action_url): ?>
<a target="_new" href='<?= $this->object->host_notes_url ?>'>{{HOST_ACTIONS_ICON}}</a>
<?php endif; ?>
<?php if ($this->object->host_notes_url): ?>
<a target="_new" href='<?= $this->object->host_notes_url ?>'>{{HOST_NOTES_ICON}}</a>
<?php endif; ?>
</td>
</tr>
<?php endif; ?>
<tr>
<td>Plugin Output</td>
<td>
<?= $this->pluginOutput($this->object->output); ?>
<?= $this->pluginOutput($this->object->long_output); ?>
</td>
<td>
<a class="button" href="#">{{SUBMIT_PASSIVE_CHECK_RESULT_COMMAND}}</a>
</td>
</tr>
<?php if ($this->object->perfdata): ?>
<tr>
<td>Performance Data</td>
<td><?= $this->perfdata($this->object->perfdata); ?></td>
</tr>
<?php endif; ?>
<tr>
<td colspan="2">
<a href="<?= $this->href('monitoring/list/services', array('host' => $object->host_name)); ?>">
View Services For This Host
</a>
</td>
<td>
<a class="button" href="#">{{{RECHECK_ALL_SERVICES_COMMAND}}</a>
</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
{{CHECK_ICON}} <span>Check Command</span>
</div>
<div class="panel-body">
<?php
$explodedCommand = explode('!', $this->host->host_check_command, 2);
array_shift($explodedCommand);
?>
<?= $this->commandArguments($this->host->host_check_command); ?>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<span>Groups and Contacts</span>
</div>
<div class="panel-body">
<?php if (count($hostgroupLinkList)): ?>
{{HOSTGROUP_ICON}} <strong>Hostgroups:</strong>
<?= implode(' ', $hostgroupLinkList); ?>
<?php endif; ?>
<?= $this->render('show/components/contacts.phtml') ?>
</div>
</div>
<?= $this->render('show/components/comments.phtml'); ?>
<?= $this->render('show/components/downtime.phtml'); ?>
<?= $this->render('show/components/comments.phtml'); ?>
<?= $this->render('show/components/properties.phtml'); ?>
<?= $this->render('show/components/flags.phtml'); ?>
<?= $this->render('show/components/hostgroups.phtml'); ?>
<?= $this->render('show/components/eventHistory.phtml'); ?>
<?= $this->render('show/components/contacts.phtml'); ?>
<?= $this->render('show/components/customvars.phtml'); ?>
<?php if ($this->host->host_perfdata): ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>Perfdata</span>
</div>
<div class="panel-body">
<?= $this->perfdata($this->host->host_perfdata); ?>
</div>
</div>
<?php endif; ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>Flags</span>
</div>
<div class="panel-body">
<?= $this->render('show/components/flags.phtml'); ?>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<span>Properties</span>
</div>
<div class="panel-body">
<?= $this->render('show/components/properties.phtml'); ?>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
{{COMMAND_ICON}} <span>Commands</span>
</div>
<div class="panel-body">
<?= $this->monitoringCommands($this->host, 'full'); ?>
</div>
</div>
<?= $this->render('show/components/command.phtml'); ?>

View File

@ -1,108 +1,124 @@
<?php
$servicegroupLinkList = array();
if (!empty($this->servicegroups)) {
foreach ($this->servicegroups as $name => $alias) {
$servicegroupLinkList[] = '<a href="' . $this->href(
'monitoring/list/services',
array(
'servicegroups' => $name
)
) . '">' . $alias . '</a>';
}
}
?>
<?=
$this->partial(
'show/header.phtml',
array(
'host' => $this->host,
'service' => $this->service,
'tabs' => $this->tabs,
'compact' => $this->compact
)
);
?>
<?= $this->preview_image ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>Plugin output</span>
</div>
<div class="panel-body">
<?= $this->pluginOutput($this->service->service_output); ?>
<?= $this->pluginOutput($this->service->service_long_output); ?>
</div>
<div class="panel-heading">
{{SERVICE_ICON}} <h1>Service Status <?= $this->escape($this->object->service_description); ?></h1>
</div>
<div class="panel-body">
<table>
<tr>
<?php if ($this->object->service_icon_image): ?>
<td>
<div>
<img src="<?= $this->object->service_icon_image; ?>" alt="Host image" />
</div>
</td>
<?php endif; ?>
<?php if (!$object->service_handled && $object->service_state > 0): ?>
<td>
<a href="#" title="Unhandled">
<i>{{UNHANDLED_ICON}}</i>
</a>
<a href="#" title="Acknowledge">
<i>{{ACKNOWLEDGE_COMMAND}}</i>
</a>
</td>
<?php endif; ?>
<?php if ($object->service_acknowledged && !$object->service_in_downtime): ?>
<td>
<a href="#" title="Acknowledged">
<i>{{ACKNOWLEDGED_ICON}}</i>
</a>
</td>
<?php endif; ?>
<td>
<strong><?= $this->util()->getServiceStateName($this->object->service_state); ?></strong>
since <?= $this->timeSince($this->object->service_last_state_change); ?>
</td>
<td><a class="button" href="#">{{RECHECK_COMMAND_BUTTON}</a></td>
</tr>
<?php if ($this->object->service_action_url || $this->object->service_notes_url): ?>
<tr>
<td rowspan="2">
<?php if ($this->object->service_action_url): ?>
{{SERVICE_ACTIONS_ICON}}
<a target="_new" href='<?= $this->object->service_notes_url ?>'>Host actions</a>
<?php endif; ?>
<?php if ($this->object->service_notes_url): ?>
{{SERVICE_NOTES_ICON}}
<a target="_new" href='<?= $this->object->service_notes_url ?>'>Host notes</a>
<?php endif; ?>
</td>
</tr>
<?php endif; ?>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
{{CHECK_ICON}} <span>Check Command</span>
</div>
<div class="panel-heading">
{{HOST_ICON}} <span><?= $this->escape($this->object->host_name); ?></span>
</div>
<div class="panel-body">
<?php
$explodedCommand = explode('!', $this->service->service_check_command, 2);
echo array_shift($explodedCommand);
?>
<?= $this->commandArguments($this->service->service_check_command); ?>
</div>
<div class="panel-body">
<table>
<tr>
<?php if ($this->object->host_icon_image): ?>
<td>
<div>
<img src="<?= $this->object->host_icon_image; ?>" alt="Host image" />
</div>
</td>
<?php endif; ?>
<?php if ($this->object->host_address && $this->object->host_address !== $this->object->host_name): ?>
<td>
<strong>Host Address:</strong> <?= $this->escape($this->object->host_address); ?>
</td>
<?php endif; ?>
<?php if (isset($this->object->host_alias) && $this->object->host_alias !== $this->object->host_name): ?>
<td>
<strong>Alias:</strong> <?= $this->object->host_alias; ?>
</td>
<?php endif; ?>
<td>
<strong><?= $this->util()->getHostStateName($this->object->host_state); ?></strong>
since <?= $this->timeSince($this->object->host_last_state_change); ?>
<?php if ($this->object->host_acknowledged === '1'): ?>
(Has been acknowledged)
<?php endif; ?>
</td>
</tr>
<?php if ($this->object->host_action_url || $this->object->host_notes_url): ?>
<tr>
<td rowspan="2">
<?php if ($this->object->host_action_url): ?>
{{HOST_ACTIONS_ICON}}
<a target="_new" href='<?= $this->object->host_notes_url ?>'>Host actions</a>
<?php endif; ?>
<?php if ($this->object->host_notes_url): ?>
{{HOST_NOTES_ICON}}
<a target="_new" href='<?= $this->object->host_notes_url ?>'>Host notes</a>
<?php endif; ?>
</td>
</tr>
<?php endif; ?>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
{{GROUP_ICON}} <span>Groups and Contacts</span>
</div>
<div class="panel-body">
<?php if (count($servicegroupLinkList)) { ?>
{{SERVICEGROUP_ICON}} <strong>Servicegroups:</strong>
<?= implode(' ', $servicegroupLinkList); ?>
<?php } ?>
<?= $this->render('show/components/contacts.phtml') ?>
</div>
</div>
<?= $this->render('show/components/comments.phtml'); ?>
<?= $this->render('show/components/command.phtml') ?>
<?= $this->render('show/components/downtime.phtml'); ?>
<?= $this->render('show/components/comments.phtml'); ?>
<?= $this->render('show/components/properties.phtml'); ?>
<?= $this->render('show/components/flags.phtml'); ?>
<?= $this->render('show/components/customvars.phtml'); ?>
<?php if ($this->service->service_perfdata): ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>Perfdata</span>
</div>
<div class="panel-body">
<?= $this->perfdata($this->service->service_perfdata); ?>
</div>
</div>
<?php endif; ?>
<?= $this->render('show/components/servicegroups.phtml'); ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>Flags</span>
</div>
<div class="panel-body">
<?= $this->render('show/components/flags.phtml'); ?>
</div>
</div>
<?= $this->render('show/components/contacts.phtml'); ?>
<div class="panel panel-default">
<div class="panel-heading">
<span>Properties</span>
</div>
<div class="panel-body">
<?= $this->render('show/components/properties.phtml'); ?>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
{{COMMAND_ICON}} <span>Commands</span>
</div>
<div class="panel-body">
<?= $this->monitoringCommands($this->service, 'full'); ?>
</div>
</div>
<?= $this->render('show/components/eventHistory.phtml'); ?>

View File

@ -1,2 +0,0 @@
<?= $this->render('show/components/header.phtml') ?>
<?= $services ?>

View File

@ -1,88 +1,122 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring;
use \Exception;
use \Icinga\Application\Config as IcingaConfig;
use \Icinga\Authentication\Manager as AuthManager;
use Zend_Config;
use Icinga\Application\Config as IcingaConfig;
use Icinga\Exception\ConfigurationError;
use Icinga\Data\DatasourceInterface;
use Icinga\Data\ResourceFactory;
use Icinga\Util\ConfigAwareFactory;
/**
* Container for monitoring backends
*/
class Backend
class Backend implements ConfigAwareFactory, DatasourceInterface
{
/**
* Array of backends
* Resource config
*
* @var array
* @var Zend_config
*/
protected static $instances = array();
private $config;
/**
* Array of configuration settings for backends
* The resource the backend utilizes
*
* @var array
* @var mixed
*/
protected static $backendConfigs;
private $resource;
private static $backendInstances = array();
private static $backendConfigs = array();
/**
* Locked constructor
* Create a new backend from the given resource config
*
* @param Zend_Config $backendConfig
* @param Zend_Config $resourceConfig
*/
final protected function __construct()
public function __construct(Zend_Config $backendConfig, Zend_Config $resourceConfig)
{
$this->config = $backendConfig;
$this->resource = ResourceFactory::createResource($resourceConfig);
}
/**
* Test if configuration key exist
* Set backend configs
*
* @param string $name
*
* @return bool
* @param Zend_Config $backendConfigs
*/
public static function exists($name)
public static function setConfig($backendConfigs)
{
$configs = self::getBackendConfigs();
return array_key_exists($name, $configs);
foreach ($backendConfigs as $name => $config) {
self::$backendConfigs[$name] = $config;
}
}
/**
* Get the first configuration name of all backends
* Backend entry point
*
* return self
*/
public function select()
{
return $this;
}
/**
* Create query to retrieve columns and rows from the the given table
*
* @param string $table
* @param array $columns
*
* @return Query
*/
public function from($table, array $columns = null)
{
$queryClass = '\\Icinga\\Module\\Monitoring\\Backend\\'
. ucfirst($this->config->type)
. '\\Query\\'
. ucfirst($table)
. 'Query';
return new $queryClass($this->resource, $columns);
}
/**
* Get the resource which was created in the constructor
*
* @return mixed
*/
public function getResource()
{
return $this->resource;
}
/**
* Get backend configs
*
* @return Zend_Config
*/
public static function getBackendConfigs()
{
if (empty(self::$backendConfigs)) {
self::setConfig(IcingaConfig::module('monitoring', 'backends'));
}
return self::$backendConfigs;
}
/**
* Retrieve the name of the default backend which is the INI's first entry
*
* @return string
*
* @throws Exception
* @throws ConfigurationError When no backend has been configured
*/
public static function getDefaultName()
public static function getDefaultBackendName()
{
$configs = self::getBackendConfigs();
if (empty($configs)) {
throw new Exception(
throw new ConfigurationError(
'Cannot get default backend as no backend has been configured'
);
}
@ -91,77 +125,32 @@ class Backend
}
/**
* Getter for backend configuration with lazy initializing
* Create the backend with the given name
*
* @return array
* @param $name
*
* @return Backend
*/
public static function getBackendConfigs()
public static function createBackend($name)
{
if (self::$backendConfigs === null) {
$resources = IcingaConfig::app('resources');
foreach ($resources as $resource) {
}
$backends = IcingaConfig::module('monitoring', 'backends');
foreach ($backends as $name => $config) {
self::$backendConfigs[$name] = $config;
}
if (array_key_exists($name, self::$backendInstances)) {
return self::$backendInstances[$name];
}
return self::$backendConfigs;
}
if ($name === null) {
$name = self::getDefaultBackendName();
}
/**
* Get a backend by name or a default one
*
* @param string $name
*
* @return AbstractBackend
*
* @throws Exception
*/
public static function getBackend($name = null)
{
if (! array_key_exists($name, self::$instances)) {
if ($name === null) {
$name = self::getDefaultName();
} else {
if (!self::exists($name)) {
throw new Exception(
sprintf(
'There is no such backend: "%s"',
$name
)
);
$config = self::$backendConfigs[$name];
self::$backendInstances[$name] = $backend = new self($config, ResourceFactory::getResourceConfig($config->resource));
switch (strtolower($config->type)) {
case 'ido':
if ($backend->getResource()->getDbType() !== 'oracle') {
$backend->getResource()->setTablePrefix('icinga_');
}
}
break;
$config = self::$backendConfigs[$name];
$type = $config->type;
$type[0] = strtoupper($type[0]);
$class = '\\Icinga\\Module\\Monitoring\\Backend\\' . $type;
self::$instances[$name] = new $class($config);
}
return self::$instances[$name];
}
/**
* Get backend by name or by user configuration
*
* @param string $name
*
* @return AbstractBackend
*/
public static function getInstance($name = null)
{
if (array_key_exists($name, self::$instances)) {
return self::$instances[$name];
} else {
if ($name === null) {
// TODO: Remove this, will be chosen by Environment
$name = AuthManager::getInstance()->getSession()->get('backend');
}
return self::getBackend($name);
}
return $backend;
}
}

View File

@ -11,7 +11,7 @@ class AbstractBackend implements DatasourceInterface
{
protected $config;
public function __construct(Zend_Config $config = null)
public function __construct(Zend_Config $config)
{
if ($config === null) {
// $config = new Zend_Config(array()); ???
@ -25,7 +25,7 @@ class AbstractBackend implements DatasourceInterface
}
/**
* Dummy function for fluent code
* Backend entry point
*
* return self
*/

View File

@ -1,64 +0,0 @@
<?php
namespace Icinga\Module\Monitoring\Backend;
use Icinga\Data\Db\Connection;
/**
* This class provides an easy-to-use interface to the IDO database
*
* You should usually not directly use this class but go through Icinga\Module\Monitoring\Backend.
*
* New MySQL indexes:
* <code>
* CREATE INDEX web2_index ON icinga_scheduleddowntime (object_id, is_in_effect);
* CREATE INDEX web2_index ON icinga_comments (object_id);
* CREATE INDEX web2_index ON icinga_objects (object_id, is_active); -- (not sure yet)
* </code>
*
* Other possible (history-related) indexes, still subject to tests:
* CREATE INDEX web2_index ON icinga_statehistory (object_id, state_time DESC);
* CREATE INDEX web2_time ON icinga_statehistory (state_time DESC);
* CREATE INDEX web2_index ON icinga_notifications (object_id, start_time DESC);
* CREATE INDEX web2_start ON icinga_downtimehistory (actual_start_time);
* CREATE INDEX web2_end ON icinga_downtimehistory (actual_end_time);
* CREATE INDEX web2_index ON icinga_commenthistory (object_id, comment_time);
* CREATE INDEX web2_object ON icinga_commenthistory (object_id);
* CREATE INDEX web2_time ON icinga_commenthistory (comment_time DESC);
*
* CREATE INDEX web2_notification_contact ON icinga_contactnotifications (contact_object_id, notification_id);
*
* These should be unique:
* CREATE INDEX web2_index ON icinga_host_contacts (host_id, contact_object_id);
* CREATE INDEX web2_index ON icinga_service_contacts (service_id, contact_object_id);
*
* ...and we should drop a lot's of useless and/or redundant index definitions
*/
class Ido extends AbstractBackend
{
protected $db;
protected $prefix = 'icinga_';
protected function init()
{
$this->db = new Connection($this->config);
if ($this->db->getDbType() === 'oracle') {
$this->prefix = '';
}
}
public function getConnection()
{
return $this->db;
}
/**
* Get our IDO table prefix
*
* return string
*/
public function getPrefix()
{
return $this->prefix;
}
}

View File

@ -34,14 +34,14 @@ abstract class AbstractQuery extends Query
{
return array_key_exists($column, $this->aggregateColumnIdx);
}
protected function init()
{
parent::init();
// TODO: $this->applyDbSpecificWorkarounds
$this->prefix = $this->ds->getPrefix();
$this->prefix = $this->ds->getTablePrefix();
if ($this->ds->getConnection()->getDbType() === 'oracle') {
if ($this->ds->getDbType() === 'oracle') {
$this->object_id = $this->host_id = $this->service_id
= $this->hostgroup_id = $this->servicegroup_id
= $this->contact_id = $this->contactgroup_id = 'id'; // REALLY?
@ -52,7 +52,7 @@ abstract class AbstractQuery extends Query
}
}
}
if ($this->ds->getConnection()->getDbType() === 'pgsql') {
if ($this->ds->getDbType() === 'pgsql') {
foreach ($this->columnMap as $table => & $columns) {
foreach ($columns as $key => & $value) {
$value = preg_replace('/ COLLATE .+$/', '', $value);
@ -115,7 +115,8 @@ abstract class AbstractQuery extends Query
protected function getDefaultColumns()
{
$table = array_shift(array_keys($this->columnMap));
reset($this->columnMap);
$table = key($this->columnMap);
return array_keys($this->columnMap[$table]);
}

View File

@ -31,6 +31,8 @@ class EventHistoryQuery extends AbstractQuery
'output' => 'eh.output', // we do not want long_output
//'problems' => 'CASE WHEN eh.state = 0 OR eh.state IS NULL THEN 0 ELSE 1 END',
'type' => 'eh.type',
'service_host_name' => 'eho.name1 COLLATE latin1_general_ci',
'service_description' => 'eho.name2 COLLATE latin1_general_ci'
),
'hostgroups' => array(
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
@ -74,7 +76,7 @@ class EventHistoryQuery extends AbstractQuery
}
if ($end) {
foreach ($this->subQueries as $query) {
$query->where('raw_timestamp', '<' . $start);
$query->where('raw_timestamp', '<' . $end);
}
}
$sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL);

View File

@ -24,7 +24,7 @@ class NotificationhistoryQuery extends AbstractQuery
//"('[' || cndetails.contacts || '] ' || n.output)"
// This is one of the db-specific workarounds that could be abstracted
// in a better way:
switch ($this->ds->getConnection()->getDbType()) {
switch ($this->ds->getDbType()) {
case 'mysql':
$concat_contacts = "GROUP_CONCAT(c.alias ORDER BY c.alias SEPARATOR ', ')";
break;
@ -73,7 +73,7 @@ $this->columnMap['history']['output'] = "('[' || $concat_contacts || '] ' || n.o
'cn.contact_object_id = c.contact_object_id',
array()
)->group('cn.notification_id')
/*->join(
array('cndetails' => $cndetails),
'cndetails.notification_id = n.notification_id',

View File

@ -1,45 +0,0 @@
<?php
/**
* Icinga Livestatus Backend
*
* @package Monitoring
*/
namespace Icinga\Module\Monitoring\Backend;
use Icinga\Protocol\Livestatus\Connection;
/**
* This class provides an easy-to-use interface to the Livestatus socket library
*
* You should usually not directly use this class but go through Icinga\Backend.
*
* @copyright Copyright (c) 2013 Icinga-Web Team <info@icinga.org>
* @author Icinga-Web Team <info@icinga.org>
* @package Icinga\Application
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
class Livestatus extends AbstractBackend
{
protected $connection;
/**
* Backend initialization starts here
*
* return void
*/
protected function init()
{
$this->connection = new Connection($this->config->socket);
}
/**
* Get our Livestatus connection
*
* return \Icinga\Protocol\Livestatus\Connection
*/
public function getConnection()
{
return $this->connection;
}
}

View File

@ -1,109 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Backend;
use Icinga\Protocol\Statusdat as StatusdatProtocol;
/**
* Class Statusdat
* @package Icinga\Backend
*/
class Statusdat extends AbstractBackend
{
/**
* @var null
*/
private $reader = null;
/**
*
*/
public function init()
{
$this->reader = new StatusdatProtocol\Reader($this->config);
}
/**
* @return null
*/
public function getReader()
{
return $this->reader;
}
/**
* @param array $filter
* @param array $flags
* @return mixed
*/
public function listServices($filter = array(), $flags = array())
{
$query = $this->select()->from("servicelist");
return $query->fetchAll();
}
/**
* @param $host
* @return MonitoringObjectList|null
*/
public function fetchHost($host, $fetchAll = false)
{
$objs = & $this->reader->getObjects();
if (!isset($objs["host"][$host])) {
return null;
}
$result = array($objs["host"][$host]);
return new MonitoringObjectList(
$result,
new StatusdatHostView($this->reader)
);
}
/**
* @param $host
* @param $service
* @return MonitoringObjectList|null
*/
public function fetchService($host, $service, $fetchAll = false)
{
$idxName = $host . ";" . $service;
$objs = & $this->reader->getObjects();
if (!isset($objs["service"][$idxName])) {
return null;
}
$result = array($objs["service"][$idxName]);
return new MonitoringObjectList(
$result,
new StatusdatServiceView($this->reader)
);
}
}

View File

@ -27,7 +27,7 @@ class StatusQuery extends Query
public function init()
{
$target = $this->getTarget();
$this->reader = $this->ds->getReader();
$this->reader = $this->ds;
$this->setResultViewClass(ucfirst($target)."StatusView");
$this->setBaseQuery($this->reader->select()->from($target."s", array()));

View File

@ -0,0 +1,176 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\DataView;
use Icinga\Data\AbstractQuery;
use Icinga\Module\Monitoring\Backend;
use Icinga\Web\Request;
/**
* A read-only view of an underlying Query
*/
abstract class DataView
{
/**
* The query used to populate the view
*
* @var AbstractQuery
*/
private $query;
/**
* Sort in ascending order, default
*/
const SORT_ASC = AbstractQuery::SORT_ASC;
/**
* Sort in reverse order
*/
const SORT_DESC = AbstractQuery::SORT_DESC;
/**
* Create a new view
*
* @param Backend $ds Which backend to query
* @param array $columns Select columns
*/
public function __construct(Backend $ds, array $columns = null)
{
$this->query = $ds->select()->from(static::getTableName(), $columns === null ? $this->getColumns() : $columns);
}
/**
* Get the queried table name
*
* @return string
*/
public static function getTableName()
{
$tableName = explode('\\', get_called_class());
$tableName = strtolower(end($tableName));
return $tableName;
}
/**
* Retrieve columns provided by this view
*
* @return array
*/
abstract public function getColumns();
/**
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
*
* @return array
*/
abstract public function getSortRules();
public function getFilterColumns()
{
return array();
}
/**
* Create view from request
*
* @param Request $request
* @param array $columns
*
* @return static
*/
public static function fromRequest($request, array $columns = null)
{
$view = new static(Backend::createBackend($request->getParam('backend')), $columns);
$view->filter($request->getParams());
$order = $request->getParam('dir');
if ($order !== null) {
if (strtolower($order) === 'desc') {
$order = self::SORT_DESC;
} else {
$order = self::SORT_ASC;
}
}
$view->sort(
$request->getParam('sort'),
$order
);
return $view;
}
/**
* Filter rows that match all of the given filters. If a filter is not valid, it's silently ignored
*
* @param array $filters
*
* @see isValidFilterColumn()
*/
public function filter(array $filters)
{
foreach ($filters as $column => $filter) {
if ($this->isValidFilterColumn($column)) {
$this->query->where($column, $filter);
}
}
}
/**
* Check whether the given column is a valid filter column, i.e. the view actually provides the column or it's
* a non-queryable filter column
*
* @param string $column
*
* @return bool
*/
protected function isValidFilterColumn($column)
{
return in_array($column, $this->getColumns()) || in_array($column, $this->getFilterColumns());
}
/**
* Sort the rows, according to the specified sort column and order
*
* @param string $column Sort column
* @param int $order Sort order, one of the SORT_ constants
*
* @see DataView::SORT_ASC
* @see DataView::SORT_DESC
*/
public function sort($column = null, $order = null)
{
$sortRules = $this->getSortRules();
if ($column === null) {
$sortColumns = reset($sortRules);
if (!isset($sortColumns['columns'])) {
$sortColumns['columns'] = array(key($sortRules));
}
} else {
if (isset($sortRules[$column])) {
$sortColumns = $sortRules[$column];
if (!isset($sortColumns['columns'])) {
$sortColumns['columns'] = array($column);
}
} else {
$sortColumns = array(
'columns' => array($column),
'order' => $order
);
};
}
$order = $order === null ? (isset($sortColumns['order']) ? $sortColumns['order'] : self::SORT_ASC) : $order;
foreach ($sortColumns['columns'] as $column) {
$this->query->order($column, $order);
}
}
/**
* Return the query which was created in the constructor
*
* @return mixed
*/
public function getQuery()
{
return $this->query;
}
}

View File

@ -0,0 +1,50 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\DataView;
class Downtime extends DataView
{
/**
* Retrieve columns provided by this view
*
* @return array
*/
public function getColumns()
{
return array(
'host_name',
'object_type',
'service_host_name',
'service_description',
'downtime_type',
'downtime_author_name',
'downtime_comment_data',
'downtime_is_fixed',
'downtime_duration',
'downtime_entry_time',
'downtime_scheduled_start_time',
'downtime_scheduled_end_time',
'downtime_was_started',
'downtime_actual_start_time',
'downtime_actual_start_time_usec',
'downtime_is_in_effect',
'downtime_trigger_time',
'downtime_triggered_by_id',
'downtime_internal_downtime_id'
);
}
public function getSortRules()
{
return array(
'downtime_is_in_effect' => array(
'order' => self::SORT_DESC
),
'downtime_actual_start_time' => array(
'order' => self::SORT_DESC
)
);
}
}

View File

@ -0,0 +1,133 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\DataView;
class HostAndServiceStatus extends DataView
{
/**
* Retrieve columns provided by this view
*
* @return array
*/
public function getColumns()
{
return array(
'host_name',
'host_state',
'host_state_type',
'host_last_state_change',
'host_address',
'host_handled',
'service_description',
'service_display_name',
'service_state',
'service_in_downtime',
'service_acknowledged',
'service_handled',
'service_output',
'service_last_state_change',
'service_icon_image',
'service_long_output',
'service_is_flapping',
'service_state_type',
'service_severity',
'service_last_check',
'service_notifications_enabled',
'service_action_url',
'service_notes_url',
'service_last_comment',
'host_icon_image',
'host_acknowledged',
'host_output',
'host_long_output',
'host_in_downtime',
'host_is_flapping',
'host_last_check',
'host_notifications_enabled',
'host_unhandled_service_count',
'host_action_url',
'host_notes_url',
'host_last_comment',
'host',
'host_display_name',
'host_alias',
'host_ipv4',
// 'host_problems',
'host_severity',
'host_perfdata',
'host_does_active_checks',
'host_accepts_passive_checks',
'host_last_hard_state',
'host_last_hard_state_change',
'host_last_time_up',
'host_last_time_down',
'host_last_time_unreachable',
'service',
// 'current_state',
'service_hard_state',
'service_perfdata',
'service_does_active_checks',
'service_accepts_passive_checks',
'service_last_hard_state',
'service_last_hard_state_change',
'service_last_time_ok',
'service_last_time_warning',
'service_last_time_critical',
'service_last_time_unknown',
'service_current_check_attempt',
'service_max_check_attempts'
// 'object_type',
// 'problems',
// 'handled',
// 'severity'
);
}
public static function getTableName()
{
return 'status';
}
public function getSortRules()
{
return array(
'host_name' => array(
'order' => self::SORT_ASC
),
'host_address' => array(
'columns' => array(
'host_ipv4',
'service_description'
),
'order' => self::SORT_ASC
),
'host_last_state_change' => array(
'order' => self::SORT_ASC
),
'host_severity' => array(
'columns' => array(
'host_severity',
'host_last_state_change',
),
'order' => self::SORT_ASC
)
);
}
public function getFilterColumns()
{
return array('hostgroups', 'servicegroups', 'service_problems');
}
protected function isValidFilterColumn($column)
{
if ($column[0] === '_'
&& preg_match('/^_(?:host|service)_/', $column)
) {
return true;
}
return parent::isValidFilterColumn($column);
}
}

View File

@ -0,0 +1,36 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\DataView;
class Notification extends DataView
{
/**
* Retrieve columns provided by this view
*
* @return array
*/
public function getColumns()
{
return array(
'host_name',
'service_description',
'notification_type',
'notification_reason',
'notification_start_time',
'notification_contact',
'notification_information',
'notification_command'
);
}
public function getSortRules()
{
return array(
'notification_start_time' => array(
'order' => self::SORT_DESC
)
);
}
}

View File

@ -3,7 +3,7 @@
namespace Icinga\Module\Monitoring\Object;
use Icinga\Data\AbstractQuery as Query;
use \Icinga\Module\Monitoring\Backend\AbstractBackend;
use \Icinga\Module\Monitoring\Backend;
abstract class AbstractObject
{
@ -26,7 +26,7 @@ abstract class AbstractObject
// 'comments' => null,
);
public function __construct(AbstractBackend $backend, $name1, $name2 = null)
public function __construct(Backend $backend, $name1, $name2 = null)
{
$this->backend = $backend;
$this->name1 = $name1;
@ -34,7 +34,7 @@ abstract class AbstractObject
$this->properties = (array) $this->fetchObject();
}
public static function fetch(AbstractBackend $backend, $name1, $name2 = null)
public static function fetch(Backend $backend, $name1, $name2 = null)
{
return new static($backend, $name1, $name2);
}
@ -142,4 +142,22 @@ abstract class AbstractObject
)->fetchPairs();
return $this;
}
protected function fetchEventHistory()
{
$this->foreign['eventHistory'] = $this->applyObjectFilter(
$this->backend->select()->from('eventHistory', array(
'object_type',
'host_name',
'service_description',
'timestamp',
'state',
'attempt',
'max_attempts',
'output',
'type'
))
);
return $this;
}
}

View File

@ -30,7 +30,8 @@ class Host extends AbstractObject
->fetchContacts()
->fetchContactgroups()
->fetchCustomvars()
->fetchComments();
->fetchComments()
->fetchEventHistory();
}
protected function fetchObject()
@ -52,6 +53,13 @@ class Host extends AbstractObject
'long_output' => 'host_long_output',
'check_command' => 'host_check_command',
'perfdata' => 'host_perfdata',
'host_icon_image',
'passive_checks_enabled' => 'host_passive_checks_enabled',
'obsessing' => 'host_obsessing',
'notifications_enabled' => 'host_notifications_enabled',
'event_handler_enabled' => 'host_event_handler_enabled',
'flap_detection_enabled' => 'host_flap_detection_enabled',
'active_checks_enabled' => 'host_active_checks_enabled'
))->where('host_name', $this->name1)->fetchRow();
}
}

View File

@ -32,7 +32,7 @@ class Service extends AbstractObject
->fetchContactgroups()
->fetchCustomvars()
->fetchComments()
;
->fetchEventHistory();
}
protected function fetchObject()
@ -60,6 +60,22 @@ class Service extends AbstractObject
'long_output' => 'service_long_output',
'check_command' => 'service_check_command',
'perfdata' => 'service_perfdata',
'current_check_attempt' => 'service_current_check_attempt',
'max_check_attemt' => 'service_max_check_attempts',
'state_type' => 'service_state_type',
'passive_checks_enabled' => 'service_passive_checks_enabled',
'last_state_change' => 'service_last_state_change',
'last_notification' => 'service_last_notification',
'current_notification_number' => 'service_current_notification_number',
'is_flapping' => 'service_is_flapping',
'percent_state_change' => 'service_percent_state_change',
'in_downtime' => 'service_in_downtime',
'passive_checks_enabled' => 'service_passive_checks_enabled',
'obsessing' => 'service_obsessing',
'notifications_enabled' => 'service_notifications_enabled',
'event_handler_enabled' => 'service_event_handler_enabled',
'flap_detection_enabled' => 'service_flap_detection_enabled',
'active_checks_enabled' => 'service_active_checks_enabled'
))
->where('host_name', $this->name1)
->where('service_description', $this->name2)

View File

@ -4,6 +4,11 @@ namespace Test\Monitoring\Application\Controllers\ListController;
require_once(dirname(__FILE__).'/../../testlib/MonitoringControllerTest.php');
require_once(dirname(__FILE__).'/../../../../library/Monitoring/DataView/DataView.php');
require_once(dirname(__FILE__).'/../../../../library/Monitoring/DataView/HostAndServiceStatus.php');
require_once(dirname(__FILE__).'/../../../../library/Monitoring/DataView/Notification.php');
require_once(dirname(__FILE__).'/../../../../library/Monitoring/DataView/Downtime.php');
use Test\Monitoring\Testlib\MonitoringControllerTest;
use Test\Monitoring\Testlib\Datasource\TestFixture;
use Test\Monitoring\Testlib\Datasource\ObjectFlags;

View File

@ -21,10 +21,10 @@ class ListControllerServiceMySQLTest extends MonitoringControllerTest
$this->executeServiceListTestFor("pgsql");
}
public function testServiceListStatusdat()
{
$this->executeServiceListTestFor("statusdat");
}
// public function testServiceListStatusdat()
// {
// $this->executeServiceListTestFor("statusdat");
// }
public function executeServiceListTestFor($backend)
{
@ -64,7 +64,6 @@ class ListControllerServiceMySQLTest extends MonitoringControllerTest
$this->assertEquals("notes.url", $result[0]->service_notes_url, "Testing for correct notes_url");
$this->assertEquals("action.url", $result[0]->service_action_url, "Testing for correct action_url");
$this->assertEquals(0, $result[0]->service_state, "Testing for correct Service state");
}
}

View File

@ -11,12 +11,12 @@ class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
public function testHosts1()
{
$testArray = array(
'host_passive_checks_enabled' => '0',
'host_active_checks_enabled' => '0',
'host_obsessing' => '1',
'host_notifications_enabled' => '0',
'host_event_handler_enabled' => '1',
'host_flap_detection_enabled' => '1',
'passive_checks_enabled' => '0',
'active_checks_enabled' => '0',
'obsessing' => '1',
'notifications_enabled' => '0',
'event_handler_enabled' => '1',
'flap_detection_enabled' => '1',
);
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
@ -39,12 +39,12 @@ class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
public function testService1()
{
$testArray = array(
'service_passive_checks_enabled' => '0',
'service_active_checks_enabled' => '1',
'service_obsessing' => '0',
'service_notifications_enabled' => '1',
'service_event_handler_enabled' => '1',
'service_flap_detection_enabled' => '0',
'passive_checks_enabled' => '0',
'active_checks_enabled' => '1',
'obsessing' => '0',
'notifications_enabled' => '1',
'event_handler_enabled' => '1',
'flap_detection_enabled' => '0',
);
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
@ -63,54 +63,4 @@ class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $returnArray);
}
public function testUglyConditions1()
{
$testArray = array(
'service_active_checks_enabled' => '1',
'service_obsessing' => '1',
'DING DING' => '$$$',
'DONG DONG' => '###'
);
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
$returnArray = $monitoringFlags->monitoringFlags((object)$testArray);
$this->assertCount(6, $returnArray);
$expected = array(
'Passive Checks' => false,
'Active Checks' => true,
'Obsessing' => true,
'Notifications' => false,
'Event Handler' => false,
'Flap Detection' => false
);
$this->assertEquals($expected, $returnArray);
}
public function testUglyConditions2()
{
$testArray = array(
'DING DING' => '$$$',
'DONG DONG' => '###'
);
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
$returnArray = $monitoringFlags->monitoringFlags((object)$testArray);
$this->assertCount(6, $returnArray);
$expected = array(
'Passive Checks' => false,
'Active Checks' => false,
'Obsessing' => false,
'Notifications' => false,
'Event Handler' => false,
'Flap Detection' => false
);
$this->assertEquals($expected, $returnArray);
}
}

View File

@ -7,7 +7,7 @@ require_once 'Zend/View.php';
require_once __DIR__. '/../../../../../application/views/helpers/MonitoringProperties.php';
/**
* @TODO(el): This test is subject to bug #4679 and
* @TODO(el): This test is subject to bug #4679 and
*/
class HostStruct4Properties extends \stdClass
{
@ -15,42 +15,42 @@ class HostStruct4Properties extends \stdClass
public $host_address = '127.0.0.1';
public $host_state = '1';
public $host_handled = '1';
public $host_in_downtime = '1';
public $host_acknowledged = '1';
public $host_check_command = 'check-host-alive';
public $host_last_state_change = '1372937083';
public $in_downtime = '1';
public $acknowledged = '1';
public $check_command = 'check-host-alive';
public $last_state_change = '1372937083';
public $host_alias = 'localhost';
public $host_output = 'DDD';
public $host_long_output = '';
public $host_perfdata = '';
public $host_current_check_attempt = '1';
public $host_max_check_attempts = '10';
public $host_attempt = '1/10';
public $host_last_check = '2013-07-04 11:24:42';
public $host_next_check = '2013-07-04 11:29:43';
public $host_check_type = '1';
public $host_last_hard_state_change = '2013-07-04 11:24:43';
public $host_last_hard_state = '0';
public $host_last_time_up = '2013-07-04 11:20:23';
public $host_last_time_down = '2013-07-04 11:24:43';
public $host_last_time_unreachable = '0000-00-00 00:00:00';
public $host_state_type = '1';
public $host_last_notification = '0000-00-00 00:00:00';
public $host_next_notification = '0000-00-00 00:00:00';
public $host_no_more_notifications = '0';
public $output = 'DDD';
public $long_output = '';
public $perfdata = '';
public $current_check_attempt = '1';
public $max_check_attempts = '10';
public $attempt = '1/10';
public $last_check = '2013-07-04 11:24:42';
public $next_check = '2013-07-04 11:29:43';
public $heck_type = '1';
public $last_hard_state_change = '2013-07-04 11:24:43';
public $last_hard_state = '0';
public $last_time_up = '2013-07-04 11:20:23';
public $last_time_down = '2013-07-04 11:24:43';
public $last_time_unreachable = '0000-00-00 00:00:00';
public $state_type = '1';
public $last_notification = '0000-00-00 00:00:00';
public $next_notification = '0000-00-00 00:00:00';
public $no_more_notifications = '0';
public $host_notifications_enabled = '1';
public $host_problem_has_been_acknowledged = '1';
public $host_acknowledgement_type = '2';
public $host_current_notification_number = '0';
public $host_passive_checks_enabled = '1';
public $host_active_checks_enabled = '0';
public $host_event_handler_enabled = '0';
public $host_flap_detection_enabled = '1';
public $host_is_flapping = '0';
public $host_percent_state_change = '12.36842';
public $host_check_latency = '0.12041';
public $host_check_execution_time = '0';
public $host_scheduled_downtime_depth = '1';
public $current_notification_number = '0';
public $passive_checks_enabled = '1';
public $active_checks_enabled = '0';
public $event_handler_enabled = '0';
public $flap_detection_enabled = '1';
public $is_flapping = '0';
public $percent_state_change = '12.36842';
public $check_latency = '0.12041';
public $check_execution_time = '0';
public $scheduled_downtime_depth = '1';
public $host_failure_prediction_enabled = '1';
public $host_process_performance_data = '1';
public $host_obsessing = '1';
@ -67,41 +67,34 @@ class MonitoringPropertiesTest extends \PHPUnit_Framework_TestCase
public function testOutput1()
{
$host = new HostStruct4Properties();
$host->host_current_check_attempt = '5';
$host->current_check_attempt = '5';
$propertyHelper = new \Zend_View_Helper_MonitoringProperties();
$items = $propertyHelper->monitoringProperties($host);
$this->assertCount(10, $items);
$this->assertEquals('5/10 (HARD state)', $items['Current Attempt']);
$this->assertEquals('2013-07-08 10:10:10', $items['Last Update']);
}
public function testOutput2()
{
date_default_timezone_set("UTC");
$host = new HostStruct4Properties();
$host->host_current_check_attempt = '5';
$host->host_active_checks_enabled = '1';
$host->host_passive_checks_enabled = '0';
$host->host_is_flapping = '1';
$host->current_check_attempt = '5';
$host->active_checks_enabled = '1';
$host->passive_checks_enabled = '0';
$host->is_flapping = '1';
$propertyHelper = new \Zend_View_Helper_MonitoringProperties();
$items = $propertyHelper->monitoringProperties($host);
$this->assertCount(10, $items);
$test = array(
'Current Attempt' => "5/10 (HARD state)",
'Last Check Time' => "2013-07-04 11:24:42",
'Check Type' => "ACTIVE",
'Check Latency / Duration' => "0.1204 / 0.0000 seconds",
'Next Scheduled Active Check' => "2013-07-04 11:29:43",
'Last State Change' => "2013-07-04 11:24:43",
'Last Notification' => "N/A (notification 0)",
'Is This Host Flapping?' => "YES (12.37% state change)",
'In Scheduled Downtime?' => "YES",
'Last Update' => "2013-07-08 10:10:10",
'In Scheduled Downtime?' => "YES"
);
$this->assertEquals($test, $items);

View File

@ -1,6 +1,8 @@
<?php
namespace Tests\Monitoring\Backend\Statusdat;
use Zend_Config;
use Tests\Icinga\Protocol\Statusdat\ReaderMock as ReaderMock;
use \Icinga\Module\Monitoring\Backend\Statusdat\Query\ServicegroupsummaryQuery;
use Tests\Icinga\Protocol\Statusdat\StatusdatTestLoader;
@ -30,10 +32,12 @@ class BackendMock extends \Icinga\Module\Monitoring\Backend\AbstractBackend
class ServicegroupsummaryqueryTest extends \PHPUnit_Framework_TestCase
{
public function testGroupByProblemType()
{
$backend = new BackendMock();
$backendConfig = new Zend_Config(
array()
);
$backend = new BackendMock($backendConfig);
$backend->setReader($this->getTestDataset());
$q = new ServicegroupsummaryQuery($backend);
$indices = array(

View File

@ -37,10 +37,10 @@ use \Zend_Test_PHPUnit_ControllerTestCase;
use \Icinga\Protocol\Statusdat\Reader;
use \Icinga\Web\Controller\ActionController;
use \Icinga\Application\DbAdapterFactory;
use \Icinga\Module\Monitoring\Backend\Ido;
use \Icinga\Module\Monitoring\Backend\Statusdat;
use \Test\Monitoring\Testlib\DataSource\TestFixture;
use \Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
use Icinga\Module\Monitoring\Backend;
use Icinga\Data\ResourceFactory;
/**
* Base class for monitoring controllers that loads required dependencies
@ -81,11 +81,13 @@ abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTest
private $appDir = "";
/**
* Require necessary libraries on test creation
* Require necessary libraries on test creation
*
* This is called for every test and assures that all required libraries for the controllers
* are loaded. If you need additional dependencies you should overwrite this method, call the parent
* and then require your classes
* This is called for every test and assures that all required libraries for the controllers
* are loaded. If you need additional dependencies you should overwrite this method, call the parent
* and then require your classes
*
* @backupStaticAttributes enabled
*/
public function setUp()
{
@ -102,6 +104,49 @@ abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTest
$this->requireBase();
$this->requireViews();
ResourceFactory::setConfig(
new Zend_Config(array(
'statusdat-unittest' => array(
'type' => 'statusdat',
'status_file' => '/tmp/teststatus.dat',
'objects_file' => '/tmp/testobjects.cache',
'no_cache' => true
),
'ido-mysql-unittest' => array(
'type' => 'db',
'db' => 'mysql',
'host' => 'localhost',
'username' => 'icinga_unittest',
'password' => 'icinga_unittest',
'dbname' => 'icinga_unittest'
),
'ido-pgsql-unittest' => array(
'type' => 'db',
'db' => 'mysql',
'host' => 'localhost',
'username' => 'icinga_unittest',
'password' => 'icinga_unittest',
'dbname' => 'icinga_unittest'
)
))
);
Backend::setConfig(
new Zend_Config(array(
'statusdat-unittest' => array(
'type' => 'statusdat',
'resource' => 'statusdat-unittest'
),
'ido-mysql-unittest' => array(
'type' => 'ido',
'resource' => 'ido-mysql-unittest'
),
'ido-pgsql-unittest' => array(
'type' => 'ido',
'resource' => 'ido-pgsql-unittest'
)
))
);
}
/**
@ -118,6 +163,7 @@ abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTest
require_once('Exception/ProgrammingError.php');
require_once('Web/Widget/SortBox.php');
require_once('library/Monitoring/Backend/AbstractBackend.php');
require_once('library/Monitoring/Backend.php');
}
@ -128,7 +174,6 @@ abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTest
private function requireIDOQueries()
{
require_once('Application/DbAdapterFactory.php');
require_once('library/Monitoring/Backend/Ido.php');
$this->requireFolder('library/Monitoring/Backend/Ido/Query');
}
@ -155,7 +200,6 @@ abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTest
*/
private function requireStatusDatQueries()
{
require_once(realpath($this->moduleDir.'/library/Monitoring/Backend/Statusdat.php'));
require_once(realpath($this->moduleDir.'/library/Monitoring/Backend/Statusdat/Query/Query.php'));
$this->requireFolder('library/Monitoring/Backend/Statusdat');
$this->requireFolder('library/Monitoring/Backend/Statusdat/Criteria');
@ -186,9 +230,17 @@ abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTest
{
require_once($this->moduleDir.'/application/controllers/'.$controller.'.php');
$controllerName = '\Monitoring_'.ucfirst($controller);
$request = $this->getRequest();
if ($backend == 'statusdat') {
$this->requireStatusDatQueries();
$request->setParam('backend', 'statusdat-unittest');
} else {
$this->requireStatusDatQueries();
$request->setParam('backend', "ido-$backend-unittest");
}
/** @var ActionController $controller */
$controller = new $controllerName(
$this->getRequest(),
$request,
$this->getResponse(),
array('noInit' => true)
);
@ -223,9 +275,11 @@ abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTest
{
if ($type == "mysql" || $type == "pgsql") {
$this->requireIDOQueries();
$resourceConfig = array(
'icinga-db-unittest' => array(
$backendConfig = new Zend_Config(array(
'type' => 'ido'
));
$resourceConfig = new Zend_Config(
array(
'type' => 'db',
'db' => $type,
'host' => "localhost",
@ -234,29 +288,24 @@ abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTest
'dbname' => "icinga_unittest"
)
);
DbAdapterFactory::resetConfig();
DbAdapterFactory::setConfig($resourceConfig);
$backendConfig = array(
'type' => 'db',
'resource' => 'icinga-db-unittest'
);
return new Ido(
new Zend_Config($backendConfig)
);
return new Backend($backendConfig, $resourceConfig);
} elseif ($type == "statusdat") {
$this->requireStatusDatQueries();
return new Statusdat(
new \Zend_Config(
array(
'status_file' => '/tmp/teststatus.dat',
'objects_file' => '/tmp/testobjects.cache',
'no_cache' => true
)
$backendConfig = new Zend_Config(array(
'type' => 'statusdat'
));
$resourceConfig = new Zend_Config(
array(
'type' => 'statusdat',
'status_file' => '/tmp/teststatus.dat',
'objects_file' => '/tmp/testobjects.cache',
'no_cache' => true
)
);
return new Backend(
$backendConfig,
$resourceConfig
);
}
}
}

View File

@ -122,11 +122,12 @@ function(Container, $, logger, URI) {
domContext = domContext || contentNode;
$('tbody tr', domContext).on('click', function(ev) {
var targetEl = ev.target || ev.toElement || ev.relatedTarget;
var targetEl = ev.target || ev.toElement || ev.relatedTarget,
a = $(targetEl).closest('a');
if (targetEl.nodeName.toLowerCase() === "a") {
if (a.length) {
// test if the URL is on the current server, if not open it directly
if(Container.isExternalLink($(targetEl).attr('href'))) {
if (true || Container.isExternalLink(a.attr('href'))) {
return true;
}
}

View File

@ -2,9 +2,11 @@
namespace Tests\Icinga\Web\Paginator\Adapter;
use \Icinga\Module\Monitoring\Backend\Statusdat;
use PHPUnit_Framework_TestCase;
use Zend_Config;
use Icinga\Protocol\Statusdat\Reader;
use Icinga\Web\Paginator\Adapter\QueryAdapter;
use Icinga\Module\Monitoring\Backend;
use Tests\Icinga\Protocol\Statusdat\StatusdatTestLoader;
require_once 'Zend/Paginator/Adapter/Interface.php';
@ -17,19 +19,22 @@ StatusdatTestLoader::requireLibrary();
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Criteria/Order.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/AbstractBackend.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Query/Query.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusQuery.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/DataView/HostStatusView.php';
require_once '../../modules/monitoring/library/Monitoring/View/AbstractView.php';
require_once '../../modules/monitoring/library/Monitoring/View/StatusView.php';
require_once '../../modules/monitoring/library/Monitoring/Backend.php';
require_once '../../library/Icinga/Protocol/AbstractQuery.php';
require_once '../../library/Icinga/Data/ResourceFactory.php';
class QueryAdapterTest extends \PHPUnit_Framework_TestCase
class QueryAdapterTest extends PHPUnit_Framework_TestCase
{
private $cacheDir;
private $config;
private $backendConfig;
private $resourceConfig;
protected function setUp()
{
@ -39,20 +44,26 @@ class QueryAdapterTest extends \PHPUnit_Framework_TestCase
mkdir($this->cacheDir);
}
$statusdatFile = dirname(__FILE__). '/../../../../../res/status/icinga.status.dat';
$cacheFile = dirname(__FILE__). '/../../../../../res/status/icinga.objects.cache';
$statusdatFile = dirname(__FILE__) . '/../../../../../res/status/icinga.status.dat';
$cacheFile = dirname(__FILE__) . '/../../../../../res/status/icinga.objects.cache';
$this->config = new \Zend_Config(
$this->backendConfig = new Zend_Config(
array(
'status_file' => $statusdatFile,
'objects_file' => $cacheFile
'type' => 'statusdat'
)
);
$this->resourceConfig = new Zend_Config(
array(
'status_file' => $statusdatFile,
'objects_file' => $cacheFile,
'type' => 'statusdat'
)
);
}
public function testLimit1()
{
$backend = new Statusdat($this->config);
$backend = new Backend($this->backendConfig, $this->resourceConfig);
$query = $backend->select()->from('status');
$adapter = new QueryAdapter($query);
@ -69,7 +80,7 @@ class QueryAdapterTest extends \PHPUnit_Framework_TestCase
public function testLimit2()
{
$backend = new Statusdat($this->config);
$backend = new Backend($this->backendConfig, $this->resourceConfig);
$query = $backend->select()->from('status');
$adapter = new QueryAdapter($query);

View File

@ -2,10 +2,13 @@
namespace Tests\Icinga\Web\Paginator\ScrollingStyle;
use \Icinga\Module\Monitoring\Backend\Statusdat;
use Zend_Config;
use Zend_Paginator_Adapter_Interface;
use Icinga\Module\Monitoring\Backend\Statusdat;
use Icinga\Protocol\Statusdat\Reader;
use Icinga\Web\Paginator\Adapter\QueryAdapter;
use Tests\Icinga\Protocol\Statusdat\StatusdatTestLoader;
use Icinga\Module\Monitoring\Backend;
require_once 'Zend/Paginator/Adapter/Interface.php';
require_once 'Zend/Paginator/ScrollingStyle/Interface.php';
@ -20,15 +23,15 @@ StatusdatTestLoader::requireLibrary();
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Criteria/Order.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/AbstractBackend.php';
require_once '../../modules/monitoring/library/Monitoring/Backend.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Query/Query.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusQuery.php';
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/DataView/HostStatusView.php';
require_once '../../modules/monitoring/library/Monitoring/View/AbstractView.php';
require_once '../../modules/monitoring/library/Monitoring/View/StatusView.php';
require_once '../../library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php';
class TestPaginatorAdapter implements \Zend_Paginator_Adapter_Interface
class TestPaginatorAdapter implements Zend_Paginator_Adapter_Interface
{
private $items = array();
@ -80,7 +83,9 @@ class SlidingwithborderTest extends \PHPUnit_Framework_TestCase
{
private $cacheDir;
private $config;
private $backendConfig;
private $resourceConfig;
protected function setUp()
{
@ -93,17 +98,23 @@ class SlidingwithborderTest extends \PHPUnit_Framework_TestCase
$statusdatFile = dirname(__FILE__). '/../../../../../res/status/icinga.status.dat';
$cacheFile = dirname(__FILE__). '/../../../../../res/status/icinga.objects.cache';
$this->config = new \Zend_Config(
$this->backendConfig = new Zend_Config(
array(
'status_file' => $statusdatFile,
'objects_file' => $cacheFile
'type' => 'statusdat'
)
);
$this->resourceConfig = new Zend_Config(
array(
'status_file' => $statusdatFile,
'objects_file' => $cacheFile,
'type' => 'statusdat'
)
);
}
public function testGetPages1()
{
$backend = new Statusdat($this->config);
$backend = new Backend($this->backendConfig, $this->resourceConfig);
$query = $backend->select()->from('status');
$adapter = new QueryAdapter($query);