From 88014bb1b3ee4c5eab569d41611b633900bbdaba Mon Sep 17 00:00:00 2001 From: loiclau Date: Thu, 30 Nov 2017 11:17:10 +0100 Subject: [PATCH] feat(api) add host getparam master (#5925) * fix(doc) doc for host get param #5783 * API: Add HOST getparam --- doc/en/api/clapi/objects/hosts.rst | 106 +++++++++++++++++ doc/fr/api/clapi/objects/hosts.rst | 107 ++++++++++++++++++ lib/Centreon/Object/Media/Media.php | 48 ++++++++ .../centreon-clapi/centreonHost.class.php | 94 ++++++++++++++- .../centreon-clapi/centreonObject.class.php | 20 +++- 5 files changed, 373 insertions(+), 2 deletions(-) create mode 100644 lib/Centreon/Object/Media/Media.php diff --git a/doc/en/api/clapi/objects/hosts.rst b/doc/en/api/clapi/objects/hosts.rst index 7b6097559dc..813dba42987 100644 --- a/doc/en/api/clapi/objects/hosts.rst +++ b/doc/en/api/clapi/objects/hosts.rst @@ -196,6 +196,112 @@ timezone Timezone .. note:: You need to generate your configuration file and restart monitoring engine in order to apply changes. +Getparam +-------- + +In order to get specific parameters on a host configuration, use the **GETPARAM** action:: + + [root@centreon ~]# ./centreon -u admin -p centreon -o HOST -a getparam -v "test;alias" + test + [root@centreon ~]# ./centreon -u admin -p centreon -o HOST -a setparam -v "test;timezone" + Europe/Berlin + +You may edit the following parameters: + +==================================== ================================================================================= +Parameter Description +==================================== ================================================================================= +2d_coords 2D coordinates (used by statusmap) + +3d_coords 3D coordinates (used by statusmap) + +action_url Action URL + +activate Whether or not host is enabled + +active_checks_enabled Whether or not active checks are enabled + +address Host IP Address + +alias Alias + +check_command Check command + +check_command_arguments Check command arguments + +check_interval Normal check interval + +check_freshness Enables check freshness + +check_period Check period + +contact_additive_inheritance Enables contact additive inheritance + +cg_additive_inheritance Enables contactgroup additive inheritance + +event_handler Event handler command + +event_handler_arguments Event handler command arguments + +event_handler_enabled Whether or not event handler is enabled + +first_notification_delay First notification delay (in seconds) + +flap_detection_enabled Whether or not flap detection is enabled + +flap_detection_options Flap detection options 'o' for Up, 'd' for Down, 'u' for Unreachable + +host_high_flap_threshold High flap threshold + +host_low_flap_threshold Low flap threshold + +icon_image Icon image + +icon_image_alt Icon image text + +max_check_attempts Maximum number of attempt before a HARD state is declared + +name Host name + +notes Notes + +notes_url Notes URL + +notifications_enabled Whether or not notification is enabled + +notification_interval Notification interval + +notification_options Notification options + +notification_period Notification period + +recovery_notification_delay Recovery notification delay + +obsess_over_host Whether or not obsess over host option is enabled + +passive_checks_enabled Whether or not passive checks are enabled + +process_perf_data Process performance data command + +retain_nonstatus_information Whether or not there is non-status retention + +retain_status_information Whether or not there is status retention + +retry_check_interval Retry check interval + +snmp_community Snmp Community + +snmp_version Snmp version + +stalking_options Comma separated options: 'o' for OK, 'd' for Down, 'u' for Unreachable + +statusmap_image Status map image (used by statusmap + +host_notification_options Notification options (d,u,r,f,s) + +timezone Timezone +==================================== ================================================================================= + Setinstance ----------- diff --git a/doc/fr/api/clapi/objects/hosts.rst b/doc/fr/api/clapi/objects/hosts.rst index 685165ddbd7..673cfa1b0e9 100644 --- a/doc/fr/api/clapi/objects/hosts.rst +++ b/doc/fr/api/clapi/objects/hosts.rst @@ -193,6 +193,113 @@ timezone Timezone ==================================== ================================================================================= +Getparam +-------- + +In order to get specific parameters on a host configuration, use the **GETPARAM** action:: + + [root@centreon ~]# ./centreon -u admin -p centreon -o HOST -a getparam -v "test;alias" + test + [root@centreon ~]# ./centreon -u admin -p centreon -o HOST -a setparam -v "test;timezone" + Europe/Berlin + +You may edit the following parameters: + +==================================== ================================================================================= +Parameter Description +==================================== ================================================================================= +2d_coords 2D coordinates (used by statusmap) + +3d_coords 3D coordinates (used by statusmap) + +action_url Action URL + +activate Whether or not host is enabled + +active_checks_enabled Whether or not active checks are enabled + +address Host IP Address + +alias Alias + +check_command Check command + +check_command_arguments Check command arguments + +check_interval Normal check interval + +check_freshness Enables check freshness + +check_period Check period + +contact_additive_inheritance Enables contact additive inheritance + +cg_additive_inheritance Enables contactgroup additive inheritance + +event_handler Event handler command + +event_handler_arguments Event handler command arguments + +event_handler_enabled Whether or not event handler is enabled + +first_notification_delay First notification delay (in seconds) + +flap_detection_enabled Whether or not flap detection is enabled + +flap_detection_options Flap detection options 'o' for Up, 'd' for Down, 'u' for Unreachable + +host_high_flap_threshold High flap threshold + +host_low_flap_threshold Low flap threshold + +icon_image Icon image + +icon_image_alt Icon image text + +max_check_attempts Maximum number of attempt before a HARD state is declared + +name Host name + +notes Notes + +notes_url Notes URL + +notifications_enabled Whether or not notification is enabled + +notification_interval Notification interval + +notification_options Notification options + +notification_period Notification period + +recovery_notification_delay Recovery notification delay + +obsess_over_host Whether or not obsess over host option is enabled + +passive_checks_enabled Whether or not passive checks are enabled + +process_perf_data Process performance data command + +retain_nonstatus_information Whether or not there is non-status retention + +retain_status_information Whether or not there is status retention + +retry_check_interval Retry check interval + +snmp_community Snmp Community + +snmp_version Snmp version + +stalking_options Comma separated options: 'o' for OK, 'd' for Down, 'u' for Unreachable + +statusmap_image Status map image (used by statusmap + +host_notification_options Notification options (d,u,r,f,s) + +timezone Timezone +==================================== ================================================================================= + + .. note:: You need to generate your configuration file and restart monitoring engine in order to apply changes. diff --git a/lib/Centreon/Object/Media/Media.php b/lib/Centreon/Object/Media/Media.php new file mode 100644 index 00000000000..1d02e82576a --- /dev/null +++ b/lib/Centreon/Object/Media/Media.php @@ -0,0 +1,48 @@ +. + * + * 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"; +} diff --git a/www/class/centreon-clapi/centreonHost.class.php b/www/class/centreon-clapi/centreonHost.class.php index c9071c55988..5593fab5553 100644 --- a/www/class/centreon-clapi/centreonHost.class.php +++ b/www/class/centreon-clapi/centreonHost.class.php @@ -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 @@ -338,6 +339,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($this->dependencyInjector); + $ret = $extended->getParameters($objectId, $field); + $ret = $ret[$field]; + } + switch ($params[1]) { + case "check_command": + case "event_handler": + $commandObject = new CentreonCommand($this->dependencyInjector); + $field = $commandObject->object->getUniqueLabelField(); + $ret = $commandObject->object->getParameters($ret, $field); + $ret = $ret[$field]; + break; + case "check_period": + case "notification_period": + $tpObj = new CentreonTimePeriod($this->dependencyInjector); + $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 * @@ -918,7 +1010,7 @@ protected function getHostListByParent(&$elements) $parents = $parentShip[$hostId]; $parentExported = true; foreach ($parents as $parentId) { - if(!in_array($parentId, $sortedHosts)){ + if (!in_array($parentId, $sortedHosts)) { $parentExported = false; break; } diff --git a/www/class/centreon-clapi/centreonObject.class.php b/www/class/centreon-clapi/centreonObject.class.php index 7f42fcf836e..576b957cda3 100644 --- a/www/class/centreon-clapi/centreonObject.class.php +++ b/www/class/centreon-clapi/centreonObject.class.php @@ -299,11 +299,29 @@ 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 * - * @param int $objectId + * @param $objectId * @param array $params + * @throws CentreonClapiException */ public function setparam($objectId, $params = array()) {