Skip to content

Commit

Permalink
Fix issue WEB-461 centreonConsole for global resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Toufik MECHOUET committed Jun 24, 2015
1 parent acdcac2 commit d96cf30
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 58 deletions.
2 changes: 0 additions & 2 deletions core/api/internal/BasicCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,6 @@ public function showAction($objectSlug, $fields = null, $linkedObject = '')
{
$repository = $this->repository;

//$objectSlug = $repository::getIdFromUnicity($this->parseObjectParams($objectSlug));

$aId = $repository::getListBySlugName($objectSlug[$this->objectName]);
if (count($aId) > 0) {
$objectSlug = $aId[0]['id'];
Expand Down
1 change: 1 addition & 0 deletions doc/en/user/object_management/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ The list of object commands is available with the following commandline :
businessactivity
trap
manufacturer
resource
100 changes: 100 additions & 0 deletions doc/en/user/object_management/resource.rst
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
54 changes: 54 additions & 0 deletions modules/CentreonConfigurationModule/commands/ResourceCommand.php
Original file line number Diff line number Diff line change
@@ -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 : [email protected]
*
*/
namespace CentreonConfiguration\Commands;

use Centreon\Api\Internal\BasicCrudCommand;

/**
*
*/
class ResourceCommand extends BasicCrudCommand
{
/**
*
* @var type
*/
public $objectName = 'resource';

public function __construct()
{
parent::__construct();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,15 @@ public function commandsForResourceAction()
{
parent::getRelations(static::$relationMap['resource_pollers']);
}

/**
* Create a new resource
*
* @method post
* @route /resource/add
*/
public function createAction()
{
parent::createAction();
}
}
103 changes: 54 additions & 49 deletions modules/CentreonConfigurationModule/install/forms/Resource.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -100,6 +95,6 @@ public static function create($givenParameters, $origin = "", $route = "", $vali
*/
public static function update($givenParameters, $origin = "", $route = "", $validate = true, $validateMandatory = true)
{
parent::update($givenParameters, "form", $route);
parent::update($givenParameters, $origin, $route);
}
}

0 comments on commit d96cf30

Please sign in to comment.