Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
feat(API) Add showinstance CLAPI command to Host (#7199)
Browse files Browse the repository at this point in the history
  • Loading branch information
loiclau authored and vhr committed Mar 13, 2019
1 parent f8b5070 commit a23a76a
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 2 deletions.
8 changes: 8 additions & 0 deletions doc/en/api/clapi/objects/hosts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ In order to set the instance from which a host will be monitored, use the **SETI

[root@centreon ~]# ./centreon -u admin -p centreon -o HOST -a setinstance -v "Centreon-Server;Poller 1"

Showinstance
-----------

To determine the instance from which a host will be monitored, use the **SHOWINSTANCE** action::

[root@centreon ~]# ./centreon -u admin -p centreon -o HOST -a showinstance -v "Centreon-Server"
id;name
2;Poller 1

Getmacro
--------
Expand Down
8 changes: 8 additions & 0 deletions doc/fr/api/clapi/objects/hosts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ In order to set the instance from which a host will be monitored, use the **SETI

[root@centreon ~]# ./centreon -u admin -p centreon -o HOST -a setinstance -v "Centreon-Server;Poller 1"

Showinstance
-----------

To determine the instance from which a host will be monitored, use the **SHOWINSTANCE** action::

[root@centreon ~]# ./centreon -u admin -p centreon -o HOST -a showinstance -v "Centreon-Server"
id;name
2;Poller 1

Getmacro
--------
Expand Down
82 changes: 80 additions & 2 deletions tests/rest_api/rest_api.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"info": {
"_postman_id": "5882d474-6c79-41b4-8fd8-2b1e1e999702",
"name": "Centreon Web Rest API",
"_postman_id": "a0f59ed8-0da0-4aa8-b270-774fcaa83146",
"name": "Centreon Web Rest API copy",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
Expand Down Expand Up @@ -25006,6 +25006,84 @@
},
"response": []
},
{
"name": "Showinstance",
"event": [
{
"listen": "test",
"script": {
"id": "d98aa955-00be-475b-88cd-b6eb878571f3",
"exec": [
"tests[\"Status code is 200\"] = responseCode.code === 200;",
"",
"var contentType = postman.getResponseHeader(\"Content-Type\");",
"tests[\"Content-Type is application/json\"] = contentType === \"application/json\";",
"",
"var jsonData = JSON.parse(responseBody);",
"var result= jsonData.result;",
"",
"var schema = {",
" \"$schema\": \"http://json-schema.org/draft-04/schema#\",",
" \"type\": \"array\",",
" \"items\": {",
" \"type\": \"object\",",
" \"properties\": {",
" \"id\": { \"type\": \"string\" },",
" \"name\": { \"type\": \"string\" }",
" },",
" \"additionalProperties\": false,",
" \"required \": [\"id\", \"name\"]",
" }",
"};",
"",
"tests[\"Validate schema\"] = tv4.validate(result, schema);",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "centreon-auth-token",
"value": "{{token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"action\":\"showinstance\",\n \"object\":\"host\",\n \"values\": \"{{host_name}}\"\n}"
},
"url": {
"raw": "http://{{url}}/centreon/api/index.php?action=action&object=centreon_clapi",
"protocol": "http",
"host": [
"{{url}}"
],
"path": [
"centreon",
"api",
"index.php"
],
"query": [
{
"key": "action",
"value": "action"
},
{
"key": "object",
"value": "centreon_clapi"
}
]
}
},
"response": []
},
{
"name": "Setmacro",
"event": [
Expand Down
35 changes: 35 additions & 0 deletions www/class/centreon-clapi/centreonHost.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,41 @@ public function del($objectName)
);
}

/**
* List instance (poller) for host
*
* @param string $parameters
* @throws CentreonClapiException
*/
public function showinstance($parameters)
{
$params = explode($this->delim, $parameters);
if ($parameters == '') {
throw new CentreonClapiException(self::MISSINGPARAMETER);
}
if (($hostId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) {
$relObj = new \Centreon_Object_Relation_Instance_Host();
$fields = array('id', 'name');
$elements = $relObj->getMergedParameters(
$fields,
array(),
-1,
0,
"host_name",
"ASC",
array('host_id' => $hostId),
'AND'
);

echo 'id' . $this->delim . 'name' . "\n";
foreach ($elements as $elem) {
echo $elem['id'] . $this->delim . $elem['name'] . "\n";
}
} else {
throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]);
}
}

/**
* Tie host to instance (poller)
*
Expand Down

0 comments on commit a23a76a

Please sign in to comment.