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

API: Add HOST getparam #5783

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions lib/Centreon/Object/Media/Media.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/*
* Copyright 2005-2017 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
*
*/

require_once "Centreon/Object/Object.php";

/**
* Used for interacting with media
*
* @author Mathieu Parent
*/
class Centreon_Object_Media extends Centreon_Object
{
protected $table = "view_img";
protected $primaryKey = "img_id";
protected $uniqueLabelField = "img_path";
}
92 changes: 92 additions & 0 deletions www/class/centreon-clapi/centreonHost.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
require_once "Centreon/Object/Relation/Contact/Group/Host.php";
require_once "Centreon/Object/Relation/Host/Service.php";
require_once "Centreon/Object/Timezone/Timezone.php";
require_once "Centreon/Object/Media/Media.php";

/**
* Centreon Host objects
Expand Down Expand Up @@ -333,6 +334,97 @@ public function setinstance($parameters)
$relationObj->insert($instanceId, $hostId);
}

/**
* Get a parameter
*
* @param string $parameters
* @return void
* @throws CentreonClapiException
*/
public function getparam($parameters = null)
{
$params = explode($this->delim, $parameters);
if (count($params) < 2) {
throw new CentreonClapiException(self::MISSINGPARAMETER);
}
if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) {
$extended = false;
$field = $params[1];
switch ($params[1]) {
case "check_command":
$field = "command_command_id";
break;
case "check_command_arguments":
$field = "command_command_id_arg1";
break;
case "event_handler":
$field = "command_command_id2";
break;
case "event_handler_arguments":
$field = "command_command_id_arg2";
break;
case "check_period":
$field = "timeperiod_tp_id";
break;
case "notification_period":
$field = "timeperiod_tp_id2";
break;
case "notes":
case "notes_url":
case "action_url":
case "icon_image":
case "icon_image_alt":
case "vrml_image":
case "statusmap_image":
case "2d_coords":
case "3d_coords":
$extended = true;
break;
case self::HOST_LOCATION:
$field = 'host_location';
break;
default:
if (!preg_match("/^host_/", $params[1])) {
$field = "host_" . $params[1];
}
break;
}
if ($extended == false) {
$ret = $this->object->getParameters($objectId, $field);
$ret = $ret[$field];
} else {
$field = "ehi_" . $field;
$extended = new \Centreon_Object_Host_Extended();
$ret = $extended->getParameters($objectId, $field);
$ret = $ret[$field];
}
switch ($params[1]) {
Copy link
Contributor

@loiclau loiclau Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The switch is the same as that employed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. But this one is to convert parameter value if needed. Otherwise, the ->getParameters would be duplicated.

case "check_command":
case "event_handler":
$commandObject = new CentreonCommand();
$field = $commandObject->object->getUniqueLabelField();
$ret = $commandObject->object->getParameters($ret, $field);
$ret = $ret[$field];
break;
case "check_period":
case "notification_period":
$tpObj = new CentreonTimePeriod();
$field = $tpObj->object->getUniqueLabelField();
$ret = $tpObj->object->getParameters($ret, $field);
$ret = $ret[$field];
break;
case self::HOST_LOCATION:
$field = $this->timezoneObject->getUniqueLabelField();
$ret = $this->timezoneObject->getParameters($ret, $field);
$ret = $ret[$field];
break;
}
echo $ret . "\n";
} else {
throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]);
}
}

/**
* Set parameters
*
Expand Down
17 changes: 17 additions & 0 deletions www/class/centreon-clapi/centreonObject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,23 @@ public function del($objectName)
}
}

/**
* Get a parameter
*
* @param string $parameters
* @return void
* @throws CentreonClapiException
*/
public function getparam($parameters = null)
{
$params = explode($this->delim, $parameters);
if (count($params) < 2) {
throw new CentreonClapiException(self::MISSINGPARAMETER);
}
$p = $this->object->getParameters($params[0], $params[1]);
print $p[$params[1]] . "\n";
}

/**
* Set Param
*
Expand Down