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 host getparam master (#5925)
Browse files Browse the repository at this point in the history
* fix(doc) doc for host get param #5783

* API: Add HOST getparam
  • Loading branch information
loiclau authored and Guillaume28 committed Nov 30, 2017
1 parent a61ceb4 commit 88014bb
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 2 deletions.
106 changes: 106 additions & 0 deletions doc/en/api/clapi/objects/hosts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand Down
107 changes: 107 additions & 0 deletions doc/fr/api/clapi/objects/hosts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
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";
}
94 changes: 93 additions & 1 deletion 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 @@ -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
*
Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 88014bb

Please sign in to comment.