diff --git a/library/Icinga/Authentication/Backend/LdapUserBackend.php b/library/Icinga/Authentication/Backend/LdapUserBackend.php index a392fa682..858fa742e 100644 --- a/library/Icinga/Authentication/Backend/LdapUserBackend.php +++ b/library/Icinga/Authentication/Backend/LdapUserBackend.php @@ -286,7 +286,6 @@ class LdapUserBackend extends UserBackend $users[] = $row->{$this->userNameAttribute}; } } - return $users; } } diff --git a/library/Icinga/Protocol/Ldap/Capability.php b/library/Icinga/Protocol/Ldap/Capability.php index 625dc98bb..e467884d3 100644 --- a/library/Icinga/Protocol/Ldap/Capability.php +++ b/library/Icinga/Protocol/Ldap/Capability.php @@ -9,7 +9,8 @@ namespace Icinga\Protocol\Ldap; * Provides information about the available encryption mechanisms (StartTLS), the supported * LDAP protocol (v2/v3), vendor-specific extensions or protocols controls and extensions. */ -class Capability { +class Capability +{ const LDAP_SERVER_START_TLS_OID = '1.3.6.1.4.1.1466.20037'; diff --git a/library/Icinga/Util/Color.php b/library/Icinga/Util/Color.php index 5bc2f2815..616bb308a 100644 --- a/library/Icinga/Util/Color.php +++ b/library/Icinga/Util/Color.php @@ -6,7 +6,8 @@ namespace Icinga\Util; /** * Provide functions to change and convert colors. */ -class Color { +class Color +{ /** * Convert a given color string to an rgb-array containing * each color as a decimal value. diff --git a/library/Icinga/Util/String.php b/library/Icinga/Util/String.php index 9fb3cb223..0d42d0e76 100644 --- a/library/Icinga/Util/String.php +++ b/library/Icinga/Util/String.php @@ -79,4 +79,59 @@ class String return $matches; } + + /** + * Check if a string ends with a different string + * + * @param $haystack The string to search for matches + * @param $needle The string to match at the start of the haystack + * + * @return bool Whether or not needle is at the beginning of haystack + */ + public static function endsWith($haystack, $needle) + { + return $needle === '' || + (($temp = strlen($haystack) - strlen($needle)) >= 0 && false !== strpos($haystack, $needle, $temp)); + } + + /** + * Generates an array of strings that constitutes the cartesian product of all passed sets, with all + * string combinations concatenated using the passed join-operator. + * + *
+     *  cartesianProduct(
+     *      array(array('foo', 'bar'), array('mumble', 'grumble', null)),
+     *      '_'
+     *  );
+     *     => array('foo_mumble', 'foo_grumble', 'bar_mumble', 'bar_grumble', 'foo', 'bar')
+     * 
+ * + * @param array $sets An array of arrays containing all sets for which the cartesian + * product should be calculated. + * @param string $glue The glue used to join the strings, defaults to ''. + * + * @returns array The cartesian product in one array of strings. + */ + public static function cartesianProduct(array $sets, $glue = '') + { + $product = null; + foreach ($sets as $set) { + if (! isset($product)) { + $product = $set; + } else { + $newProduct = array(); + foreach ($product as $strA) { + foreach ($set as $strB) { + if ($strB === null) { + $newProduct []= $strA; + } else { + $newProduct []= $strA . $glue . $strB; + } + } + } + $product = $newProduct; + } + } + return $product; + } } diff --git a/library/Icinga/Web/Widget/Chart/InlinePie.php b/library/Icinga/Web/Widget/Chart/InlinePie.php index 0bddc906d..70aadf666 100644 --- a/library/Icinga/Web/Widget/Chart/InlinePie.php +++ b/library/Icinga/Web/Widget/Chart/InlinePie.php @@ -5,11 +5,13 @@ namespace Icinga\Web\Widget\Chart; use Icinga\Chart\PieChart; use Icinga\Module\Monitoring\Plugin\PerfdataSet; +use Icinga\Util\String; use Icinga\Web\Widget\AbstractWidget; use Icinga\Web\Url; use Icinga\Util\Format; use Icinga\Application\Logger; use Icinga\Exception\IcingaException; +use stdClass; /** * A SVG-PieChart intended to be displayed as a small icon next to labels, to offer a better visualization of the @@ -27,6 +29,45 @@ class InlinePie extends AbstractWidget const NUMBER_FORMAT_BYTES = 'bytes'; const NUMBER_FORMAT_RATIO = 'ratio'; + public static $colorsHostStates = array( + '#44bb77', // up + '#ff99aa', // down + '#cc77ff', // unreachable + '#77aaff' // pending + ); + + public static $colorsHostStatesHandledUnhandled = array( + '#44bb77', // up + '#44bb77', + '#ff99aa', // down + '#ff5566', + '#cc77ff', // unreachable + '#aa44ff', + '#77aaff', // pending + '#77aaff' + ); + + public static $colorsServiceStates = array( + '#44bb77', // Ok + '#ffaa44', // Warning + '#ff99aa', // Critical + '#aa44ff', // Unknown + '#77aaff' // Pending + ); + + public static $colorsServiceStatesHandleUnhandled = array( + '#44bb77', // Ok + '#44bb77', + '#ffaa44', // Warning + '#ffcc66', + '#ff99aa', // Critical + '#ff5566', + '#cc77ff', // Unknown + '#aa44ff', + '#77aaff', // Pending + '#77aaff' + ); + /** * The template string used for rendering this widget * @@ -231,4 +272,19 @@ EOD; $template = str_replace('{data}', htmlspecialchars(implode(',', $data)), $template); return $template; } + + public static function createFromStateSummary(stdClass $states, $title, array $colors) + { + $handledUnhandledStates = array(); + foreach ($states as $key => $value) { + if (String::endsWith($key, '_handled') || String::endsWith($key, '_unhandled')) { + $handledUnhandledStates[$key] = $value; + } + } + $chart = new self(array_values($handledUnhandledStates), $title, $colors); + return $chart + ->setSize(50) + ->setTitle('') + ->setSparklineClass('sparkline-multi'); + } } diff --git a/library/Icinga/Web/Widget/FilterEditor.php b/library/Icinga/Web/Widget/FilterEditor.php index 16c396f85..a362d1014 100644 --- a/library/Icinga/Web/Widget/FilterEditor.php +++ b/library/Icinga/Web/Widget/FilterEditor.php @@ -447,10 +447,10 @@ class FilterEditor extends AbstractWidget if ($this->addTo && $this->addTo === $filter->getId()) { return preg_replace( - '/ class="autosubmit"/', - ' class="autofocus"', - $this->selectOperator() - ) + '/ class="autosubmit"/', + ' class="autofocus"', + $this->selectOperator() + ) . '