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

Parameter Line in CMD/show in API returns string or array #7621

Open smutel opened 5 years ago

smutel 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

19.04.2

Operating System

CentOS Linux release 7.6.1810 (Core)

Browser used

Version: 67.0.2 (64 bits)

Additional environment details (AWS, VirtualBox, physical, etc.):

Inside VirtualBox, ovf from centreon website.

Description

When we would like to display the list of commands in centreon using the REST API, sometimes the parameter line is a string, sometimes the parameter line is an array. If the command line contains the character | (pipe), then the line parameter is an array. Otherwise it's a string.

Steps to Reproduce

  1. I logged in Centreon
  2. I created two commands:
    • One with name test1, any type and command line: test
    • Second one with name test2, any type and command line: test | test
  3. I got an auth token from the API
  4. I use the API with object CMD, action SHOW and argurment the name of the command above.

Describe the received result

I assume that env variable CENTREON_TOKEN contains the auth token to the API and CENTREON_URL contains the URL to centreon.

$ curl -s -H "centreon-auth-token:$CENTREON_TOKEN" -H "Content-Type: application/json" -d '{"action":"show", "object":"CMD", "values":"test1"}' "${CENTREON_URL}/centreon/api/index.php?action=action&object=centreon_clapi"
{"result":[{"id":"89","name":"test1","type":"notif","line":"test"}]}
$ curl -s -H "centreon-auth-token:$CENTREON_TOKEN" -H "Content-Type: application/json" -d '{"action":"show", "object":"CMD", "values":"test2"}' "${CENTREON_URL}/centreon/api/index.php?action=action&object=centreon_clapi"
{"result":[{"id":"90","name":"test2","type":"notif","line":["test","test"]}]}

Describe the expected result

$ curl -s -H "centreon-auth-token:$CENTREON_TOKEN" -H "Content-Type: application/json" -d '{"action":"show", "object":"CMD", "values":"test1"}' "${CENTREON_URL}/centreon/api/index.php?action=action&object=centreon_clapi"
{"result":[{"id":"89","name":"test1","type":"notif","line":"test"}]}
$ curl -s -H "centreon-auth-token:$CENTREON_TOKEN" -H "Content-Type: application/json" -d '{"action":"show", "object":"CMD", "values":"test2"}' "${CENTREON_URL}/centreon/api/index.php?action=action&object=centreon_clapi"
{"result":[{"id":"90","name":"test2","type":"notif","line":"test | test"}]}
smutel commented 5 years ago

The issue seems to be due to this piece of code. If I comment this code, it works correctly. But I don't know the side effect for the rest of the API ...

https://github.com/centreon/centreon/blob/9c7eabd32e7b3a9a10cf82093cfec19469fb4f0b/www/api/class/centreon_clapi.class.php#L202-L206