Commit bb77d104 authored by David Kunz's avatar David Kunz

Adding upstream version 1.1.0.

Signed-off-by: David Kunz's avatarDavid Kunz <david.kunz@dknet.ch>
parent d53a5812
<!--- Provide a general summary of the issue in the Title above -->
<!-- Formatting tips:
GitHub supports Markdown: https://guides.github.com/features/mastering-markdown/
Multi-line code blocks either with three back ticks, or four space indent.
```
Stacktrace ...
<line>
<line>
```
-->
## Expected Behavior
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->
## Current Behavior
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
## Possible Solution
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
<!--- or ideas how to implement: the addition or change -->
## Steps to Reproduce (for bugs)
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
<!--- reproduce this bug. Include configuration, logs, etc. to reproduce, if relevant -->
1.
2.
3.
4.
## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
## Your Environment
<!--- Include as many relevant details about the environment you experienced the problem in -->
* Icinga Web 2 Map version (System - About):
* Icinga Web 2 version and modules (System - About):
* Version used (`icinga2 --version`):
* Operating System and version:
* Enabled features (`icinga2 feature list`):
* Config validation (`icinga2 daemon -C`):
.idea
*.sw*
*~
This diff is collapsed.
# <a id="contributing"></a> Contributing
Icinga Web 2 Module for Maps is an open source project and lives from your ideas and contributions.
There are many ways to contribute, from improving the documentation, submitting
bug reports and features requests or writing code to add enhancements or fix bugs.
#### Table of Contents
1. [Introduction](#contributing-intro)
2. [Fork the Project](#contributing-fork)
3. [Branches](#contributing-branches)
4. [Commits](#contributing-commits)
5. [Pull Requests](#contributing-pull-requests)
6. [Testing](#contributing-testing)
7. [Source Code Patches](#contributing-patches-source-code)
8. [Documentation Patches](#contributing-patches-documentation)
9. [Review](#contributing-review)
## <a id="contributing-intro"></a> Introduction
Please consider our [roadmap](https://github.com/nbuchwitz/icingaweb2-module-map/milestones) and
[open issues](https://github.com/nbuchwitz/icingaweb2-module-map/issues) when you start contributing
to the project.
Before starting your work on this Map module for Icinga Web 2, you should [fork the project](https://help.github.com/articles/fork-a-repo/)
to your GitHub account. This allows you to freely experiment with your changes.
When your changes are complete, submit a [pull request](https://help.github.com/articles/using-pull-requests/).
All pull requests will be reviewed and merged if they suit some general guidelines:
* Changes are located in a topic branch
* For new functionality, proper tests are written
* Changes should follow the existing coding style and standards
Please continue reading in the following sections for a step by step guide.
## <a id="contributing-fork"></a> Fork the Project
[Fork the project](https://help.github.com/articles/fork-a-repo/) to your GitHub account
and clone the repository:
```
git clone git@github.com:dnsmichi/icingaweb2-module-map.git
cd icingaweb2-module-map
```
Add a new remote `upstream` with this repository as value.
```
git remote add upstream https://github.com/nbuchwitz/icingaweb2-module-map.git
```
You can pull updates to your fork's master branch:
```
git fetch --all
git pull upstream HEAD
```
Please continue to learn about [branches](CONTRIBUTING.md#contributing-branches).
## <a id="contributing-branches"></a> Branches
Choosing a proper name for a branch helps us identify its purpose and possibly
find an associated bug or feature.
Generally a branch name should include a topic such as `fix` or `feature` followed
by a description and an issue number if applicable. Branches should have only changes
relevant to a specific issue.
```
git checkout -b fix/service-template-typo-1234
git checkout -b feature/config-handling-1235
```
Continue to apply your changes and test them. More details on specific changes:
* [Source Code Patches](#contributing-patches-source-code)
* [Documentation Patches](#contributing-patches-documentation)
## <a id="contributing-commits"></a> Commits
Once you've finished your work in a branch, please ensure to commit
your changes. A good commit message includes a short topic, additional body
and a reference to the issue you wish to solve (if existing).
Fixes:
```
Fix missing style in detail view
refs #4567
```
Features:
```
Add DateTime picker
refs #1234
```
You can add multiple commits during your journey to finish your patch.
Don't worry, you can squash those changes into a single commit later on.
## <a id="contributing-pull-requests"></a> Pull Requests
Once you've committed your changes, please update your local master
branch and rebase your fix/feature branch against it before submitting a PR.
```
git checkout master
git pull upstream HEAD
git checkout fix/style-detail-view
git rebase master
```
Once you've resolved any conflicts, push the branch to your remote repository.
It might be necessary to force push after rebasing - use with care!
New branch:
```
git push --set-upstream origin fix/style-detail-view
```
Existing branch:
```
git push -f origin fix/style-detail-view
```
You can now either use the [hub](https://hub.github.com) CLI tool to create a PR, or nagivate
to your GitHub repository and create a PR there.
The pull request should again contain a telling subject and a reference
with `fixes` to an existing issue id if any. That allows developers
to automatically resolve the issues once your PR gets merged.
```
hub pull-request
<a telling subject>
fixes #1234
```
Thanks a lot for your contribution!
### <a id="contributing-rebase"></a> Rebase a Branch
If you accidentally sent in a PR which was not rebased against the upstream master,
developers might ask you to rebase your PR.
First off, fetch and pull `upstream` master.
```
git checkout master
git fetch --all
git pull upstream HEAD
```
Then change to your working branch and start rebasing it against master:
```
git checkout fix/style-detail-view
git rebase master
```
If you are running into a conflict, rebase will stop and ask you to fix the problems.
```
git status
both modified: path/to/conflict.php
```
Edit the file and search for `>>>`. Fix, build, test and save as needed.
Add the modified file(s) and continue rebasing.
```
git add path/to/conflict.php
git rebase --continue
```
Once succeeded ensure to push your changed history remotely.
```
git push -f origin fix/style-detail-view
```
If you fear to break things, do the rebase in a backup branch first and later replace your current branch.
```
git checkout fix/style-detail-view
git checkout -b fix/style-detail-view-rebase
git rebase master
git branch -D fix/style-detail-view
git checkout -b fix/style-detail-view
git push -f origin fix/style-detail-view
```
### <a id="contributing-squash"></a> Squash Commits
> **Note:**
>
> Be careful with squashing. This might lead to non-recoverable mistakes.
>
> This is for advanced Git users.
Say you want to squash the last 3 commits in your branch into a single one.
Start an interactive (`-i`) rebase from current HEAD minus three commits (`HEAD~3`).
```
git rebase -i HEAD~3
```
Git opens your preferred editor. `pick` the commit in the first line, change `pick` to `squash` on the other lines.
```
pick e4bf04e47 Fix style detail view
squash d7b939d99 Tests
squash b37fd5377 Doc updates
```
Save and let rebase to its job. Then force push the changes to the remote origin.
```
git push -f origin fix/style-detail-view
```
## <a id="contributing-testing"></a> Testing
You can help test-drive the Git master inside the
[Icinga 2 Vagrant boxes](https://github.com/icinga/icinga-vagrant).
$ git clone https://github.com/Icinga/icinga-vagrant.git
$ cd icinga-vagrant/icinga2x
$ vagrant up
$ vagrant ssh -c "cd /usr/share/icingaweb2/modules/map && sudo git pull"
## <a id="contributing-patches-source-code"></a> Source Code Patches
Icinga Web 2 is written in PHP and JavaScript. This module relies on the base
framework.
Start your work in a test installation where the module's directory is mounted
and you can see codes change in a direct manner.
## <a id="contributing-review"></a> Review
### <a id="contributing-pr-review"></a> Pull Request Review
This is only important for developers who will review pull requests. If you want to join
the development team, kindly contact us.
- Ensure that the style guide applies.
- Verify that the patch fixes a problem or linked issue, if any.
- Discuss new features with team members.
- Test the patch in your local dev environment.
If there are changes required, kindly ask for an updated patch.
Once the review is completed, merge the PR via GitHub.
#### <a id="contributing-pr-review-fixes"></a> Pull Request Review Fixes
In order to amend the commit message, fix conflicts or add missing changes, you can
add your changes to the PR.
A PR is just a pointer to a different Git repository and branch.
By default, pull requests allow to push into the repository of the PR creator.
Example for [#4956](https://github.com/Icinga/icinga2/pull/4956):
At the bottom it says "Add more commits by pushing to the fix/persistent-comments-are-not-persistent branch on TheFlyingCorpse/icinga2."
First off, add the remote repository as additional origin and fetch its content:
```
git remote add theflyingcorpse https://github.com/TheFlyingCorpse/icinga2
git fetch --all
```
Checkout the mentioned remote branch into a local branch (Note: `theflyingcorpse` is the name of the remote):
```
git checkout theflyingcorpse/fix/persistent-comments-are-not-persistent -b fix/persistent-comments-are-not-persistent
```
Rebase, amend, squash or add your own commits on top.
Once you are satisfied, push the changes to the remote `theflyingcorpse` and its branch `fix/persistent-comments-are-not-persistent`.
The syntax here is `git push <remote> <localbranch>:<remotebranch>`.
```
git push theflyingcorpse fix/persistent-comments-are-not-persistent:fix/persistent-comments-are-not-persistent
```
In case you've changed the commit history (rebase, amend, squash), you'll need to force push. Be careful, this can't be reverted!
```
git push -f theflyingcorpse fix/persistent-comments-are-not-persistent:fix/persistent-comments-are-not-persistent
```
This diff is collapsed.
# Map module for Icinga Web 2
#### Table of Contents
1. [About](#about)
2. [License](#license)
3. [Documentation](#documentation)
4. [Support](#support)
5. [Requirements](#requirements)
6. [Thanks](#thanks)
7. [Contributing](#contributing)
## About
This module displays host objects as markers on [openstreetmap](https://www.openstreetmap.org) using [leaflet.js](http://leafletjs.com/). If you configure multiple hosts with the same coordinates, i.e. servers in a datacenter, a clustered view is rendered.
![Marker popup](doc/screenshot/map-module.png)
You could also integrate a map as dashlet into your dashboards:
![Marker popup](doc/screenshot/dashlets.png)
## License
Icinga Web 2 and this Icinga Web 2 module are licensed under the terms of the GNU General Public License Version 2, you will find a copy of this license in the LICENSE file included in the source package.
This module uses Leaflet and several plugins:
* [Leaflet](https://github.com/Leaflet/Leaflet) - BSD 2-clause "Simplified" License
* [Leaflet.markercluster](https://github.com/Leaflet/Leaflet.markercluster) - MIT license
* [Leaflet.Locate](https://github.com/domoritz/leaflet-locatecontrol) - MIT license
* [Leaflet.EasyButton](https://github.com/CliffCloud/Leaflet.EasyButton) - MIT license
* [Leaflet.Spin](https://github.com/makinacorpus/Leaflet.Spin) - MIT license
* [Leaflet.awesome-markers](https://github.com/sigma-geosistemas/Leaflet.awesome-markers) - MIT license
* [Spin.js](spin.js.org) - MIT license
## Documentation
* [Installation](doc/01-Installation.md)
* [Adding markers to your map](doc/02-Add-Items-to-map.md)
* [Exploring the map](doc/03-Exploring-the-map.md)
## Support
Join the [Icinga community channels](https://www.icinga.com/community/get-involved/) for questions.
## Requirements
* [Icinga Web 2](https://www.icinga.com/products/icinga-web-2/) (>= 2.4.1)
## Thanks
This module borrows a lot from https://github.com/Mikesch-mp/icingaweb2-module-globe.
## Contributing
There are many ways to contribute to the Icinga Web module for Maps --
whether it be sending patches, testing, reporting bugs, or reviewing and
updating the documentation. Every contribution is appreciated!
Please continue reading in the [contributing chapter](CONTRIBUTING.md).
# Release Workflow
Print this document.
Specify the release version.
```
VERSION=1.1.0
```
## Issues
Check issues at https://github.com/nbuchwitz/icingaweb2-module-map/milestones
## Version
Update the version number in the following file:
* [module.info](module.info): Version: (.*)
Example:
```
sed -i "s/Version: .*/Version: $VERSION/g" module.info
```
## Changelog
Ensure to have [github_changelog_generator](https://github.com/skywinder/github-changelog-generator)
installed and set the GitHub token to avoid rate limiting.
```
github_changelog_generator -u nbuchwitz -p icingaweb2-module-map --future-release=$VERSION
```
## Git Tag
Commit these changes to the "master" branch:
```
$ git commit -v -a -m "Release version $VERSION"
```
Create a signed tag (tags/v<VERSION>) on the "master" branch.
```
$ git tag -m "Version $VERSION" v$VERSION
```
Push the tag.
```
$ git push --tags
```
# External Dependencies
## Release Tests
* Provision the vagrant boxes and pull the master in `/usr/share/icingaweb2/modules/map`
Example:
```
$ git clone https://github.com/Icinga/icinga-vagrant.git
$ cd icinga-vagrant/standalone
$ vagrant up
$ vagrant ssh -c "cd /usr/share/icingaweb2/modules/map && sudo git pull"
```
## GitHub Release
Create a new release for the newly created Git tag.
https://github.com/nbuchwitz/icingaweb2-module-map/releases
Note: A new GitHub release will be synced by Icinga Exchange automatically.
## Announcement
* Twitter (highlight @icinga, use hashtags #icinga #map #monitoringlove)
* Forum: https://monitoring-portal.org/t/map-module-for-icinga-web-2/101
# After the release
* Close the released version at https://github.com/nbuchwitz/icingaweb2-module-map/milestones
<?php
namespace Icinga\Module\Map\Controllers;
use Icinga\Module\Map\Forms\Config\GeneralConfigForm;
use Icinga\Web\Controller;
class ConfigController extends Controller
{
public function init()
{
$this->assertPermission('config/modules');
}
public function indexAction()
{
$form = new GeneralConfigForm();
$form->setIniConfig($this->Config());
$form->handleRequest();
$this->view->form = $form;
$this->view->tabs = $this->Module()->getConfigTabs()->activate('config');
}
}
<?php
namespace Icinga\Module\Map\Controllers;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\DataView\DataView;
class DataController extends Controller
{
/**
* Apply filters on a DataView
*
* @param DataView $dataView The DataView to apply filters on
*
* @return DataView $dataView
*/
protected function filterQuery(DataView $dataView)
{
$this->setupFilterControl($dataView, null, null, ['stateType', 'objectType', 'problems']);
return $dataView;
}
private $stateColumn;
private $stateChangeColumn;
/**
* Get JSON state objects
*/
public function pointsAction()
{
$points = array();
try {
// Borrowed from monitoring module
// Handle soft and hard states
$config = $this->config();
$stateType = strtolower($this->params->shift('stateType',
$config->get('map', 'stateType', 'soft')
));
$userPreferences = $this->Auth()->getUser()->getPreferences();
if ($userPreferences->has("map")) {
$stateType = $userPreferences->getValue("map", "stateType", $stateType);
}
$filter = (bool)$this->params->shift('problems', false) ? Filter::where('service_problem', 1) : null;
$objectType = strtolower($this->params->shift('objectType', 'all'));
if ($stateType === 'hard') {
$this->stateColumn = 'hard_state';
$this->stateChangeColumn = 'last_hard_state_change';
} else {
$this->stateColumn = 'state';
$this->stateChangeColumn = 'last_state_change';
}
if (in_array($objectType, ['all', 'host'])) {
// get host data
$hostQuery = $this->backend
->select()
->from('hoststatus', array(
'host_display_name',
'host_name',
'host_acknowledged',
'host_state' => 'host_' . $this->stateColumn,
'host_last_state_change' => 'host_' . $this->stateChangeColumn,
'host_in_downtime',
'host_problem',
'coordinates' => '_host_geolocation',
'icon' => '_host_map_icon',
))
->applyFilter(Filter::fromQueryString('_host_geolocation >'));
$this->applyRestriction('monitoring/filter/objects', $hostQuery);
$this->filterQuery($hostQuery);
// get service data
$serviceQuery = $this->backend
->select()
->from('servicestatus', array(
'host_name',
'service_display_name',
'service_name' => 'service',
'service_acknowledged',
'service_state' => 'service_' . $this->stateColumn,
'service_last_state_change' => 'service_' . $this->stateChangeColumn,
'service_in_downtime'
))
->applyFilter(Filter::fromQueryString('_host_geolocation >'));
if ($filter) {
$serviceQuery->applyFilter($filter);
}
$this->applyRestriction('monitoring/filter/objects', $serviceQuery);
$this->filterQuery($serviceQuery);
if ($hostQuery->count() > 0) {
foreach ($hostQuery as $row) {
$hostname = $row->host_name;
$host = (array)$row;
$host['services'] = array();
// check for broken coordinates
$coordinate_pattern = '/^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/';
if (!preg_match($coordinate_pattern, $host['coordinates'])) {
continue;
}
$host['coordinates'] = explode(",", $host['coordinates']);
$points['hosts'][$hostname] = $host;
}
}
// add services to host
if ($serviceQuery->count() > 0) {
foreach ($serviceQuery as $row) {
$hostname = $row->host_name;
$service = (array)$row;
unset($service['host_name']);
if (isset($points['hosts'][$hostname])) {
$points['hosts'][$hostname]['services'][$service['service_display_name']] = $service;
}
}
}
// remove hosts without problems and services
if ($filter) {
foreach ($points['hosts'] as $name => $host) {
if (empty($host['services']) && $host['host_problem'] != '1') {
unset($points['hosts'][$name]);
}
}
}
}
if (in_array($objectType, ['all', 'service'])) {
// get services with geolocation
$geoServiceQuery = $this->backend
->select()
->from('servicestatus', array(
'host_display_name',
'host_name',
'host_acknowledged',
'host_state' => 'host_' . $this->stateColumn,
'host_last_state_change' => 'host_' . $this->stateChangeColumn,
'host_in_downtime',
'service_display_name',
'service_name' => 'service',
'service_acknowledged',
'service_state' => 'service_' . $this->stateColumn,
'service_last_state_change' => 'service_' . $this->stateChangeColumn,
'service_in_downtime',
'coordinates' => '_service_geolocation',
'icon' => '_service_map_icon',
))->applyFilter(Filter::fromQueryString('_service_geolocation >'));
if ($filter) {
$geoServiceQuery->applyFilter($filter);
}
$this->applyRestriction('monitoring/filter/objects', $geoServiceQuery);
$this->filterQuery($geoServiceQuery);
// ---
if ($geoServiceQuery->count() > 0) {
foreach ($geoServiceQuery as $row) {
$identifier = $row->host_name . "!" . $row->service_name;
$ar = (array)$row;