From 05e11bf19d15c36e7ce34f775ee1c3f0ee00d4c3 Mon Sep 17 00:00:00 2001 From: SAADOUNE Chamseddine Date: Tue, 17 Sep 2019 17:29:20 +0200 Subject: [PATCH 1/4] Add getAllHostsByElement --- html/api/index.php | 3 ++- include/ObjectManager.php | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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..48ba6ad 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -631,6 +631,31 @@ public function getHost( $hostName){ return "Host named ".$hostName." doesn't exist."; } } + /* LILAC - Get All Hosts by Element */ + public function getAllHostsByElement($element){ + $element = trim($element); + $nhp = new NagiosHostPeer(); + $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.\n"; + }else{ + return $result; + } + } /* LILAC - Get Hosts by template name */ public function getHostsBytemplate( $templateHostName){ $nhtp = new NagiosHostTemplatePeer; From 02a9d57a60d86da2903e5f6e26c22aae57f472c8 Mon Sep 17 00:00:00 2001 From: ChamMach Date: Tue, 17 Sep 2019 19:47:13 +0200 Subject: [PATCH 2/4] Update ObjectManager.php Minor modifications --- include/ObjectManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index 48ba6ad..5b43d3d 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -644,14 +644,14 @@ public function getAllHostsByElement($element){ $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosHostPeer::NAME); - $hosts = NagiosHostPeer::doSelect($c); #select all hosts if exist + $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.\n"; + return "No host with this element: $element."; }else{ return $result; } From 13b89c54000be93c69c5ed2c1f3e23f364657be9 Mon Sep 17 00:00:00 2001 From: ChamMach Date: Tue, 17 Sep 2019 22:06:42 +0200 Subject: [PATCH 3/4] getAllHostsByElement: deletion of one variable Minor modification : deletion of one useless variable --- include/ObjectManager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index 5b43d3d..d9c054c 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -634,7 +634,6 @@ public function getHost( $hostName){ /* LILAC - Get All Hosts by Element */ public function getAllHostsByElement($element){ $element = trim($element); - $nhp = new NagiosHostPeer(); $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 From 18c811b7d094b5f9abd2aaf0172e8adc0f99a92c Mon Sep 17 00:00:00 2001 From: jeremyH Date: Mon, 28 Oct 2019 10:29:23 +0100 Subject: [PATCH 4/4] Allow no argument Allow no argument to get all host --- include/ObjectManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index d9c054c..c549f7f 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -632,7 +632,7 @@ public function getHost( $hostName){ } } /* LILAC - Get All Hosts by Element */ - public function getAllHostsByElement($element){ + public function getAllHostsByElement($element=" "){ $element = trim($element); $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosHostPeer::NAME, "%" . $element . "%", Criteria::LIKE); //search by name