diff --git a/lib/Centreon/Object/Instance/Instance.php b/lib/Centreon/Object/Instance/Instance.php index 0e45909149e4f47b89bbb2a60b13eef0f0a46288..bacfa8c901226dbb517942a7a91e9021d9e52de3 100644 --- a/lib/Centreon/Object/Instance/Instance.php +++ b/lib/Centreon/Object/Instance/Instance.php @@ -45,4 +45,16 @@ class Centreon_Object_Instance extends Centreon_Object protected $table = "nagios_server"; protected $primaryKey = "id"; protected $uniqueLabelField = "name"; + + public function getDefaultInstance() + { + $res = $this->db->query("SELECT `name` FROM `nagios_server` WHERE `is_default` = 1"); + if( $res->rowCount() == 0) { + $res = $this->db->query("SELECT `name` FROM `nagios_server` WHERE `localhost` = '1'"); + } + + $row = $res->fetch(); + return $row['name']; + } + } diff --git a/www/class/centreon-clapi/centreonHost.class.php b/www/class/centreon-clapi/centreonHost.class.php index e8a62ad376959d0b6dcba28b5d5af1be8e6b0d3c..e1f90c89dafda880f1c8d6aa4bfbc70f340350b1 100644 --- a/www/class/centreon-clapi/centreonHost.class.php +++ b/www/class/centreon-clapi/centreonHost.class.php @@ -257,7 +257,14 @@ class CentreonHost extends CentreonObject if ($instanceName) { $tmp = $instanceObject->getIdByParameter($instanceObject->getUniqueLabelField(), $instanceName); if (!count($tmp)) { - throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $instanceName); + $defaultInstanceName = $instanceObject->getDefaultInstance(); + $tmp = $instanceObject->getIdByParameter( + $instanceObject->getUniqueLabelField(), + $defaultInstanceName + ); + if (!count($tmp)) { + throw new CentreonClapiException(self::OBJECT_NOT_FOUND . " :" . $instanceName); + } } $instanceId = $tmp[0]; } else {