Icinga / icingaweb2-module-cube

Drill-down view for Icinga web 2 based on custom variables
GNU General Public License v2.0
45 stars 12 forks source link

Dimension slicing by custom data field names with certain characteristics cause failures or stacktrackes #62

Closed jwilliams-shadowsoft closed 2 years ago

jwilliams-shadowsoft commented 4 years ago

Describe the bug

With the advent of Director administrators can name custom Data Fields with a variety of characters. Users cannot use the entire variety of custom data field names that can be created as dimensions to slice Cubes.

Several unwritten rules must be followed in v1.1.1 for a Cube slicing operation to succeed and not cause a stack trace. The rules are:

  1. A custom data field name must start with a lower-case letter.
  2. A custom data field name cannot contain spaces.
  3. A custom data field name cannot contain any punctuation besides underscores.
  4. A custom data field name cannot contain upper-case letters.
  5. A custom data field name must be 31 characters or less.

The regex that matches a name with the characteristics is: [a-z]([a-z0-9_])*.

Several different failures or stacktraces will result based on violation of these rules:

Test Cases

All test cases begin with Reporting -> Cube -> + Add a dimension.

Test case Field name Workflow Result
F stringf Click cube name -> Click Modify Success
G string g Click cube name Failure: Got no such dimension
H string-h Click cube name -> Click Modify Success
I StringI Click cube name -> Click Modify Failure: Modify 0 hosts
J string_j Click cube name -> Click Modify Success

Result explanations

Success

Success of this test means that the Modify link was clicked and the Director Host modification form was presented.

Failure: Got no such dimension

This is an invalid error message in the test case (G), because the field does exist. When the title of the cube is clicked, the following is given in the right panel:

Got no such dimension: "string%20g"

#0 /usr/share/icingaweb2/modules/cube/library/Cube/Web/Controller.php(54): Icinga\Module\Cube\Cube->slice(String, String)
#1 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(507): Icinga\Module\Cube\Web\Controller->detailsAction()
#2 /usr/share/php/Icinga/Web/Controller/Dispatcher.php(76): Zend_Controller_Action->dispatch(String)
#3 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#4 /usr/share/php/Icinga/Application/Web.php(300): Zend_Controller_Front->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#5 /usr/share/php/Icinga/Application/webrouter.php(99): Icinga\Application\Web->dispatch()
#6 /usr/share/icingaweb2/public/index.php(4): require_once(String)
#7 {main}

Note that the error message is URL-encoded, perhaps this is why the comparsion to find the dimension failed.

Also please note that a better error message for a failed search would be "Dimension not found."

Failure: Modify 0 hosts

This is also a problem with the comparison in the search. Apparently the string to look for in the list of dimensions is lowercased before the search. When the title of the cube is clicked, the following is given in the right panel:

stringi = Igloodly Doodly Doo

Show hosts status         Modify 0 hosts

This shows all            This allows you to 
matching hosts and        modify properties for 
their current state in    all chosen hosts at
the monitoring module     once

Clearly the search string was lowercased before the search, since it was displayed that way. And yet the code believes the search succeeded, because it wants to let you modify the Hosts. But there are zero (0) of them.

If the Modify 0 hosts link is clicked:

Uncaught Error: Call to a member function hasConnection() on boolean in /usr/share/icingaweb2/modules/director/library/Director/Web/Form/DirectorObjectForm.php:132
Stack trace:
#0 /usr/share/icingaweb2/modules/director/application/forms/IcingaMultiEditForm.php(28): Icinga\Module\Director\Web\Form\DirectorObjectForm->object()
#1 /usr/share/icingaweb2/modules/director/library/Director/Web/Controller/ObjectsController.php(182): Icinga\Module\Director\Forms\IcingaMultiEditForm->setObjects(Array)
#2 /usr/share/icingaweb2/modules/director/library/Director/Web/Controller/ObjectsController.php(165): Icinga\Module\Director\Web\Controller\ObjectsController->commonForEdit()
#3 /usr/share/icingaweb2/modules/director/application/controllers/HostsController.php(37): Icinga\Module\Director\Web\Controller\ObjectsController->editAction()
#4 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(507): Icinga\Module\Director\Controllers\HostsController->editAction()
#5 /usr/share/php/Icinga/Web/Controller/Dispatcher.ph

#0 [internal function]: Icinga\Application\Web->Icinga\Application\{closure}()
#1 {main}

Recent fixes

These tests were previously conducted on v1.1.0 and there were stacktraces produced for test cases G and H. v1.1.1 fixed test case H, and produces an invalid error message for case G.

To Reproduce

  1. In Director, add the following Data Fields of Data Type String:
    • stringf (all lowercase)
    • string g (with a space)
    • string-h (with a dash)
    • StringI (mixed case)
    • string_j (all lowercase with an underscore)
  2. In Director, create a Host Template and add all fields created above.
  3. In Director, Create a Host using that template, setting values for the fields. (The exact value is not significant.)
  4. In Director, Deploy.
  5. Use the workflows above to reproduce the test cases.

Expected behavior

All given examples should work. All cases should present the correct list of Hosts for Director Modification.

Screenshots

Setup

Screen Shot 2020-07-15 at 8 04 48 PM

Success

Screen Shot 2020-07-15 at 8 06 18 PM Screen Shot 2020-07-15 at 8 06 38 PM

Failure: Got no such dimension

Screen Shot 2020-07-15 at 8 07 01 PM

Failure: Failure: Modify 0 hosts

Screen Shot 2020-07-15 at 8 07 35 PM Screen Shot 2020-07-15 at 8 07 52 PM

Your Environment

Additional context

There may be additional test cases I have not thought of.

Also, based on the limitations of column naming in MySQL, MariaDB and PostgreSQL, the maximum length of a custom data field that will succeed is 31 characters.

lippserd commented 4 years ago

ref/IP/26723