Icinga / icingaweb2-module-director

The Director aims to be your new favourite Icinga config deployment tool. Director is designed for those who want to automate their configuration deployment and those who want to grant their “point & click” users easy access to the configuration.
https://icinga.com/docs/director/latest
GNU General Public License v2.0
413 stars 203 forks source link

Cannot edit host object with utf-8 characters #988

Closed pfried closed 7 years ago

pfried commented 7 years ago

I copy&pasted a hostname in hosts in the director. The name appeared to be UTF-8. Unfortunately now I cannot edit the item anymore as i get an error. I also tried to delete the object via cli which does not work either

Expected Behavior

One should be able to at least delete broken items. I had a similar case before where i had items broken and was not able to delete them via web or cli. This is annoying as you have broken objects in director which propably even lead to broken configuration which cannot be deployed then.

Current Behavior

Director accepts other charsets but cannot handle them afterwards

Error shown is

SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (latin1_general_cs,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=', query was: SELECT ho.name1 AS hostname FROM icinga_hosts AS h
INNER JOIN icinga_objects AS ho ON ho.object_id = h.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1 WHERE (ho.name1 = 'US‑8‑150W-1') ORDER BY h.display_name COLLATE latin1_general_ci ASC

#0 /usr/share/icingaweb2/library/vendor/Zend/Db/Statement.php(297): Zend_Db_Statement_Pdo->_execute(Array)
#1 /usr/share/icingaweb2/library/vendor/Zend/Db/Adapter/Abstract.php(470): Zend_Db_Statement->execute(Array)
#2 /usr/share/icingaweb2/library/vendor/Zend/Db/Adapter/Pdo/Abstract.php(232): Zend_Db_Adapter_Abstract->query(Object(Zend_Db_Select), Array)
#3 /usr/share/icingaweb2/library/vendor/Zend/Db/Adapter/Abstract.php(816): Zend_Db_Adapter_Pdo_Abstract->query(Object(Zend_Db_Select), Array)
#4 /usr/share/php/Icinga/Data/Db/DbConnection.php(302): Zend_Db_Adapter_Abstract->fetchOne(Object(Zend_Db_Select))
#5 /usr/share/php/Icinga/Data/SimpleQuery.php(611): Icinga\Data\Db\DbConnection->fetchOne(Object(Icinga\Module\Monitoring\Backend\Ido\Query\HoststatusQuery))
#6 /usr/local/share/icingaweb2/modules/monitoring/library/Monitoring/DataView/DataView.php(632): Icinga\Data\SimpleQuery->fetchOne()
#7 /usr/local/share/icingaweb2/modules/director/library/Director/Monitoring.php(34): Icinga\Module\Monitoring\DataView\DataView->fetchOne()
#8 /usr/local/share/icingaweb2/modules/director/application/controllers/HostController.php(55): Icinga\Module\Director\Monitoring->hasHost('US\xE2\x80\x918\xE2\x80\x91150W-1')
#9 /usr/local/share/icingaweb2/modules/director/library/Director/Web/Controller/ObjectController.php(112): Icinga\Module\Director\Controllers\HostController->editAction()
#10 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(507): Icinga\Module\Director\Web\Controller\ObjectController->indexAction()
#11 /usr/share/php/Icinga/Web/Controller/Dispatcher.php(76): Zend_Controller_Action->dispatch('indexAction')
#12 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#13 /usr/share/php/Icinga/Application/Web.php(389): Zend_Controller_Front->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#14 /usr/share/php/Icinga/Application/webrouter.php(109): Icinga\Application\Web->dispatch()
#15 /usr/share/icingaweb2/public/index.php(4): require_once('/usr/share/php/...')
#16 {main}

Possible Solution

Validate input in the input fields.

Or which I think would be nice: Be able to delete items from the list view.

Steps to Reproduce (for bugs)

  1. Enter a non standard string in the hostname and save a host object

Context

I am setting up a new environment

Your Environment

Thomas-Gelf commented 7 years ago

Your problem sits in your IDO database. Please note that even when storing UTF8 data, the only safe way of creating/using the schema for a long time used to be latin1. Please do not ask why, i tried hard to change this - but failed for non-technical reasons. We'll get this right in IcingaDB, the upcoming IDO successor - but for now we're stick with what we have. Please search the icingaweb2 issue tracker for related issues, and configure your IDO DB resource in Icinga Web 2 being latin1.

Director bases itself on the monitoring module in this particular place, it doesn't run the queries by itself. For the 1.4 (next) branch I'll add a try/catch block silently discarding this error.

Thomas-Gelf commented 7 years ago

Pushed to next, will be part of 1.4.0. Still, you have to solve your problem elsewhere. Director will no longer fail here, but it cannot fix your problem.