...
 
Commits (2)

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

## 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 -->
## Your Environment
<!--- Include as many relevant details about the environment you experienced the problem in -->
* Director version (System - About):
* Icinga Web 2 version and modules (System - About):
* Icinga 2 version (`icinga2 --version`):
* Operating System and version:
* Webserver, PHP versions:
## Editors
/.idea/
.*.sw[op]
## PHP vendor artifacts
/vendor/
stages:
- Coding Standards
- Unit-Tests with DB
PSR2 CS Test:
stage: Coding Standards
tags:
- xenial
script:
- phpcs --report-width=auto --report-full --report-gitblame --report-summary -p --standard=PSR2 --extensions=php --encoding=utf-8 -w -s library/Director/ library/vendor/ipl/ application/ *.php test
CentOS 7/MySQL:
stage: Unit-Tests with DB
tags:
- centos7
- director
variables:
DIRECTOR_TESTDB: "director_test_${CI_BUILD_ID}_${CI_RUNNER_ID}"
DIRECTOR_TESTDB_RES: "Director MySQL TestDB"
before_script:
- mysql -u root -e "CREATE DATABASE $DIRECTOR_TESTDB"
after_script:
- mysql -u root -e "DROP DATABASE $DIRECTOR_TESTDB"
script:
- phpunit --verbose
CentOS 7/PostgreSQL:
stage: Unit-Tests with DB
tags:
- centos7
- director
variables:
DIRECTOR_TESTDB: "director_test_${CI_BUILD_ID}_${CI_RUNNER_ID}"
DIRECTOR_TESTDB_RES: "Director PostgreSQL TestDB"
DIRECTOR_TESTDB_USER: "director_${CI_BUILD_ID}_${CI_RUNNER_ID}"
before_script:
- psql postgres -q -c "CREATE DATABASE $DIRECTOR_TESTDB WITH ENCODING 'UTF8';"
- psql $DIRECTOR_TESTDB -q -c "CREATE USER $DIRECTOR_TESTDB_USER WITH PASSWORD 'testing'; GRANT ALL PRIVILEGES ON DATABASE $DIRECTOR_TESTDB TO $DIRECTOR_TESTDB_USER; CREATE EXTENSION pgcrypto;"
after_script:
- psql postgres -c "DROP DATABASE $DIRECTOR_TESTDB"
- psql postgres -c "DROP USER $DIRECTOR_TESTDB_USER"
script:
- phpunit --verbose
#CentOS 6/MySQL:
# stage: Unit-Tests with DB
# tags:
# - centos6
# - director
# variables:
# DIRECTOR_TESTDB: "director_test_${CI_BUILD_ID}_${CI_RUNNER_ID}"
# DIRECTOR_TESTDB_RES: "Director MySQL TestDB"
# before_script:
# - mysql -u root -e "CREATE DATABASE $DIRECTOR_TESTDB"
# after_script:
# - mysql -u root -e "DROP DATABASE $DIRECTOR_TESTDB"
# script:
# - phpunit
Jessie/MySQL:
stage: Unit-Tests with DB
tags:
- jessie
- director
variables:
DIRECTOR_TESTDB: "director_test_${CI_BUILD_ID}_${CI_RUNNER_ID}"
DIRECTOR_TESTDB_RES: "Director MySQL TestDB"
before_script:
- mysql -u root -e "CREATE DATABASE $DIRECTOR_TESTDB"
after_script:
- mysql -u root -e "DROP DATABASE $DIRECTOR_TESTDB"
script:
- phpunit --verbose
Jessie/PostgreSQL:
stage: Unit-Tests with DB
tags:
- jessie
- director
variables:
DIRECTOR_TESTDB: "director_test_${CI_BUILD_ID}_${CI_RUNNER_ID}"
DIRECTOR_TESTDB_RES: "Director PostgreSQL TestDB"
DIRECTOR_TESTDB_USER: "director_${CI_BUILD_ID}_${CI_RUNNER_ID}"
before_script:
- psql postgres -q -c "CREATE DATABASE $DIRECTOR_TESTDB WITH ENCODING 'UTF8';"
- psql $DIRECTOR_TESTDB -q -c "CREATE USER $DIRECTOR_TESTDB_USER WITH PASSWORD 'testing'; GRANT ALL PRIVILEGES ON DATABASE $DIRECTOR_TESTDB TO $DIRECTOR_TESTDB_USER; CREATE EXTENSION pgcrypto;"
after_script:
- psql postgres -c "DROP DATABASE $DIRECTOR_TESTDB"
- psql postgres -c "DROP USER $DIRECTOR_TESTDB_USER"
script:
- phpunit --verbose
Xenial/MySQL:
stage: Unit-Tests with DB
tags:
- xenial
- director
variables:
DIRECTOR_TESTDB: "director_test_${CI_BUILD_ID}_${CI_RUNNER_ID}"
DIRECTOR_TESTDB_RES: "Director MySQL TestDB"
before_script:
- mysql -u root -e "CREATE DATABASE $DIRECTOR_TESTDB"
after_script:
- mysql -u root -e "DROP DATABASE $DIRECTOR_TESTDB"
script:
- phpunit --verbose
Xenial/PostgreSQL:
stage: Unit-Tests with DB
tags:
- ubuntu
- director
variables:
DIRECTOR_TESTDB: "director_test_${CI_BUILD_ID}_${CI_RUNNER_ID}"
DIRECTOR_TESTDB_RES: "Director PostgreSQL TestDB"
DIRECTOR_TESTDB_USER: "director_${CI_BUILD_ID}_${CI_RUNNER_ID}"
before_script:
- psql postgres -q -c "CREATE DATABASE $DIRECTOR_TESTDB WITH ENCODING 'UTF8';"
- psql $DIRECTOR_TESTDB -q -c "CREATE USER $DIRECTOR_TESTDB_USER WITH PASSWORD 'testing'; GRANT ALL PRIVILEGES ON DATABASE $DIRECTOR_TESTDB TO $DIRECTOR_TESTDB_USER; CREATE EXTENSION pgcrypto;"
after_script:
- psql postgres -c "DROP DATABASE $DIRECTOR_TESTDB"
- psql postgres -c "DROP USER $DIRECTOR_TESTDB_USER"
script:
- phpunit --verbose
language: php
php:
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- nightly
services:
- mysql
- postgresql
cache:
directories:
- vendor
matrix:
fast_finish: true
include:
- env: CHECK=phpcs
php: nightly # Note: will be allowed failure
- env: CHECK=phpcs
php: '7.0'
- env: CHECK=phpcs
php: '5.4'
allow_failures:
- php: nightly
- php: '7.3'
env:
- CHECK=phpunit DB=mysql DIRECTOR_TESTDB_RES="Director MySQL TestDB" DIRECTOR_TESTDB="director_test"
- CHECK=phpunit DB=pgsql DIRECTOR_TESTDB_RES="Director PostgreSQL TestDB" DIRECTOR_TESTDB="director_test"
DIRECTOR_TESTDB_USER="director_test"
before_script:
- ./test/setup_vendor.sh
- '[ "$CHECK" != phpunit ] || ./test/travis-prepare.sh'
script:
- '[ "$CHECK" != phpcs ] || php vendor/phpcs.phar'
- '[ "$CHECK" != phpunit ] || php vendor/phpunit.phar --testdox || php vendor/phpunit.phar --verbose'
This diff is collapsed.
Icinga Director
===============
Icinga Director has been designed to make Icinga 2 configuration handling easy.
It tries to target two main audiences:
* Users with the desire to completely automate their datacenter
* Sysops willing to grant their "point & click" users a lot of flexibility
What makes Icinga Director so special is the fact that it tries to target both
of them at once.
![Icinga Director](doc/screenshot/director/readme/director_main_screen.png)
Read more about Icinga Director in our [Introduction](doc/01-Introduction.md) section.
Afterwards, you should be ready for [getting started](doc/04-Getting-started.md).
Documentation
-------------
Please have a look at our [Installation instructions](doc/02-Installation.md)
and our hints for how to apply [Upgrades](doc/05-Upgrading.md). We love automation
and in case you also do so, the [Automation chapter](doc/03-Automation.md) could
be worth a read. When upgrading, you should also have a look at our [Changelog](doc/82-Changelog.md).
You could be interested in understanding how the [Director works](doc/10-How-it-works.md)
internally. [Working with agents](doc/24-Working-with-agents.md) is a topic that
affects many Icinga administrators. Other interesting entry points might be
[Import and Synchronization](doc/70-Import-and-Sync.md), our [CLI interface](doc/60-CLI.md),
the [REST API](doc/70-REST-API.md) and last but not least our [FAQ](doc/80-FAQ.md).
A complete list of all our documentation can be found in the [doc](doc/) directory.
Contributing
------------
Icinga Director is an Open Source project and lives from your contributions. No
matter whether these are feature requests, issues, translations, documentation
or code.
* Please check whether a related issue already exists on our [Issue Tracker](https://github.com/Icinga/icingaweb2-module-director/issues)
* Make sure your code conforms to the [PSR-2: Coding Style Guide](http://www.php-fig.org/psr/psr-2/)
* [Unit-Tests](doc/93-Testing.md) would be great
* Send a [Pull Request](https://github.com/Icinga/icingaweb2-module-director/pulls)
(it will automatically be tested on Travis-CI)
* We try hard to keep our master always green: [![Build Status](https://travis-ci.org/Icinga/icingaweb2-module-director.svg?branch=master)](https://travis-ci.org/Icinga/icingaweb2-module-director)
Addons
------
The following are to be considered community-supported modules, as they are not
supported by the Icinga Team. At least not yet. But please give them a try if
they fit your needs. They are being used in productive environments:
* [AWS - Amazon Web Services](https://github.com/Icinga/icingaweb2-module-aws):
provides an Import Source for Autoscaling Groups on AWS
* [File-Shipper](https://github.com/Icinga/icingaweb2-module-fileshipper):
allows Director to ship additional config files with manual config with its
deployments
* [PuppetDB](https://github.com/Icinga/icingaweb2-module-puppetdb): provides
an Import Source dealing with your PuppetDB
* [vSphere](https://github.com/Icinga/icingaweb2-module-vsphere): VMware vSphere
Import Source for Virtual Machines and Host Systems
<?php
namespace Icinga\Module\Director\Clicommands;
use Icinga\Date\DateFormatter;
use Icinga\Module\Director\Cli\Command;
use Icinga\Module\Director\DirectorObject\Automation\Basket;
use Icinga\Module\Director\DirectorObject\Automation\BasketSnapshot;
/**
* Export Director Config Objects
*/
class BasketCommand extends Command
{
/**
* List configured Baskets
*
* USAGE
*
* icingacli director basket list
*
* OPTIONS
*/
public function listAction()
{
$db = $this->db()->getDbAdapter();
$query = $db->select()
->from('director_basket', 'basket_name')
->order('basket_name');
foreach ($db->fetchCol($query) as $name) {
echo "$name\n";
}
}
/**
* JSON-dump for objects related to the given Basket
*
* USAGE
*
* icingacli director basket dump --name <basket>
*
* OPTIONS
*/
public function dumpAction()
{
$basket = $this->requireBasket();
$snapshot = BasketSnapshot::createForBasket($basket, $this->db());
echo $snapshot->getJsonDump() . "\n";
}
/**
* Take a snapshot for the given Basket
*
* USAGE
*
* icingacli director basket snapshot --name <basket>
*
* OPTIONS
*/
public function snapshotAction()
{
$basket = $this->requireBasket();
$snapshot = BasketSnapshot::createForBasket($basket, $this->db());
$snapshot->store();
$hexSum = bin2hex($snapshot->get('content_checksum'));
printf(
"Snapshot '%s' taken for Basket '%s' at %s\n",
substr($hexSum, 0, 7),
$basket->get('basket_name'),
DateFormatter::formatDateTime($snapshot->get('ts_create') / 1000)
);
}
/**
* Restore a Basket from JSON dump provided on STDIN
*
* USAGE
*
* icingacli director basket restore < basket-dump.json
*
* OPTIONS
*/
public function restoreAction()
{
$json = file_get_contents('php://stdin');
BasketSnapshot::restoreJson($json, $this->db());
echo "Objects from Basket Snapshot have been restored\n";
}
/**
*/
protected function requireBasket()
{
return Basket::load($this->params->getRequired('name'), $this->db());
}
}
<?php
namespace Icinga\Module\Director\Clicommands;
use Icinga\Application\Benchmark;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filter\FilterChain;
use Icinga\Data\Filter\FilterExpression;
use Icinga\Module\Director\Cli\Command;
use Icinga\Module\Director\Objects\HostGroupMembershipResolver;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaHostVar;
class BenchmarkCommand extends Command
{
public function resolvehostgroupsAction()
{
$resolver = new HostGroupMembershipResolver($this->db());
$resolver->refreshDb();
}
public function filterAction()
{
$flat = array();
/** @var FilterChain|FilterExpression $filter */
$filter = Filter::fromQueryString(
// 'object_name=*ic*2*&object_type=object'
'vars.bpconfig=*'
);
Benchmark::measure('ready');
$objs = IcingaHost::loadAll($this->db());
Benchmark::measure('db done');
foreach ($objs as $host) {
$flat[$host->get('id')] = (object) array();
foreach ($host->getProperties() as $k => $v) {
$flat[$host->get('id')]->$k = $v;
}
}
Benchmark::measure('objects ready');
$vars = IcingaHostVar::loadAll($this->db());
Benchmark::measure('vars loaded');
foreach ($vars as $var) {
if (! array_key_exists($var->get('host_id'), $flat)) {
// Templates?
continue;
}
$flat[$var->get('host_id')]->{'vars.' . $var->get('varname')} = $var->get('varvalue');
}
Benchmark::measure('vars done');
foreach ($flat as $host) {
if ($filter->matches($host)) {
echo $host->object_name . "\n";
}
}
}
}
<?php
namespace Icinga\Module\Director\Clicommands;
use Icinga\Module\Director\Cli\ObjectCommand;
/**
* Manage Icinga Commands
*
* Use this command to show, create, modify or delete Icinga Command
* objects
*/
class CommandCommand extends ObjectCommand
{
}
<?php
namespace Icinga\Module\Director\Clicommands;
use Icinga\Module\Director\Cli\ObjectsCommand;
/**
* List Icinga Commands
*
* Use this command to list Icinga Command objects
*/
class CommandsCommand extends ObjectsCommand
{
}
<?php
namespace Icinga\Module\Director\Clicommands;
use Icinga\Application\Benchmark;
use Icinga\Module\Director\Cli\Command;
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use Icinga\Module\Director\Util;
/**
* Generate, show and deploy Icinga 2 configuration
*/
class ConfigCommand extends Command
{
/**
* Re-render the current configuration
*/
public function renderAction()
{
$profile = $this->params->shift('profile');
if ($profile) {
$this->enableDbProfiler();
}
$config = new IcingaConfig($this->db());
Benchmark::measure('Rendering config');
if ($config->hasBeenModified()) {
Benchmark::measure('Config rendered, storing to db');
$config->store();
Benchmark::measure('All done');
$checksum = $config->getHexChecksum();
printf(
"New config with checksum %s has been generated\n",
$checksum
);
} else {
$checksum = $config->getHexChecksum();
printf(
"Config with checksum %s already exists\n",
$checksum
);
}
if ($profile) {
$this->dumpDbProfile();
}
}
protected function dumpDbProfile()
{
$profiler = $this->getDbProfiler();
$totalTime = $profiler->getTotalElapsedSecs();
$queryCount = $profiler->getTotalNumQueries();
$longestTime = 0;
$longestQuery = null;
/** @var \Zend_Db_Profiler_Query $query */
foreach ($profiler->getQueryProfiles() as $query) {
echo $query->getQuery() . "\n";
if ($query->getElapsedSecs() > $longestTime) {
$longestTime = $query->getElapsedSecs();
$longestQuery = $query->getQuery();
}
}
echo 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds' . "\n";
echo 'Average query length: ' . $totalTime / $queryCount . ' seconds' . "\n";
echo 'Queries per second: ' . $queryCount / $totalTime . "\n";
echo 'Longest query length: ' . $longestTime . "\n";
echo "Longest query: \n" . $longestQuery . "\n";
}
protected function getDbProfiler()
{
return $this->db()->getDbAdapter()->getProfiler();
}
protected function enableDbProfiler()
{
return $this->getDbProfiler()->setEnabled(true);
}
/**
* Deploy the current configuration
*
* Does nothing if config didn't change unless you provide