diff --git a/html/api/index.php b/html/api/index.php index 9d50de9..7d53c14 100644 --- a/html/api/index.php +++ b/html/api/index.php @@ -29,6 +29,7 @@ addRoute('post', '/getHost', 'getHost', 'operator'); +addRoute('post', '/getAllHostsByElement', 'getAllHostsByElement', 'operator'); addRoute('post', '/getContact', 'getContact', 'operator'); addRoute('post', '/getCommand', 'getCommand', 'operator'); addRoute('post', '/getHostGroup', 'getHostGroup', 'operator'); @@ -235,4 +236,4 @@ function addRoute($httpMethod, $routeName, $methodName, $right="admin"){ $app->run(); -?> \ No newline at end of file +?> diff --git a/include/ObjectManager.php b/include/ObjectManager.php index ee547b6..c549f7f 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -631,6 +631,30 @@ public function getHost( $hostName){ return "Host named ".$hostName." doesn't exist."; } } + /* LILAC - Get All Hosts by Element */ + public function getAllHostsByElement($element=" "){ + $element = trim($element); + $c = new Criteria(); + $c1 = $c->getNewCriterion(NagiosHostPeer::NAME, "%" . $element . "%", Criteria::LIKE); //search by name + $c2 = $c->getNewCriterion(NagiosHostPeer::ALIAS, "%" . $element . "%", Criteria::LIKE); //search by alias + $c3 = $c->getNewCriterion(NagiosHostPeer::ADDRESS, "%" . $element . "%", Criteria::LIKE); //search by ip address + $c2->addOr($c3); + $c1->addOr($c2); + $c->add($c1); + $c->setIgnoreCase(true); + $c->addAscendingOrderByColumn(NagiosHostPeer::NAME); + $hosts = NagiosHostPeer::doSelect($c); //select all hosts if exist + $result = array(); + foreach($hosts as $host) { + $answer = $host->toArray(); + array_push($result,$answer); + } + if (!$result){ + return "No host with this element: $element."; + }else{ + return $result; + } + } /* LILAC - Get Hosts by template name */ public function getHostsBytemplate( $templateHostName){ $nhtp = new NagiosHostTemplatePeer;