centreon / centreon-archived

Centreon is a network, system and application monitoring tool. Centreon is the only AIOps Platform Providing Holistic Visibility to Complex IT Workflows from Cloud to Edge.
https://www.centreon.com
GNU General Public License v2.0
574 stars 240 forks source link

[API REST] using sortType with state field on centreon_realtime_services does not actually sort by state #7750

Open thibaults-centreon opened 5 years ago

thibaults-centreon commented 5 years ago

BUG REPORT INFORMATION

Prerequisites

The opened issue, must be code related. GitHub is not meant for support. Feel free to check the CONTRIBUTING section for more details.

Versions

centreon-release-19.04-1.el7.centos.noarch centreon-web-19.04.3-1564057808.b9e6802b1.el7.centos.noarch

Operating System

CentOS7*

Browser used

Description

using sortType parameter with state field on centreon_realtime_services doesn't work, services are actually returned but not sorted by state. "current_state" has to be used instead of "state" as sortType parameter to get the services properly sorted.

Steps to Reproduce

http://127.0.0.1/centreon/api/index.php?object=centreon_realtime_services&action=list&sortType=state&fields=host_name,description,state => results sorted by service name

http://127.0.0.1/centreon/api/index.php?object=centreon_realtime_services&action=list&sortType=current_state&fields=host_name,description,state => results correctly sorted by status code

Additional relevant information (e.g. frequency, ...)

lpinsivy commented 5 years ago

You right the sources say:

        $tabOrder = array();
        $tabOrder["criticality_id"] = " ORDER BY criticality $q, h.name, s.description ";
        $tabOrder["host_name"] = " ORDER BY h.name $q, s.description ";
        $tabOrder["service_description"] = " ORDER BY s.description $q, h.name";
        $tabOrder["current_state"] = " ORDER BY s.state $q, h.name, s.description";
        $tabOrder["last_state_change"] = " ORDER BY s.last_state_change $q, h.name, s.description";
        $tabOrder["last_hard_state_change"] = " ORDER by s.last_hard_state_change $q, h.name, s.description";
        $tabOrder["last_check"] = " ORDER BY s.last_check $q, h.name, s.description";
        $tabOrder["current_attempt"] = " ORDER BY s.check_attempt $q, h.name, s.description";
        $tabOrder["output"] = " ORDER BY s.output $q, h.name, s.description";
        $tabOrder["default"] = " ORDER BY s.description $q, h.name";

You must use current_state instead of state