2014-10-20 10:26:06 -04:00
|
|
|
<?php
|
|
|
|
|
|
2014-11-30 09:56:58 -05:00
|
|
|
namespace Icinga\Module\Businessprocess;
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
use Icinga\Application\Benchmark;
|
2015-02-06 17:22:38 -05:00
|
|
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
2014-12-02 05:35:21 -05:00
|
|
|
use Icinga\Data\Filter\Filter;
|
2014-10-20 10:26:06 -04:00
|
|
|
use Exception;
|
|
|
|
|
|
|
|
|
|
class BusinessProcess
|
|
|
|
|
{
|
|
|
|
|
const SOFT_STATE = 0;
|
2015-02-06 18:13:37 -05:00
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
const HARD_STATE = 1;
|
2015-02-06 17:22:38 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
|
|
|
|
* Name of the configured monitoring backend
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $backendName;
|
|
|
|
|
|
2015-02-06 17:22:38 -05:00
|
|
|
/**
|
|
|
|
|
* Monitoring backend to retrieve states from
|
|
|
|
|
*
|
|
|
|
|
* @var MonitoringBackend
|
|
|
|
|
*/
|
|
|
|
|
protected $backend;
|
|
|
|
|
|
2015-02-06 18:13:37 -05:00
|
|
|
/**
|
|
|
|
|
* Business process name
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-12-01 08:07:30 -05:00
|
|
|
protected $name;
|
2015-02-06 18:13:37 -05:00
|
|
|
|
2015-02-06 18:19:36 -05:00
|
|
|
/**
|
|
|
|
|
* Business process title
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $title;
|
|
|
|
|
|
2015-02-06 18:13:37 -05:00
|
|
|
/**
|
|
|
|
|
* State type, soft or hard
|
|
|
|
|
*
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
2014-10-20 10:26:06 -04:00
|
|
|
protected $state_type = self::HARD_STATE;
|
2015-02-06 18:13:37 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Warnings, usually filled at process build time
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2014-10-20 10:26:06 -04:00
|
|
|
protected $warnings = array();
|
2015-02-06 18:13:37 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
|
|
|
|
* Errors, usually filled at process build time
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $errors = array();
|
|
|
|
|
|
2015-02-06 18:13:37 -05:00
|
|
|
/**
|
|
|
|
|
* All used node objects
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2014-10-20 10:26:06 -04:00
|
|
|
protected $nodes = array();
|
2015-02-06 18:13:37 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Root node objects
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2014-10-20 10:26:06 -04:00
|
|
|
protected $root_nodes = array();
|
2015-02-06 18:13:37 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* All check names { 'hostA;ping' => true, ... }
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2014-10-20 10:26:06 -04:00
|
|
|
protected $all_checks = array();
|
2015-02-06 18:13:37 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* All host names { 'hostA' => true, ... }
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2014-10-20 10:26:06 -04:00
|
|
|
protected $hosts = array();
|
2015-02-06 18:13:37 -05:00
|
|
|
|
|
|
|
|
/**
|
2015-03-16 04:08:00 -04:00
|
|
|
* Applied state simulation
|
2015-02-06 18:13:37 -05:00
|
|
|
*
|
2015-03-16 04:08:00 -04:00
|
|
|
* @var Simulation
|
2015-02-06 18:13:37 -05:00
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
protected $simulation;
|
2015-02-06 18:13:37 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether we are in edit mode
|
|
|
|
|
*
|
|
|
|
|
* @var boolean
|
|
|
|
|
*/
|
2014-11-30 05:28:58 -05:00
|
|
|
protected $editMode = false;
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
protected $locked = true;
|
|
|
|
|
|
|
|
|
|
protected $changeCount = 0;
|
|
|
|
|
|
|
|
|
|
protected $simulationCount = 0;
|
|
|
|
|
|
2015-03-16 08:14:59 -04:00
|
|
|
protected $appliedChanges;
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
}
|
2014-11-30 05:28:58 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
public function applyChanges(ProcessChanges $changes)
|
|
|
|
|
{
|
|
|
|
|
$cnt = 0;
|
|
|
|
|
foreach ($changes->getChanges() as $change) {
|
|
|
|
|
$cnt++;
|
|
|
|
|
$change->applyTo($this);
|
|
|
|
|
}
|
|
|
|
|
$this->changeCount = $cnt;
|
|
|
|
|
|
2015-03-16 08:14:59 -04:00
|
|
|
$this->appliedChanges = $changes;
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function applySimulation(Simulation $simulation)
|
|
|
|
|
{
|
|
|
|
|
$cnt = 0;
|
|
|
|
|
|
|
|
|
|
foreach ($simulation->simulations() as $node => $s) {
|
|
|
|
|
if (! $this->hasNode($node)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$cnt++;
|
|
|
|
|
$this->getNode($node)
|
|
|
|
|
->setState($s->state)
|
|
|
|
|
->setAck($s->acknowledged)
|
2015-10-06 02:57:39 -04:00
|
|
|
->setDowntime($s->in_downtime)
|
|
|
|
|
->setMissing(false);
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->simulationCount = $cnt;
|
|
|
|
|
}
|
|
|
|
|
public function countChanges()
|
|
|
|
|
{
|
|
|
|
|
return $this->changeCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hasChanges()
|
|
|
|
|
{
|
|
|
|
|
return $this->countChanges() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 08:07:30 -05:00
|
|
|
public function setName($name)
|
|
|
|
|
{
|
|
|
|
|
$this->name = $name;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
|
{
|
|
|
|
|
return $this->name;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 18:19:36 -05:00
|
|
|
public function setTitle($title)
|
|
|
|
|
{
|
|
|
|
|
$this->title = $title;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTitle()
|
|
|
|
|
{
|
|
|
|
|
return $this->title ?: $this->getName();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
public function hasTitle()
|
2015-02-06 18:49:32 -05:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
return $this->title !== null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setBackendName($name)
|
|
|
|
|
{
|
|
|
|
|
$this->backendName = $name;
|
2015-02-06 18:49:32 -05:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
public function getBackendName()
|
|
|
|
|
{
|
|
|
|
|
return $this->backendName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hasBackendName()
|
|
|
|
|
{
|
|
|
|
|
return $this->backendName !== null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 18:25:41 -05:00
|
|
|
public function setBackend(MonitoringBackend $backend)
|
|
|
|
|
{
|
|
|
|
|
$this->backend = $backend;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getBackend()
|
|
|
|
|
{
|
2015-02-06 18:49:32 -05:00
|
|
|
if ($this->backend === null) {
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->backend = MonitoringBackend::createBackend(
|
|
|
|
|
$this->getBackendName()
|
|
|
|
|
);
|
2015-02-06 18:49:32 -05:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2015-02-06 18:25:41 -05:00
|
|
|
return $this->backend;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hasBackend()
|
|
|
|
|
{
|
|
|
|
|
return $this->backend !== null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 05:28:58 -05:00
|
|
|
public function hasBeenChanged()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
public function isLocked()
|
|
|
|
|
{
|
|
|
|
|
return $this->locked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function lock($lock = true)
|
2014-11-30 05:28:58 -05:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->locked = (bool) $lock;
|
2014-11-30 05:28:58 -05:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
public function unlock()
|
|
|
|
|
{
|
|
|
|
|
return $this->lock(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hasSimulations()
|
2014-11-30 05:28:58 -05:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
return $this->countSimulations() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function countSimulations()
|
|
|
|
|
{
|
|
|
|
|
return $this->simulationCount;
|
2014-11-30 05:28:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setEditMode($mode = true)
|
|
|
|
|
{
|
|
|
|
|
$this->editMode = (bool) $mode;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isEditMode()
|
|
|
|
|
{
|
|
|
|
|
return $this->editMode;
|
|
|
|
|
}
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2015-03-16 08:14:59 -04:00
|
|
|
public function clearAppliedChanges()
|
|
|
|
|
{
|
|
|
|
|
if ($this->appliedChanges !== null) {
|
|
|
|
|
$this->appliedChanges->clear();
|
|
|
|
|
}
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
public function useSoftStates()
|
|
|
|
|
{
|
|
|
|
|
$this->state_type = self::SOFT_STATE;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function useHardStates()
|
|
|
|
|
{
|
|
|
|
|
$this->state_type = self::HARD_STATE;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 19:55:46 -05:00
|
|
|
public function usesSoftStates()
|
|
|
|
|
{
|
|
|
|
|
return $this->state_type === self::SOFT_STATE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function usesHardStates()
|
|
|
|
|
{
|
|
|
|
|
$this->state_type === self::HARD_STATE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 05:58:24 -05:00
|
|
|
public function addRootNode($name)
|
|
|
|
|
{
|
|
|
|
|
$this->root_nodes[$name] = $this->getNode($name);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 08:17:03 -04:00
|
|
|
public function removeRootNode($name)
|
|
|
|
|
{
|
|
|
|
|
if ($this->isRootNode($name)) {
|
|
|
|
|
unset($this->root_nodes[$name]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isRootNode($name)
|
|
|
|
|
{
|
|
|
|
|
return array_key_exists($name, $this->root_nodes);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 18:49:32 -05:00
|
|
|
public function retrieveStatesFromBackend()
|
2014-10-20 10:26:06 -04:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
try {
|
|
|
|
|
$this->reallyRetrieveStatesFromBackend();
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$this->error(
|
|
|
|
|
$this->translate('Could not retrieve process state: %s'),
|
|
|
|
|
$e->getMessage()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function reallyRetrieveStatesFromBackend()
|
|
|
|
|
{
|
|
|
|
|
Benchmark::measure('Retrieving states for business process ' . $this->getName());
|
2015-02-06 18:49:32 -05:00
|
|
|
$backend = $this->getBackend();
|
2014-10-20 10:26:06 -04:00
|
|
|
// TODO: Split apart, create a dedicated function.
|
|
|
|
|
// Separate "parse-logic" from "retrieve-state-logic"
|
|
|
|
|
// Allow DB-based backend
|
|
|
|
|
// Use IcingaWeb2 Multi-Backend-Support
|
|
|
|
|
$check_results = array();
|
|
|
|
|
$hostFilter = array_keys($this->hosts);
|
2015-02-06 18:13:37 -05:00
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
if ($this->state_type === self::HARD_STATE) {
|
2015-01-28 14:02:50 -05:00
|
|
|
$hostStateColumn = 'host_hard_state';
|
|
|
|
|
$hostStateChangeColumn = 'host_last_hard_state_change';
|
|
|
|
|
$serviceStateColumn = 'service_hard_state';
|
|
|
|
|
$serviceStateChangeColumn = 'service_last_hard_state_change';
|
2014-10-20 10:26:06 -04:00
|
|
|
} else {
|
2015-01-28 14:02:50 -05:00
|
|
|
$hostStateColumn = 'host_state';
|
|
|
|
|
$hostStateChangeColumn = 'host_last_state_change';
|
|
|
|
|
$serviceStateColumn = 'service_state';
|
|
|
|
|
$serviceStateChangeColumn = 'service_last_state_change';
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2014-12-02 05:35:21 -05:00
|
|
|
$filter = Filter::matchAny();
|
|
|
|
|
foreach ($hostFilter as $host) {
|
2015-02-06 18:01:30 -05:00
|
|
|
$filter->addFilter(Filter::where('host_name', $host));
|
2014-12-02 05:35:21 -05:00
|
|
|
}
|
2015-02-06 18:01:30 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
if ($filter->isEmpty()) {
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 05:06:03 -05:00
|
|
|
$hostStatus = $backend->select()->from('hostStatus', array(
|
2015-01-28 14:02:50 -05:00
|
|
|
'hostname' => 'host_name',
|
|
|
|
|
'last_state_change' => $hostStateChangeColumn,
|
|
|
|
|
'in_downtime' => 'host_in_downtime',
|
|
|
|
|
'ack' => 'host_acknowledged',
|
|
|
|
|
'state' => $hostStateColumn
|
2014-12-02 05:35:21 -05:00
|
|
|
))->applyFilter($filter)->getQuery()->fetchAll();
|
2014-11-30 05:06:03 -05:00
|
|
|
|
|
|
|
|
$serviceStatus = $backend->select()->from('serviceStatus', array(
|
2015-01-28 14:02:50 -05:00
|
|
|
'hostname' => 'host_name',
|
|
|
|
|
'service' => 'service_description',
|
|
|
|
|
'last_state_change' => $serviceStateChangeColumn,
|
|
|
|
|
'in_downtime' => 'service_in_downtime',
|
|
|
|
|
'ack' => 'service_acknowledged',
|
|
|
|
|
'state' => $serviceStateColumn
|
2014-12-02 05:35:21 -05:00
|
|
|
))->applyFilter($filter)->getQuery()->fetchAll();
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2015-09-11 03:31:58 -04:00
|
|
|
foreach ($serviceStatus as $row) {
|
|
|
|
|
$this->handleDbRow($row);
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2015-09-11 03:31:58 -04:00
|
|
|
|
|
|
|
|
foreach ($hostStatus as $row) {
|
|
|
|
|
$this->handleDbRow($row);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
ksort($this->root_nodes);
|
2015-03-16 04:08:00 -04:00
|
|
|
Benchmark::measure('Got states for business process ' . $this->getName());
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 03:31:58 -04:00
|
|
|
protected function handleDbRow($row)
|
|
|
|
|
{
|
|
|
|
|
$key = $row->hostname;
|
|
|
|
|
if (property_exists($row, 'service')) {
|
|
|
|
|
$key .= ';' . $row->service;
|
|
|
|
|
} else {
|
|
|
|
|
$key .= ';Hoststatus';
|
|
|
|
|
}
|
|
|
|
|
// We fetch more states than we need, so skip unknown ones
|
|
|
|
|
if (! $this->hasNode($key)) return;
|
|
|
|
|
$node = $this->getNode($key);
|
|
|
|
|
|
|
|
|
|
if ($row->state !== null) {
|
|
|
|
|
$node->setState($row->state)->setMissing(false);
|
|
|
|
|
}
|
|
|
|
|
if ($row->last_state_change !== null) {
|
|
|
|
|
$node->setLastStateChange($row->last_state_change);
|
|
|
|
|
}
|
|
|
|
|
if ((int) $row->in_downtime === 1) {
|
|
|
|
|
$node->setDowntime(true);
|
|
|
|
|
}
|
|
|
|
|
if ((int) $row->ack === 1) {
|
|
|
|
|
$node->setAck(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 05:28:58 -05:00
|
|
|
public function getChildren()
|
|
|
|
|
{
|
|
|
|
|
return $this->getRootNodes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function countChildren()
|
|
|
|
|
{
|
|
|
|
|
return count($this->root_nodes);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
public function getRootNodes()
|
|
|
|
|
{
|
2014-12-02 05:35:21 -05:00
|
|
|
ksort($this->root_nodes);
|
2014-10-20 10:26:06 -04:00
|
|
|
return $this->root_nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 05:28:58 -05:00
|
|
|
public function getNodes()
|
|
|
|
|
{
|
|
|
|
|
return $this->nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
public function hasNode($name)
|
|
|
|
|
{
|
|
|
|
|
return array_key_exists($name, $this->nodes);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 13:56:52 -05:00
|
|
|
public function createService($host, $service)
|
|
|
|
|
{
|
|
|
|
|
$node = new ServiceNode(
|
|
|
|
|
$this,
|
|
|
|
|
(object) array(
|
|
|
|
|
'hostname' => $host,
|
|
|
|
|
'service' => $service
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$this->nodes[$host . ';' . $service] = $node;
|
2015-02-06 18:01:30 -05:00
|
|
|
$this->hosts[$host] = true;
|
2015-01-28 13:56:52 -05:00
|
|
|
return $node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createHost($host)
|
|
|
|
|
{
|
|
|
|
|
$node = new HostNode($this, (object) array('hostname' => $host));
|
|
|
|
|
$this->nodes[$host . ';Hoststatus'] = $node;
|
2015-02-06 18:01:30 -05:00
|
|
|
$this->hosts[$host] = true;
|
2015-01-28 13:56:52 -05:00
|
|
|
return $node;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 19:55:46 -05:00
|
|
|
public function createImportedNode($config, $name)
|
|
|
|
|
{
|
|
|
|
|
$node = new ImportedNode($this, (object) array('name' => $name, 'configName' => $config));
|
|
|
|
|
$this->nodes[$name] = $node;
|
|
|
|
|
return $node;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
public function getNode($name)
|
|
|
|
|
{
|
|
|
|
|
if (array_key_exists($name, $this->nodes)) {
|
|
|
|
|
return $this->nodes[$name];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fallback: if it is a service, create an empty one:
|
|
|
|
|
$this->warn(sprintf('The node "%s" doesn\'t exist', $name));
|
|
|
|
|
$pos = strpos($name, ';');
|
|
|
|
|
if ($pos !== false) {
|
|
|
|
|
$host = substr($name, 0, $pos);
|
|
|
|
|
$service = substr($name, $pos + 1);
|
2015-01-28 14:02:50 -05:00
|
|
|
return $this->createService($host, $service);
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Exception(
|
|
|
|
|
sprintf('The node "%s" doesn\'t exist', $name)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 13:56:52 -05:00
|
|
|
public function addObjectName($name)
|
|
|
|
|
{
|
|
|
|
|
$this->all_checks[$name] = 1;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 05:08:04 -05:00
|
|
|
public function addNode($name, Node $node)
|
2014-10-20 10:26:06 -04:00
|
|
|
{
|
|
|
|
|
if (array_key_exists($name, $this->nodes)) {
|
|
|
|
|
$this->warn(
|
|
|
|
|
sprintf(
|
2015-03-16 04:08:00 -04:00
|
|
|
mt('businessprocess', 'Node "%s" has been defined twice'),
|
2014-10-20 10:26:06 -04:00
|
|
|
$name
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-02-06 18:01:30 -05:00
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
$this->nodes[$name] = $node;
|
2015-03-16 08:17:03 -04:00
|
|
|
|
|
|
|
|
if ($node->getDisplay() > 0) {
|
|
|
|
|
if (! $this->isRootNode($name)) {
|
|
|
|
|
$this->addRootNode($name);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($this->isRootNode($name)) {
|
|
|
|
|
$this->removeRootNode($name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 15:11:20 -05:00
|
|
|
public function listBpNodes()
|
|
|
|
|
{
|
|
|
|
|
$nodes = array();
|
|
|
|
|
|
|
|
|
|
foreach ($this->nodes as $node) {
|
|
|
|
|
if (! $node instanceof BpNode) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$name = (string) $node;
|
|
|
|
|
$alias = $node->getAlias();
|
|
|
|
|
$nodes[$name] = $name === $alias ? $name : sprintf('%s (%s)', $alias, $node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
natsort($nodes);
|
|
|
|
|
return $nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
public function getUnboundNodes()
|
|
|
|
|
{
|
|
|
|
|
$nodes = array();
|
|
|
|
|
|
|
|
|
|
foreach ($this->nodes as $node) {
|
|
|
|
|
if (! $node instanceof BpNode) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($node->hasParents()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 08:17:03 -04:00
|
|
|
if ($node->getDisplay() === 0) {
|
2015-03-16 04:08:00 -04:00
|
|
|
$nodes[(string) $node] = $node;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
public function hasWarnings()
|
|
|
|
|
{
|
|
|
|
|
return ! empty($this->warnings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getWarnings()
|
|
|
|
|
{
|
|
|
|
|
return $this->warnings;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
public function hasErrors()
|
|
|
|
|
{
|
|
|
|
|
return ! empty($this->errors) || $this->isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getErrors()
|
|
|
|
|
{
|
|
|
|
|
$errors = $this->errors;
|
|
|
|
|
if ($this->isEmpty()) {
|
|
|
|
|
$errors[] = sprintf(
|
|
|
|
|
$this->translate(
|
|
|
|
|
'No business process nodes for "%s" have been defined yet'
|
|
|
|
|
),
|
|
|
|
|
$this->getTitle()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return $errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function translate($msg)
|
|
|
|
|
{
|
|
|
|
|
return mt('businessprocess', $msg);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
protected function warn($msg)
|
|
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
$args = func_get_args();
|
|
|
|
|
array_shift($args);
|
2014-10-20 10:26:06 -04:00
|
|
|
if (isset($this->parsing_line_number)) {
|
|
|
|
|
$this->warnings[] = sprintf(
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->translate('Parser waring on %s:%s: %s'),
|
2014-10-20 10:26:06 -04:00
|
|
|
$this->filename,
|
|
|
|
|
$this->parsing_line_number,
|
2015-03-16 04:08:00 -04:00
|
|
|
vsprintf($msg, $args)
|
2014-10-20 10:26:06 -04:00
|
|
|
);
|
|
|
|
|
} else {
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->warnings[] = vsprintf($msg, $args);
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
|
|
|
|
}
|
2014-11-30 05:30:59 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function error($msg)
|
|
|
|
|
{
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
array_shift($args);
|
|
|
|
|
$this->errors[] = vsprintf($msg, $args);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-02 05:38:42 -05:00
|
|
|
public function toLegacyConfigString()
|
|
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
$settings = array();
|
|
|
|
|
if ($this->hasTitle()) {
|
|
|
|
|
$settings['Title'] = $this->getTitle();
|
|
|
|
|
}
|
|
|
|
|
// TODO: backendName?
|
|
|
|
|
if ($this->backend) {
|
|
|
|
|
$settings['Backend'] = $this->backend->getName();
|
|
|
|
|
}
|
|
|
|
|
$settings['Statetype'] = $this->usesSoftStates() ? 'soft' : 'hard';
|
2015-02-06 18:35:11 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
if (false) {
|
|
|
|
|
$settings['SLA Hosts'] = implode(', ', array());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$conf = "### Business Process Config File ###\n#\n";
|
|
|
|
|
foreach ($settings as $key => $value) {
|
|
|
|
|
$conf .= sprintf("# %-9s : %s\n", $key, $value);
|
|
|
|
|
}
|
2015-02-06 18:35:11 -05:00
|
|
|
|
2015-10-05 12:48:43 -04:00
|
|
|
$conf .= "#\n###################################\n\n";
|
2015-02-06 18:35:11 -05:00
|
|
|
|
2015-03-03 06:51:03 -05:00
|
|
|
$rendered = array();
|
2014-12-02 05:38:42 -05:00
|
|
|
foreach ($this->getChildren() as $child) {
|
2015-03-03 06:51:03 -05:00
|
|
|
$conf .= $child->toLegacyConfigString($rendered);
|
2015-10-05 10:40:08 -04:00
|
|
|
$rendered[(string) $child] = true;
|
2014-12-02 05:38:42 -05:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
foreach ($this->getUnboundNodes() as $node) {
|
|
|
|
|
$conf .= $node->toLegacyConfigString($rendered);
|
2015-10-05 10:40:08 -04:00
|
|
|
$rendered[(string) $node] = true;
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
2015-03-02 12:21:50 -05:00
|
|
|
return $conf . "\n";
|
2014-12-02 05:38:42 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
public function isEmpty()
|
|
|
|
|
{
|
|
|
|
|
return $this->countChildren() === 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 05:30:59 -05:00
|
|
|
public function renderHtml($view)
|
|
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
$html = '';
|
2014-11-30 05:30:59 -05:00
|
|
|
foreach ($this->getRootNodes() as $name => $node) {
|
|
|
|
|
$html .= $node->renderHtml($view);
|
|
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
return $html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function renderUnbound($view)
|
|
|
|
|
{
|
|
|
|
|
$html = '';
|
2015-03-16 08:14:59 -04:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$unbound = $this->getUnboundNodes();
|
|
|
|
|
if (empty($unbound)) {
|
|
|
|
|
return $html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$parent = new BpNode($this, (object) array(
|
|
|
|
|
'name' => '__unbound__',
|
|
|
|
|
'operator' => '|',
|
|
|
|
|
'child_names' => array_keys($unbound)
|
|
|
|
|
));
|
|
|
|
|
$parent->getState();
|
|
|
|
|
$parent->setMissing()
|
|
|
|
|
->setDowntime(false)
|
|
|
|
|
->setAck(false)
|
|
|
|
|
->setAlias('Unbound nodes');
|
|
|
|
|
|
|
|
|
|
$html .= $parent->renderHtml($view);
|
2014-11-30 05:30:59 -05:00
|
|
|
return $html;
|
|
|
|
|
}
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|