diff --git a/core/api/internal/BasicCrud.php b/core/api/internal/BasicCrud.php index 02444e86f013eb11dacd5ed620a1ba69facff135..756b7a8cf4884ca44529e16ef2deb428a36c6485 100644 --- a/core/api/internal/BasicCrud.php +++ b/core/api/internal/BasicCrud.php @@ -455,8 +455,6 @@ class BasicCrud extends AbstractCommand { $repository = $this->repository; - //$objectSlug = $repository::getIdFromUnicity($this->parseObjectParams($objectSlug)); - $aId = $repository::getListBySlugName($objectSlug[$this->objectName]); if (count($aId) > 0) { $objectSlug = $aId[0]['id']; diff --git a/doc/en/user/object_management/index.rst b/doc/en/user/object_management/index.rst index e91c974056de8067049f852a06e6dfa82cffe03b..dc7ab0b49285aa266f344dbb4decb9b4094b0fe6 100644 --- a/doc/en/user/object_management/index.rst +++ b/doc/en/user/object_management/index.rst @@ -28,3 +28,4 @@ The list of object commands is available with the following commandline : businessactivity trap manufacturer + resource diff --git a/doc/en/user/object_management/resource.rst b/doc/en/user/object_management/resource.rst new file mode 100644 index 0000000000000000000000000000000000000000..41357e00a648617096c14400cbcf1196d2bb2339 --- /dev/null +++ b/doc/en/user/object_management/resource.rst @@ -0,0 +1,100 @@ +Resource +======== + +Overview +-------- + +Object name: **centreon-configuration:Resource** + +Available parameters are the following: + +=================== =========================== +Parameter Description +=================== =========================== +*--resource-name** Resource name + +--resource-line Resource description + +--resource-pollers Slug name of poller + +--resource-comment Resource comment + +--resource-activate Enable (0 or 1) + +=================== =========================== + +List +---- + +In order to list resource, use **list** action:: + + ./centreonConsole centreon-configuration:Resource:list + id;name;slug;line;activate;comment;organization;pollers + 1;command;command;polklfd;1;dfdfdfdf;1;central + 2;switch;switch;ma ligne;0;rere fdfd;1;central + 10;resource1;resource1;;;rere fdfd;1;central + 14;$USER1$;user1-2;$1 dfdf/lk $5;1;rere fdfd;1;central + + + +Columns are the following: + +================== =========================== +Column Description +================== =========================== +id Resource id + +name Resource name + +slug Slug of resource + +line Resource description + +comment Comment of the resource + +activate Enable (0 or 1) + +organization Organization + +poller Identifiant of poller + +================== =========================== + +Show +---- + +In order to show a resource, use **show** action:: + + ./centreonConsole centreon-configuration:Resource:show --resource "switch" + id: 13 + name: $USER1$ + resource slug: user1 + resource line: $1 dfdf/lk $5 + resource comment: rere fdfd + resource activate: 1 + organization: 1 + poller: 1 + +Create +------ + +In order to create a resource, use **create** action:: + + ./centreonConsole centreon-configuration:Resource:create --resource-name "$USER1$" --resource-activate 1 --resource-pollers 'central' --resource-comment 'comment' --resource-line '/usr/lib/nagios/plugins' + Object successfully created + +Update +------ + +In order to update a resource, use **update** action:: + + ./centreonConsole centreon-configuration:Resource:update --resource 'user1' --resource-name "$USER1$" --resource-activate 1 --resource-pollers 'central' --resource-comment 'comment' --resource-line '/usr/lib/nagios/plugins' + Object successfully updated + +Delete +------ + +In order to delete a resource, use **delete** action:: + + ./centreonConsole centreon-configuration:Resource:delete --resource "linkDown" + Object successfully deleted diff --git a/modules/CentreonConfigurationModule/api/internal/resourceManifest.json b/modules/CentreonConfigurationModule/api/internal/resourceManifest.json new file mode 100644 index 0000000000000000000000000000000000000000..57201a6945dd9df08dd18a8bae2f8164a169847c --- /dev/null +++ b/modules/CentreonConfigurationModule/api/internal/resourceManifest.json @@ -0,0 +1,81 @@ +{ + "liteAttributesSet" : "resource_id,resource_name,resource_slug,resource_line,resource_activate,resource_comment,pollers,organization_id", + "repository" : "\\CentreonConfiguration\\Repository\\ResourceRepository", + "objectBaseUrl" : "resource", + "objectClass" : "\\CentreonConfiguration\\Models\\Resource", + "attributesMap" : { + "id" : "resource_id", + "name" : "resource_name", + "slug" : "resource_slug", + "line" : "resource_line", + "activate" : "resource_activate", + "comment" : "resource_comment", + "pollers" : "name", + "organization" : "organization_id" + }, + "externalAttributeSet" : [ + { + "type": "pollers", + "fields": "name", + "link": "relation", + "objectClass": "resource_pollers", + "group": false + }, + { + "type": "resource_pollers", + "fields": "id,slug", + "message": "The poller is not in database", + "link": "simple", + "objectClass": "\\CentreonConfiguration\\Models\\Poller", + "group": false + } + ], + "relationMap" : { + "resource_pollers" : "\\CentreonConfiguration\\Models\\Relation\\Resource\\Poller" + }, + "options" : { + "showAction" : { + "resource" : { + "functionParams" : "object", + "help": "The resource", + "type": "string", + "toTransform" : "resource", + "multiple" : false, + "required" : true + } + }, + "createAction" : { + + }, + "updateAction" : { + "resource" : { + "functionParams" : "object", + "help": "The resource", + "type": "string", + "toTransform" : "resource", + "multiple" : false, + "required" : true + } + }, + "deleteAction" : { + "resource" : { + "functionParams" : "object", + "help": "The resource", + "type": "string", + "toTransform" : "resource", + "multiple" : false, + "required" : true + } + }, + "duplicateAction" : { + "resource" : { + "functionParams" : "object", + "help": "The resource", + "type": "string", + "toTransform" : "resource", + "multiple" : false, + "required" : true + } + } + } +} diff --git a/modules/CentreonConfigurationModule/commands/ResourceCommand.php b/modules/CentreonConfigurationModule/commands/ResourceCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..7ac125f4ae9cb248a05872ff76155eab95cf0191 --- /dev/null +++ b/modules/CentreonConfigurationModule/commands/ResourceCommand.php @@ -0,0 +1,54 @@ +<?php +/* + * Copyright 2005-2015 CENTREON + * Centreon is developped by : Julien Mathis and Romain Le Merlus under + * GPL Licence 2.0. + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation ; either version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, see <http://www.gnu.org/licenses>. + * + * Linking this program statically or dynamically with other modules is making a + * combined work based on this program. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this program give CENTREON + * permission to link this program with independent modules to produce an executable, + * regardless of the license terms of these independent modules, and to copy and + * distribute the resulting executable under terms of CENTREON choice, provided that + * CENTREON also meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module which is not + * derived from this program. If you modify this program, you may extend this + * exception to your version of the program, but you are not obliged to do so. If you + * do not wish to do so, delete this exception statement from your version. + * + * For more information : contact@centreon.com + * + */ +namespace CentreonConfiguration\Commands; + +use Centreon\Api\Internal\BasicCrudCommand; + +/** + * + */ +class ResourceCommand extends BasicCrudCommand +{ + /** + * + * @var type + */ + public $objectName = 'resource'; + + public function __construct() + { + parent::__construct(); + } +} diff --git a/modules/CentreonConfigurationModule/controllers/ResourceController.php b/modules/CentreonConfigurationModule/controllers/ResourceController.php index b45bd613c5a7a2b1322f5bd97291ff15f6a61516..b275ff204a6b28a5a151df3d8547f9e389703e01 100644 --- a/modules/CentreonConfigurationModule/controllers/ResourceController.php +++ b/modules/CentreonConfigurationModule/controllers/ResourceController.php @@ -62,4 +62,15 @@ class ResourceController extends FormController { parent::getRelations(static::$relationMap['resource_pollers']); } + + /** + * Create a new resource + * + * @method post + * @route /resource/add + */ + public function createAction() + { + parent::createAction(); + } } diff --git a/modules/CentreonConfigurationModule/install/forms/Resource.xml b/modules/CentreonConfigurationModule/install/forms/Resource.xml index 450457061fed0ac74036a6ed763a523e955860ac..d7ad31e59ad774cb6e0c9ce1904309aad72a1295 100644 --- a/modules/CentreonConfigurationModule/install/forms/Resource.xml +++ b/modules/CentreonConfigurationModule/install/forms/Resource.xml @@ -1,55 +1,60 @@ <?xml version="1.0" encoding="UTF-8"?> <forms> - <form name="resource_form"> - <route>/centreon-configuration/resource/update</route> - <redirect>1</redirect> - <redirect_route>/centreon-configuration/resource</redirect_route> - <section name="General"> - <block name="General information"> - <field name="resource_name" label="Name" default_value="" advanced="0" type="text" parent_field="" mandatory="1"> - <validators> - <validator rules="remote" serverside="centreon-main.unique" /> - </validators> - <help>Name which will be used for identifying the resource.</help> + <form name="resource_form"> + <route>/centreon-configuration/resource/update</route> + <redirect>1</redirect> + <redirect_route>/centreon-configuration/resource</redirect_route> + <section name="General"> + <block name="General information"> + <field name="resource_name" label="Name" default_value="" advanced="0" type="text" parent_field="" mandatory="1"> + <validators> + <validator rules="remote" serverside="centreon-main.unique" /> + </validators> + <help>Name which will be used for identifying the resource.</help> </field> - <field name="resource_line" label="MACRO Expression" default_value="" advanced="0" type="text" parent_field="" mandatory="0"> + <field name="resource_line" label="MACRO Expression" default_value="" advanced="0" type="text" parent_field="" mandatory="0"> <help>A short description of the resource.</help> </field> - <field name="resource_pollers" label="Linked instances" default_value="" advanced="0" type="select" parent_field="" mandatory="0"> - <attributes> - <object_type>object</object_type> - <defaultValuesRoute>/centreon-configuration/poller/formlist</defaultValuesRoute> - <listValuesRoute>/centreon-configuration/resource/[i:id]/poller</listValuesRoute> - <multiple>true</multiple> - <ordered>false</ordered> - </attributes> - <help>This is the list of all pollers using this resource.</help> - </field> - <field name="resource_comment" label="Comment" default_value="" advanced="0" type="textarea" parent_field="" mandatory="0"> - <help>This will be executed by Centreon Engine, note that this line contains macros that will be replaced before execution. e.g: centreon_resource_perl.</help> - </field> - <field name="resource_activate" label="Status" default_value="1" advanced="0" type="radio" parent_field="" mandatory="1"> - <attributes> - <choices> - <Enabled>1</Enabled> - <Disabled>0</Disabled> - </choices> - </attributes> - <help>Whether or not the resource is enabled.</help> - </field> - </block> - </section> - </form> - <wizard name="add_resource"> - <route>/centreon-configuration/resource/add</route> - <step name="General"> - <field name="resource_name" mandatory="1"></field> - <field name="resource_line" mandatory="1"></field> - <field name="resource_comment" mandatory="0"></field> - <field name="resource_activate" mandatory="1"></field> - </step> - <step name="Relation"> - <field name="resource_pollers" mandatory="0"></field> - </step> - </wizard> + <field name="resource_pollers" label="Linked instances" default_value="" advanced="0" type="select" parent_field="" mandatory="0"> + <attributes> + <object_type>object</object_type> + <defaultValuesRoute>/centreon-configuration/poller/formlist</defaultValuesRoute> + <listValuesRoute>/centreon-configuration/resource/[i:id]/poller</listValuesRoute> + <multiple>true</multiple> + <ordered>false</ordered> + </attributes> + <help>This is the list of all pollers using this resource.</help> + </field> + <field name="resource_comment" label="Comment" default_value="" advanced="0" type="textarea" parent_field="" mandatory="0"> + <help>Comment of the resource.</help> + </field> + <field name="resource_activate" label="Status" default_value="1" advanced="0" type="radio" parent_field="" mandatory="1"> + <attributes> + <choices> + <Enabled>1</Enabled> + <Disabled>0</Disabled> + </choices> + </attributes> + <help>Whether or not the resource is enabled.</help> + <validators> + <validator rules="remote" serverside="core.AuthorizedValues"> + <argument name="values">0,1</argument> + </validator> + </validators> + </field> + </block> + </section> + </form> + <wizard name="add_resource"> + <route>/centreon-configuration/resource/add</route> + <step name="General"> + <field name="resource_name" mandatory="1"></field> + <field name="resource_line" mandatory="1"></field> + <field name="resource_comment" mandatory="0"></field> + <field name="resource_activate" mandatory="1"></field> + </step> + <step name="Relation"> + <field name="resource_pollers" mandatory="0"></field> + </step> + </wizard> </forms> diff --git a/modules/CentreonConfigurationModule/repositories/ResourceRepository.php b/modules/CentreonConfigurationModule/repositories/ResourceRepository.php index 93fb1fbd02c88699034f101cd4e3901eec25aec0..2bad6e362bf450894969b7e4f932be33bbfb6f63 100644 --- a/modules/CentreonConfigurationModule/repositories/ResourceRepository.php +++ b/modules/CentreonConfigurationModule/repositories/ResourceRepository.php @@ -82,12 +82,7 @@ class ResourceRepository extends \CentreonConfiguration\Repository\Repository public static function create($givenParameters, $origin = "", $route = "", $validate = true, $validateMandatory = true) { - /* - if ($validate) { - self::validateForm($givenParameters, $origin, $route, $validateMandatory); - } - */ - parent::create($givenParameters, "wizard", $route); + parent::create($givenParameters, $origin, $route); } /** @@ -100,6 +95,6 @@ class ResourceRepository extends \CentreonConfiguration\Repository\Repository */ public static function update($givenParameters, $origin = "", $route = "", $validate = true, $validateMandatory = true) { - parent::update($givenParameters, "form", $route); + parent::update($givenParameters, $origin, $route); } }