icingaweb2-module-elasticsearch
icingaweb2-module-elasticsearch copied to clipboard
Array values for fields throw exception
Expected Behavior
ellipsis() should be able to handle Array type, but yet better the view script should decide upon Array values how to deal with such.
Current Behavior
check_result.command has an array as value.
array(5) { [0]=> string(37) "/usr/lib64/nagios/plugins/check_users" [1]=> string(2) "-c" [2]=> string(2) "50" [3]=> string(2) "-w" [4]=> string(2) "20" }
This causes a 500 error.
2017-11-29T21:28:37+01:00 - ERROR - ErrorException in /usr/share/php/Icinga/Util/StringHelper.php:57 with message: strlen() expects parameter 1 to be string, array given
#0 [internal function]: Icinga\Application\ApplicationBootstrap->Icinga\Application\{closure}(2, 'strlen() expect...', '/usr/share/php/...', 57, Array)
#1 /usr/share/php/Icinga/Util/StringHelper.php(57): strlen(Array)
#2 /usr/share/php/Icinga/Web/View/helpers/string.php(9): Icinga\Util\StringHelper::ellipsis(Array, 100, '...')
#3 [internal function]: Icinga\Web\View->Icinga\Web\View\{closure}(Array, 100)
#4 /usr/share/php/Icinga/Web/View.php(199): call_user_func_array(Object(Closure), Array)
#5 /usr/share/php/Icinga/Web/View.php(287): Icinga\Web\View->callHelperFunction('ellipsis', Array)
#6 zend.view:///usr/share/icingaweb2/modules/elasticsearch/application/views/scripts/events/index.phtml(28): Icinga\Web\View->__call('ellipsis', Array)
#7 /usr/share/php/Icinga/Web/View.php(270): include('zend.view:///us...')
#8 /usr/share/icingaweb2/library/vendor/Zend/View/Abstract.php(877): Icinga\Web\View->_run('/usr/share/icin...')
#9 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action/Helper/ViewRenderer.php(904): Zend_View_Abstract->render(NULL)
#10 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action/Helper/ViewRenderer.php(925): Zend_Controller_Action_Helper_ViewRenderer->renderScript('events/index.ph...', NULL)
#11 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action/Helper/ViewRenderer.php(964): Zend_Controller_Action_Helper_ViewRenderer->render()
#12 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action/HelperBroker.php(272): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#13 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(518): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
#14 /usr/share/php/Icinga/Web/Controller/Dispatcher.php(76): Zend_Controller_Action->dispatch('indexAction')
#15 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#16 /usr/share/php/Icinga/Application/Web.php(407): Zend_Controller_Front->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#17 /usr/share/php/Icinga/Application/webrouter.php(104): Icinga\Application\Web->dispatch()
#18 /usr/share/icingaweb2/public/index.php(4): require_once('/usr/share/php/...')
#19 {main}
Possible Solution
Ensure that $this->ellipsis
only is called with a string parameter as the function requires. Or put a safety hook inside, as the strlen() exception is not that informative and not logged to the frontend either.
Steps to Reproduce (for bugs)
- Icinga Web 2 & Elasticsearch module
- Icinga 2 ElasticsearchWriter enabled
- View specific host events for icinga2-* index
/etc/icingaweb2/modules/elasticsearch/instances.ini
[elasticsearch]
uri = "http://localhost:9200"
/etc/icingaweb2/modules/elasticsearch/eventtypes.ini
[icinga2]
instance = "elasticsearch"
index = "icinga2-*"
filter = "host={host.name}"
fields = "*"
To better catch the exception, let Icinga 2 run for a while. Modify the source code to catch the exception and dump the $column
.
diff --git a/application/views/scripts/events/index.phtml b/application/views/scripts/events/index.phtml
index 81f4389..48d7bdd 100644
--- a/application/views/scripts/events/index.phtml
+++ b/application/views/scripts/events/index.phtml
@@ -25,7 +25,11 @@
<tr href="<?= $documentsUri->with(array('index' => $event['_index'], 'type' => $event['_type'], 'id' => $event['_id'])) ?>">
<?php foreach ($fields as $getter):
$column = $getter($event['_source']);
+ try {
$ellipsis = $this->ellipsis($column, 100);
+ } catch (ErrorException $e) {
+ var_dump($column); die();
+ }
if ($column !== $ellipsis): ?>
<td title="<?= $this->escape($column) ?>"><?= $this->escape($ellipsis) ?></td>
<?php else: ?>
Context
This causes internal server error views, which requires you to watch /var/log/icingaweb2/icingaweb2.log
![screen shot 2017-11-29 at 21 45 37](https://user-images.githubusercontent.com/382049/33398268-ab651a9a-d54e-11e7-9a0b-081bb101fb81.png)
Your Environment
- Module version (System - About): aebb9bb7b8521ac1ab88173c4d6874f7c560d973
- Icinga Web 2 version and modules (System - About): icingaweb2-2.5.0.2.g890013c-0.2017.11.28+2.el7.icinga.noarch
- Icinga 2 version (
icinga2 --version
): icinga2-2.8.0.45.g1f52e39-0.2017.11.28+2.el7.icinga.x86_64 - Operating System and version: CentOS 7
- Webserver, PHP versions: Apache, PHP FPM, rh-php71