From 3e02d5aff85babc3ffbfcf52313f2108e313aa23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:46:43 +0200 Subject: Adding upstream version 2.12.1. Signed-off-by: Daniel Baumann --- .../library/Monitoring/DataView/Command.php | 24 + .../library/Monitoring/DataView/Comment.php | 82 +++ .../library/Monitoring/DataView/Commentevent.php | 30 + .../library/Monitoring/DataView/Contact.php | 73 +++ .../library/Monitoring/DataView/Contactgroup.php | 57 ++ .../library/Monitoring/DataView/Customvar.php | 47 ++ .../library/Monitoring/DataView/DataView.php | 608 +++++++++++++++++++++ .../library/Monitoring/DataView/Downtime.php | 96 ++++ .../library/Monitoring/DataView/Downtimeevent.php | 33 ++ .../library/Monitoring/DataView/Eventgrid.php | 60 ++ .../library/Monitoring/DataView/Eventgridhosts.php | 7 + .../Monitoring/DataView/Eventgridservices.php | 7 + .../library/Monitoring/DataView/Eventhistory.php | 60 ++ .../library/Monitoring/DataView/Flappingevent.php | 27 + .../library/Monitoring/DataView/Hostcomment.php | 45 ++ .../library/Monitoring/DataView/Hostcontact.php | 17 + .../library/Monitoring/DataView/Hostdowntime.php | 50 ++ .../library/Monitoring/DataView/Hostgroup.php | 34 ++ .../Monitoring/DataView/Hostgroupsummary.php | 81 +++ .../library/Monitoring/DataView/Hoststatus.php | 129 +++++ .../Monitoring/DataView/Hoststatussummary.php | 40 ++ .../library/Monitoring/DataView/Instance.php | 33 ++ .../library/Monitoring/DataView/Notification.php | 59 ++ .../Monitoring/DataView/Notificationevent.php | 29 + .../library/Monitoring/DataView/Programstatus.php | 44 ++ .../library/Monitoring/DataView/Runtimesummary.php | 38 ++ .../Monitoring/DataView/Runtimevariables.php | 34 ++ .../library/Monitoring/DataView/Servicecomment.php | 48 ++ .../library/Monitoring/DataView/Servicecontact.php | 8 + .../Monitoring/DataView/Servicedowntime.php | 50 ++ .../library/Monitoring/DataView/Servicegroup.php | 31 ++ .../Monitoring/DataView/Servicegroupsummary.php | 75 +++ .../library/Monitoring/DataView/Servicestatus.php | 180 ++++++ .../Monitoring/DataView/Servicestatussummary.php | 45 ++ .../Monitoring/DataView/Statechangeevent.php | 32 ++ .../library/Monitoring/DataView/Statussummary.php | 111 ++++ .../Monitoring/DataView/Unhandledhostproblems.php | 28 + .../DataView/Unhandledserviceproblems.php | 28 + 38 files changed, 2480 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/DataView/Command.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Comment.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Commentevent.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Contact.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Contactgroup.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Customvar.php create mode 100644 modules/monitoring/library/Monitoring/DataView/DataView.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Downtime.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Downtimeevent.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Eventgrid.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Eventgridhosts.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Eventgridservices.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Eventhistory.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Flappingevent.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Hostcomment.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Hostcontact.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Hostdowntime.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Hostgroup.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Hoststatus.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Instance.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Notification.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Notificationevent.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Programstatus.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Runtimesummary.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Runtimevariables.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicecomment.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicecontact.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicedowntime.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicegroup.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicestatus.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicestatussummary.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Statechangeevent.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Statussummary.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Unhandledhostproblems.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Unhandledserviceproblems.php (limited to 'modules/monitoring/library/Monitoring/DataView') diff --git a/modules/monitoring/library/Monitoring/DataView/Command.php b/modules/monitoring/library/Monitoring/DataView/Command.php new file mode 100644 index 0000000..6beb8bc --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Command.php @@ -0,0 +1,24 @@ + array( + 'order' => self::SORT_DESC + ), + 'host_display_name' => array( + 'columns' => array( + 'host_display_name', + 'service_display_name' + ), + 'order' => self::SORT_ASC + ), + 'service_display_name' => array( + 'columns' => array( + 'service_display_name', + 'host_display_name' + ), + 'order' => self::SORT_ASC + ) + ); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Commentevent.php b/modules/monitoring/library/Monitoring/DataView/Commentevent.php new file mode 100644 index 0000000..316700a --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Commentevent.php @@ -0,0 +1,30 @@ + array( + 'order' => self::SORT_ASC + ) + ); + } + + /** + * {@inheritdoc} + */ + public function getStaticFilterColumns() + { + return array( + 'contact', 'instance_name', + 'contactgroup', 'contactgroup_name', 'contactgroup_alias', + 'host', 'host_name', 'host_display_name', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); + } + + /** + * {@inheritdoc} + */ + public function getSearchColumns() + { + return array('contact_alias'); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Contactgroup.php b/modules/monitoring/library/Monitoring/DataView/Contactgroup.php new file mode 100644 index 0000000..84eecd1 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Contactgroup.php @@ -0,0 +1,57 @@ + array( + 'order' => self::SORT_ASC + ), + 'contactgroup_alias' => array( + 'order' => self::SORT_ASC + ) + ); + } + + /** + * {@inheritdoc} + */ + public function getStaticFilterColumns() + { + return array( + 'contactgroup', + 'host', 'host_name', 'host_display_name', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'instance_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); + } + + /** + * {@inheritdoc} + */ + public function getSearchColumns() + { + return array('contactgroup_alias'); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Customvar.php b/modules/monitoring/library/Monitoring/DataView/Customvar.php new file mode 100644 index 0000000..c02d52f --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Customvar.php @@ -0,0 +1,47 @@ + array( + 'columns' => array( + 'varname', + 'varvalue' + ) + ) + ); + } + + /** + * {@inheritdoc} + */ + public function getStaticFilterColumns() + { + return array('host', 'service', 'contact'); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/DataView.php b/modules/monitoring/library/Monitoring/DataView/DataView.php new file mode 100644 index 0000000..5b16e28 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/DataView.php @@ -0,0 +1,608 @@ +connection = $connection; + $this->query = $connection->query($this->getQueryName(), $columns); + } + + /** + * Return a iterator for all rows of the result set + * + * @return IdoQuery + */ + public function getIterator(): Traversable + { + return $this->getQuery(); + } + + /** + * Return the current position of the result set's iterator + * + * @return int + */ + public function getIteratorPosition() + { + return $this->query->getIteratorPosition(); + } + + /** + * Get the query name this data view relies on + * + * By default this is this class' name without its namespace + * + * @return string + */ + public static function getQueryName() + { + $tableName = explode('\\', get_called_class()); + $tableName = end($tableName); + return $tableName; + } + + public function where($condition, $value = null) + { + $this->query->where($condition, $value); + return $this; + } + + /** + * Add a filter expression, with as less validation as possible + * + * @param FilterExpression $ex + * + * @internal If you use this outside the monitoring module, it's your fault if something breaks + * @return $this + */ + public function whereEx(FilterExpression $ex) + { + $this->query->whereEx($ex); + return $this; + } + + public function dump() + { + if (! $this->isSorted) { + $this->order(); + } + return $this->query->dump(); + } + + /** + * Retrieve columns provided by this view + * + * @return array + */ + abstract public function getColumns(); + + protected function getHookedColumns() + { + $columns = array(); + foreach (Hook::all('monitoring/dataviewExtension') as $hook) { + foreach ($hook->getAdditionalQueryColumns($this->getQueryName()) as $col) { + $columns[] = $col; + } + } + + return $columns; + } + + /** + * Create view from params + * + * @param array $params + * @param array $columns + * + * @return static + */ + public static function fromParams(array $params, array $columns = null) + { + $view = new static(MonitoringBackend::instance($params['backend']), $columns); + + foreach ($params as $key => $value) { + if ($view->isValidFilterTarget($key)) { + $view->where($key, $value); + } + } + + if (isset($params['sort'])) { + $order = isset($params['order']) ? $params['order'] : null; + if ($order !== null) { + if (strtolower($order) === 'desc') { + $order = self::SORT_DESC; + } else { + $order = self::SORT_ASC; + } + } + + $view->order($params['sort'], $order); + } + return $view; + } + + /** + * Check whether the given column is a valid filter column + * + * @param string $column + * + * @return bool + */ + public function isValidFilterTarget($column) + { + // Customvar + if ($column[0] === '_' && preg_match('/^_(?:host|service)_/i', $column)) { + return true; + } + return in_array($column, $this->getColumns()) || in_array($column, $this->getStaticFilterColumns()); + } + + /** + * Return all filter columns with their optional label as key + * + * This will merge the results of self::getColumns(), self::getStaticFilterColumns() and + * self::getDynamicFilterColumns() *once*. (i.e. subsequent calls of this function will + * return the same result.) + * + * @return array + */ + public function getFilterColumns() + { + if ($this->filterColumns === null) { + $columns = array_merge( + $this->getColumns(), + $this->getStaticFilterColumns(), + $this->getDynamicFilterColumns() + ); + + $this->filterColumns = array(); + foreach ($columns as $label => $column) { + if (is_int($label)) { + $label = ucwords(str_replace('_', ' ', $column)); + } + + if ($this->query->isCaseInsensitive($column)) { + $label .= ' ' . t('(Case insensitive)'); + } + + $this->filterColumns[$label] = $column; + } + } + + return $this->filterColumns; + } + + /** + * Return all static filter columns + * + * @return array + */ + public function getStaticFilterColumns() + { + return array(); + } + + /** + * Return all dynamic filter columns such as custom variables + * + * @return array + */ + public function getDynamicFilterColumns() + { + $columns = array(); + if (! $this->query->allowsCustomVars()) { + return $columns; + } + + $query = MonitoringBackend::instance() + ->select() + ->from('customvar', array('varname', 'object_type')) + ->where('is_json', 0) + ->where('object_type_id', array(1, 2)) + ->getQuery()->group(array('varname', 'object_type')); + foreach ($query as $row) { + if ($row->object_type === 'host') { + $label = t('Host') . ' ' . ucwords(str_replace('_', ' ', $row->varname)); + $columns[$label] = '_host_' . $row->varname; + } else { // $row->object_type === 'service' + $label = t('Service') . ' ' . ucwords(str_replace('_', ' ', $row->varname)); + $columns[$label] = '_service_' . $row->varname; + } + } + + return $columns; + } + + /** + * Return the current filter + * + * @return Filter + */ + public function getFilter() + { + return $this->query->getFilter(); + } + + /** + * Return a pivot table for the given columns based on the current query + * + * @param string $xAxisColumn The column to use for the x axis + * @param string $yAxisColumn The column to use for the y axis + * @param Filter $xAxisFilter The filter to apply on a query for the x axis + * @param Filter $yAxisFilter The filter to apply on a query for the y axis + * + * @return PivotTable + */ + public function pivot($xAxisColumn, $yAxisColumn, Filter $xAxisFilter = null, Filter $yAxisFilter = null) + { + $pivot = new PivotTable($this->query, $xAxisColumn, $yAxisColumn); + return $pivot->setXAxisFilter($xAxisFilter)->setYAxisFilter($yAxisFilter); + } + + /** + * Sort result set either by the given column (and direction) or the sort defaults + * + * @param string $column + * @param string $direction + * + * @return $this + */ + public function order($column = null, $direction = null) + { + $sortRules = $this->getSortRules(); + if ($column === null) { + // Use first available sort rule as default + if (empty($sortRules)) { + return $this; + } + $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' => $direction + ); + }; + } + + $direction = $direction === null ? ($sortColumns['order'] ?? static::SORT_ASC) : $direction; + $direction = (strtoupper($direction) === static::SORT_ASC) ? 'ASC' : 'DESC'; + + foreach ($sortColumns['columns'] as $column) { + list($column, $order) = $this->query->splitOrder($column); + if (! $this->isValidFilterTarget($column)) { + throw new QueryException( + mt('monitoring', 'The sort column "%s" is not allowed in "%s".'), + $column, + get_class($this) + ); + } + $this->query->order($column, $order !== null ? $order : $direction); + } + $this->isSorted = true; + return $this; + } + + /** + * Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort + * + * @return array + */ + public function getSortRules() + { + return array(); + } + + /** + * Whether an order is set + * + * @return bool + */ + public function hasOrder() + { + return $this->query->hasOrder(); + } + + /** + * Get the order if any + * + * @return array|null + */ + public function getOrder() + { + return $this->query->getOrder(); + } + + public function getMappedField($field) + { + return $this->query->getMappedField($field); + } + + /** + * Return the query which was created in the constructor + * + * @return \Icinga\Data\SimpleQuery + */ + public function getQuery() + { + if (! $this->isSorted) { + $this->order(); + } + return $this->query; + } + + public function applyFilter(Filter $filter) + { + $this->validateFilterColumns($filter); + + return $this->addFilter($filter); + } + + /** + * Validates recursive the Filter columns against the isValidFilterTarget() method + * + * @param Filter $filter + * + * @throws \Icinga\Data\Filter\FilterException + */ + public function validateFilterColumns(Filter $filter) + { + if ($filter instanceof FilterMatch) { + if (! $this->isValidFilterTarget($filter->getColumn())) { + throw new QueryException( + mt('monitoring', 'The filter column "%s" is not allowed here.'), + $filter->getColumn() + ); + } + } + + if (method_exists($filter, 'filters')) { + foreach ($filter->filters() as $filter) { + $this->validateFilterColumns($filter); + } + } + } + + public function clearFilter() + { + $this->query->clearFilter(); + return $this; + } + + /** + * @deprecated(EL): Only use DataView::applyFilter() for applying filter because all other functions are missing + * column validation. Filter::matchAny() for the IdoQuery (or the DbQuery or the SimpleQuery I didn't have a look) + * is required for the filter to work properly. + */ + public function setFilter(Filter $filter) + { + $this->query->setFilter($filter); + return $this; + } + + /** + * Get the view's search columns + * + * @return string[] + */ + public function getSearchColumns() + { + return array(); + } + + /** + * @deprecated(EL): Only use DataView::applyFilter() for applying filter because all other functions are missing + * column validation. + */ + public function addFilter(Filter $filter) + { + $this->query->addFilter($filter); + return $this; + } + + /** + * Count result set + * + * @return int + */ + public function count(): int + { + return $this->query->count(); + } + + /** + * Set whether the query should peek ahead for more results + * + * Enabling this causes the current query limit to be increased by one. The potential extra row being yielded will + * be removed from the result set. Note that this only applies when fetching multiple results of limited queries. + * + * @return $this + */ + public function peekAhead($state = true) + { + $this->query->peekAhead($state); + return $this; + } + + /** + * Return whether the query did not yield all available results + * + * @return bool + */ + public function hasMore() + { + return $this->query->hasMore(); + } + + /** + * Return whether this query will or has yielded any result + * + * @return bool + */ + public function hasResult() + { + return $this->query->hasResult(); + } + + /** + * Set a limit count and offset + * + * @param int $count Number of rows to return + * @param int $offset Start returning after this many rows + * + * @return self + */ + public function limit($count = null, $offset = null) + { + $this->query->limit($count, $offset); + return $this; + } + + /** + * Whether a limit is set + * + * @return bool + */ + public function hasLimit() + { + return $this->query->hasLimit(); + } + + /** + * Get the limit if any + * + * @return int|null + */ + public function getLimit() + { + return $this->query->getLimit(); + } + + /** + * Whether an offset is set + * + * @return bool + */ + public function hasOffset() + { + return $this->query->hasOffset(); + } + + /** + * Get the offset if any + * + * @return int|null + */ + public function getOffset() + { + return $this->query->getOffset(); + } + + /** + * Retrieve an array containing all rows of the result set + * + * @return array + */ + public function fetchAll() + { + return $this->getQuery()->fetchAll(); + } + + /** + * Fetch the first row of the result set + * + * @return mixed + */ + public function fetchRow() + { + return $this->getQuery()->fetchRow(); + } + + /** + * Fetch the first column of all rows of the result set as an array + * + * @return array + */ + public function fetchColumn() + { + return $this->getQuery()->fetchColumn(); + } + + /** + * Fetch the first column of the first row of the result set + * + * @return string + */ + public function fetchOne() + { + return $this->getQuery()->fetchOne(); + } + + /** + * Fetch all rows of the result set as an array of key-value pairs + * + * The first column is the key, the second column is the value. + * + * @return array + */ + public function fetchPairs() + { + return $this->getQuery()->fetchPairs(); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Downtime.php b/modules/monitoring/library/Monitoring/DataView/Downtime.php new file mode 100644 index 0000000..ca42e2d --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Downtime.php @@ -0,0 +1,96 @@ + array( + 'columns' => array( + 'downtime_is_in_effect', + 'downtime_scheduled_start' + ), + 'order' => self::SORT_DESC + ), + 'downtime_start' => array( + 'order' => self::SORT_DESC + ), + 'host_display_name' => array( + 'columns' => array( + 'host_display_name', + 'service_display_name' + ), + 'order' => self::SORT_ASC + ), + 'service_display_name' => array( + 'columns' => array( + 'service_display_name', + 'host_display_name' + ), + 'order' => self::SORT_ASC + ) + ); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Downtimeevent.php b/modules/monitoring/library/Monitoring/DataView/Downtimeevent.php new file mode 100644 index 0000000..a1fc0f6 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Downtimeevent.php @@ -0,0 +1,33 @@ + array( + 'order' => self::SORT_DESC + ) + ); + } + + /** + * {@inheritdoc} + */ + public function getStaticFilterColumns() + { + return array( + 'instance_name', + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_host_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Eventgridhosts.php b/modules/monitoring/library/Monitoring/DataView/Eventgridhosts.php new file mode 100644 index 0000000..9d9acc9 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Eventgridhosts.php @@ -0,0 +1,7 @@ + array( + 'order' => self::SORT_DESC + ) + ); + } + + /** + * {@inheritdoc} + */ + public function getStaticFilterColumns() + { + return array( + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); + } + + /** + * {@inheritdoc} + */ + public function getSearchColumns() + { + return array('host_display_name', 'service_display_name'); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Flappingevent.php b/modules/monitoring/library/Monitoring/DataView/Flappingevent.php new file mode 100644 index 0000000..bc79497 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Flappingevent.php @@ -0,0 +1,27 @@ + array( + 'order' => self::SORT_ASC + ) + ); + } + + public function getStaticFilterColumns() + { + return array( + 'instance_name', 'host_name', 'service_description', 'servicegroup_name' + ); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php new file mode 100644 index 0000000..9ed2eb9 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php @@ -0,0 +1,81 @@ + array( + 'order' => self::SORT_ASC + ), + 'hosts_severity' => array( + 'columns' => array( + 'hosts_severity', + 'hostgroup_alias ASC' + ), + 'order' => self::SORT_DESC + ) + ); + } + + public function getStaticFilterColumns() + { + return array( + 'instance_name', + 'host_contact', 'host_contactgroup', 'host_name', + 'hostgroup', + 'service_description', + 'servicegroup_name' + ); + } + + public function getFilterColumns() + { + if ($this->filterColumns === null) { + $filterColumns = parent::getFilterColumns(); + $diff = array_diff($filterColumns, $this->getColumns()); + $this->filterColumns = array_merge($diff, [ + 'Hostgroup Name' => 'hostgroup_name', + 'Hostgroup Alias' => 'hostgroup_alias' + ]); + } + + return $this->filterColumns; + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Hoststatus.php b/modules/monitoring/library/Monitoring/DataView/Hoststatus.php new file mode 100644 index 0000000..cd9b31f --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Hoststatus.php @@ -0,0 +1,129 @@ +getHookedColumns(), array( + 'host_acknowledged', + 'host_acknowledgement_type', + 'host_action_url', + 'host_active_checks_enabled', + 'host_active_checks_enabled_changed', + 'host_address', + 'host_address6', + 'host_alias', + 'host_check_command', + 'host_check_execution_time', + 'host_check_latency', + 'host_check_source', + 'host_check_timeperiod', + 'host_current_check_attempt', + 'host_current_notification_number', + 'host_display_name', + 'host_event_handler_enabled', + 'host_event_handler_enabled_changed', + 'host_flap_detection_enabled', + 'host_flap_detection_enabled_changed', + 'host_handled', + 'host_hard_state', + 'host_in_downtime', + 'host_ipv4', + 'host_is_flapping', + 'host_is_reachable', + 'host_last_check', + 'host_last_notification', + 'host_last_state_change', + 'host_last_state_change_ts', + 'host_long_output', + 'host_max_check_attempts', + 'host_modified_host_attributes', + 'host_name', + 'host_next_check', + 'host_notes_url', + 'host_notifications_enabled', + 'host_notifications_enabled_changed', + 'host_obsessing', + 'host_obsessing_changed', + 'host_output', + 'host_passive_checks_enabled', + 'host_passive_checks_enabled_changed', + 'host_percent_state_change', + 'host_perfdata', + 'host_problem', + 'host_severity', + 'host_state', + 'host_state_type', + 'host_unhandled', + 'instance_name' + )); + } + + /** + * {@inheritdoc} + */ + public function getStaticFilterColumns() + { + return array( + 'host', 'host_contact', 'host_contactgroup', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); + } + + /** + * {@inheritdoc} + */ + public function getSearchColumns($search = null) + { + if ($search !== null + && (@inet_pton($search) !== false || preg_match('/^\d{1,3}\.\d{1,3}\./', $search)) + ) { + return array('host', 'host_address', 'host_address6'); + } else { + if ($this->connection->isIcinga2()) { + return array('host', 'host_display_name'); + } else { + return array('host', 'host_display_name', 'host_alias'); + } + } + } + + /** + * {@inheritdoc} + */ + public function getSortRules() + { + return array( + 'host_display_name' => array( + 'order' => self::SORT_ASC + ), + 'host_severity' => array( + 'columns' => array( + 'host_severity', + 'host_last_state_change_ts DESC' + ), + 'order' => self::SORT_DESC + ), + 'host_address' => array( + 'columns' => array( + 'host_ipv4' + ), + 'order' => self::SORT_ASC + ), + 'host_last_state_change' => array( + 'columns' => array( + 'host_last_state_change_ts' + ), + 'order' => self::SORT_DESC + ) + ); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php b/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php new file mode 100644 index 0000000..a857466 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php @@ -0,0 +1,40 @@ + array( + 'order' => self::SORT_ASC + ) + ); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Notification.php b/modules/monitoring/library/Monitoring/DataView/Notification.php new file mode 100644 index 0000000..90755de --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Notification.php @@ -0,0 +1,59 @@ + array( + 'order' => self::SORT_DESC + ) + ); + } + + /** + * {@inheritdoc} + */ + public function getStaticFilterColumns() + { + return array( + 'hostgroup_name', + 'instance_name', + 'servicegroup_name' + ); + } + + /** + * {@inheritdoc} + */ + public function getSearchColumns() + { + return array('host_display_name', 'service_display_name'); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Notificationevent.php b/modules/monitoring/library/Monitoring/DataView/Notificationevent.php new file mode 100644 index 0000000..82dd212 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Notificationevent.php @@ -0,0 +1,29 @@ + array( + 'order' => self::SORT_ASC + ) + ); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Runtimevariables.php b/modules/monitoring/library/Monitoring/DataView/Runtimevariables.php new file mode 100644 index 0000000..b3624b7 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Runtimevariables.php @@ -0,0 +1,34 @@ + array( + 'order' => self::SORT_ASC + ) + ); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Servicecomment.php b/modules/monitoring/library/Monitoring/DataView/Servicecomment.php new file mode 100644 index 0000000..78c1333 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Servicecomment.php @@ -0,0 +1,48 @@ + array( + 'order' => self::SORT_ASC + ) + ); + } + + public function getStaticFilterColumns() + { + return array( + 'instance_name', 'host_name', 'hostgroup_name', 'service_description' + ); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php new file mode 100644 index 0000000..9dc3ee0 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php @@ -0,0 +1,75 @@ + array( + 'order' => self::SORT_ASC + ), + 'services_severity' => array( + 'columns' => array( + 'services_severity', + 'servicegroup_alias ASC' + ), + 'order' => self::SORT_DESC + ) + ); + } + + public function getStaticFilterColumns() + { + return array( + 'instance_name', + 'services_severity', + 'host_contact', 'host_contactgroup', 'host_name', + 'hostgroup_name', + 'service_contact', 'service_contactgroup', 'service_description', + 'servicegroup' + ); + } + + public function getFilterColumns() + { + if ($this->filterColumns === null) { + $filterColumns = parent::getFilterColumns(); + $diff = array_diff($filterColumns, $this->getColumns()); + $this->filterColumns = array_merge($diff, [ + 'Servicegroup Name' => 'servicegroup_name', + 'Servicegroup Alias' => 'servicegroup_alias' + ]); + } + + return $this->filterColumns; + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Servicestatus.php b/modules/monitoring/library/Monitoring/DataView/Servicestatus.php new file mode 100644 index 0000000..86da272 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Servicestatus.php @@ -0,0 +1,180 @@ +getHookedColumns(), array( + 'host_acknowledged', + 'host_action_url', + 'host_active_checks_enabled', + 'host_address', + 'host_address6', + 'host_alias', + 'host_check_source', + 'host_display_name', + 'host_handled', + 'host_hard_state', + 'host_in_downtime', + 'host_ipv4', + 'host_is_flapping', + 'host_last_check', + 'host_last_hard_state', + 'host_last_hard_state_change', + 'host_last_state_change', + 'host_last_time_down', + 'host_last_time_unreachable', + 'host_last_time_up', + 'host_long_output', + 'host_modified_host_attributes', + 'host_name', + 'host_notes_url', + 'host_notifications_enabled', + 'host_output', + 'host_passive_checks_enabled', + 'host_perfdata', + 'host_problem', + 'host_severity', + 'host_state', + 'host_state_type', + 'host_unhandled_service_count', + 'instance_name', + 'service_acknowledged', + 'service_acknowledgement_type', + 'service_action_url', + 'service_active_checks_enabled', + 'service_active_checks_enabled_changed', + 'service_attempt', + 'service_check_command', + 'service_check_source', + 'service_check_timeperiod', + 'service_current_check_attempt', + 'service_current_notification_number', + 'service_description', + 'service_display_name', + 'service_event_handler_enabled', + 'service_event_handler_enabled_changed', + 'service_flap_detection_enabled', + 'service_flap_detection_enabled_changed', + 'service_handled', + 'service_hard_state', + 'service_host_name', + 'service_in_downtime', + 'service_is_flapping', + 'service_is_reachable', + 'service_last_check', + 'service_last_hard_state', + 'service_last_hard_state_change', + 'service_last_notification', + 'service_last_state_change', + 'service_last_state_change_ts', + 'service_last_time_critical', + 'service_last_time_ok', + 'service_last_time_unknown', + 'service_last_time_warning', + 'service_long_output', + 'service_max_check_attempts', + 'service_modified_service_attributes', + 'service_next_check', + 'service_notes', + 'service_notes_url', + 'service_notifications_enabled', + 'service_notifications_enabled_changed', + 'service_obsessing', + 'service_obsessing_changed', + 'service_output', + 'service_passive_checks_enabled', + 'service_passive_checks_enabled_changed', + 'service_perfdata', + 'service_problem', + 'service_severity', + 'service_state', + 'service_state_type', + 'service_unhandled' + )); + } + + /** + * {@inheritdoc} + */ + public function getSortRules() + { + return array( + 'service_display_name' => array( + 'order' => self::SORT_ASC + ), + 'service_severity' => array( + 'columns' => array( + 'service_severity', + 'service_last_state_change_ts DESC' + ), + 'order' => self::SORT_DESC + ), + 'service_last_state_change' => array( + 'columns' => array( + 'service_last_state_change_ts' + ), + 'order' => self::SORT_DESC + ), + 'host_severity' => array( + 'columns' => array( + 'host_severity', + 'host_last_state_change DESC', + 'host_display_name ASC', + 'service_display_name ASC' + ), + 'order' => self::SORT_DESC + ), + 'host_display_name' => array( + 'columns' => array( + 'host_display_name', + 'service_display_name' + ), + 'order' => self::SORT_ASC + ), + 'host_address' => array( + 'columns' => array( + 'host_ipv4', + 'service_display_name' + ), + 'order' => self::SORT_ASC + ) + ); + } + + /** + * {@inheritdoc} + */ + public function getStaticFilterColumns() + { + return array( + 'host', + 'host_contact', + 'host_contactgroup', + 'hostgroup', + 'hostgroup_alias', + 'hostgroup_name', + 'service', + 'service_contact', + 'service_contactgroup', + 'service_host', + 'servicegroup', + 'servicegroup_alias', + 'servicegroup_name' + ); + } + + /** + * {@inheritdoc} + */ + public function getSearchColumns() + { + return array('service', 'service_display_name'); + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Servicestatussummary.php b/modules/monitoring/library/Monitoring/DataView/Servicestatussummary.php new file mode 100644 index 0000000..abd3593 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Servicestatussummary.php @@ -0,0 +1,45 @@ +