From 29d2e90ce6bc90ba5d4b841d6f348c70fc94fe7b Mon Sep 17 00:00:00 2001 From: Jeremy Hoarau Date: Mon, 6 Jan 2020 15:37:16 +0100 Subject: [PATCH 01/14] Add functionnality to add and delete parent/child relationship --- html/api/index.php | 2 + include/ObjectManager.php | 108 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/html/api/index.php b/html/api/index.php index 9d50de9..0024952 100644 --- a/html/api/index.php +++ b/html/api/index.php @@ -58,6 +58,7 @@ addRoute('post', '/createServiceToHostTemplate', 'createServiceToHostTemplate'); addRoute('post', '/addEventBroker', 'addEventBroker'); +addRoute('post', '/addParentToHost', 'addParentToHost'); addRoute('post', '/addContactToHost', 'addContactToHost'); addRoute('post', '/addHostGroupToHost', 'addHostGroupToHost'); addRoute('post', '/addContactGroupToHost', 'addContactGroupToHost'); @@ -112,6 +113,7 @@ addRoute('post', '/deleteServiceGroup', 'deleteServiceGroup'); addRoute('post', '/deleteHostTemplate', 'deleteHostTemplate'); addRoute('post', '/deleteHostDowntime', 'deleteHostDowntime'); +addRoute('post', '/deleteParentToHost', 'deleteParentToHost'); addRoute('post', '/deleteContactToHost', 'deleteContactToHost'); addRoute('post', '/deleteServiceTemplate', 'deleteServiceTemplate'); addRoute('post', '/deleteHostGroupToHost', 'deleteHostGroupToHost'); diff --git a/include/ObjectManager.php b/include/ObjectManager.php index ee547b6..c06633b 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -944,6 +944,63 @@ public function getResources(){ } ########################################## CREATE + + /* LILAC - add kinship link */ + public function addParentToHost($parentName, $childName, $exportConfiguration=FALSE){ + + $error = ""; + $success = ""; + $code=0; + + try{ + + // Wants to add a parent + $nhp = new NagiosHostPeer; + // Find host + $parentHost = $nhp->getByName($parentName); + if(!$parentHost) { + $code=1; + $error .= "Parent Host $parentName does not exists\n"; + } + + $childHost = $nhp->getByName($childName); + if(!$childHost) { + $code=1; + $error .= "Child Host $childName does not exists\n"; + } + + if($code==0){ + $c = new Criteria(); + $c->add(NagiosHostParentPeer::CHILD_HOST , $childHost->getId()); + $c->add(NagiosHostParentPeer::PARENT_HOST, $parentHost->getId()); + $parentRelationship = NagiosHostParentPeer::doSelectOne($c); + if($parentRelationship) { + $code=1; + $error .= "That parent relationship already exist.\n"; + }else { + $tempParent = new NagiosHostParent(); + $tempParent->setChildHost($childHost->getId()); + $tempParent->setParentHost($parentHost->getId()); + $tempParent->save(); + $success .= "Parent added"; + } + + if( $exportConfiguration == TRUE ) + $this->exportConfigurationToNagios($error, $success); + + } + + }catch(Exception $e) { + $code=1; + $error .= $e->getMessage(); + } + + $logs = $this->getLogs($error, $success); + + return array("code"=>$code,"description"=>$logs); + } + + /* LILAC - create contact */ public function createContact($contactName, $contactAlias="description", $contactMail, $contactPager="", $contactGroup="",$serviceNotificationCommand="notify-by-email-service",$hostNotificationCommand="notify-by-email-host", $options=NULL, $exportConfiguration = FALSE ){ $error = ""; @@ -4171,6 +4228,57 @@ public function modifyNagiosMainConfiguration($requestConf=NULL, $exportConfigur } ########################################## DELETE +/* LILAC - delete kinship link */ +public function deleteParentToHost($parentName, $childName, $exportConfiguration=FALSE){ + + $error = ""; + $success = ""; + $code=0; + + try{ + + // Wants to add a parent + $nhp = new NagiosHostPeer; + // Find host + $parentHost = $nhp->getByName($parentName); + if(!$parentHost) { + $code=1; + $error .= "Parent Host $parentName does not exists\n"; + } + + $childHost = $nhp->getByName($childName); + if(!$childHost) { + $code=1; + $error .= "Child Host $childName does not exists\n"; + } + + if($code==0){ + $c = new Criteria(); + $c->add(NagiosHostParentPeer::CHILD_HOST , $childHost->getId()); + $c->add(NagiosHostParentPeer::PARENT_HOST, $parentHost->getId()); + $parentRelationship = NagiosHostParentPeer::doSelectOne($c); + if($parentRelationship) { + $parentRelationship->delete(); + $success .= "That parent relationship been deleted.\n"; + }else { + $code = 1; + $error.= "That parent relationship does not exist yet.\n"; + } + + if( $exportConfiguration == TRUE ) + $this->exportConfigurationToNagios($error, $success); + + } + + }catch(Exception $e) { + $code=1; + $error .= $e->getMessage(); + } + + $logs = $this->getLogs($error, $success); + + return array("code"=>$code,"description"=>$logs); +} /* LILAC - delete host Downtimes */ public function deleteHostDowntime($idDowntime){ $error = ""; From 1b5b8f44597ee749ccd1d39706fc6cf157c76cb8 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Wed, 5 Feb 2020 11:18:41 +0100 Subject: [PATCH 02/14] Ajout de la route listHosts --- html/api/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/html/api/index.php b/html/api/index.php index 0024952..651d147 100644 --- a/html/api/index.php +++ b/html/api/index.php @@ -153,6 +153,7 @@ addRoute('post', '/listNagiosStates', 'listNagiosStates', 'readonly'); addRoute('post', '/listNagiosObjects', 'listNagiosObjects', 'readonly'); addRoute('post', '/listNagiosBackends', 'listNagiosBackends', 'readonly'); +addRoute('post', '/listHosts', 'listHosts', 'readonly'); //============================================================================== //eonweb @@ -237,4 +238,4 @@ function addRoute($httpMethod, $routeName, $methodName, $right="admin"){ $app->run(); -?> \ No newline at end of file +?> From 4c8e51b420694a307b0259a3b54a32ec5364e469 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Wed, 5 Feb 2020 11:27:45 +0100 Subject: [PATCH 03/14] essai fonction listHosts --- include/ObjectManager.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index c06633b..40767c1 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -602,9 +602,8 @@ public function modifyNotifierMethod($method_name, $method_type,$new_method_name /* LILAC - List Hosts */ public function listHosts( $hostName = false, $hostTemplate = false ){ - - return true; - + return listNagiosObjects("hosts"); + //return true; } ########################################## GET From d050cb232e5420888f07666e101d3f91f3d7864a Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Wed, 5 Feb 2020 11:29:31 +0100 Subject: [PATCH 04/14] test --- include/ObjectManager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index 40767c1..f889b39 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -602,7 +602,8 @@ public function modifyNotifierMethod($method_name, $method_type,$new_method_name /* LILAC - List Hosts */ public function listHosts( $hostName = false, $hostTemplate = false ){ - return listNagiosObjects("hosts"); + //return listNagiosObjects("hosts"); + return("test"); //return true; } From 8c3df3f92aba60ab80f56097853f643137b32d31 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Wed, 5 Feb 2020 11:31:31 +0100 Subject: [PATCH 05/14] test2 --- include/ObjectManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index f889b39..798aa6a 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -602,8 +602,8 @@ public function modifyNotifierMethod($method_name, $method_type,$new_method_name /* LILAC - List Hosts */ public function listHosts( $hostName = false, $hostTemplate = false ){ - //return listNagiosObjects("hosts"); - return("test"); + return $this->listNagiosObjects("hosts"); + //return("test"); //return true; } From dffd091426980a67ea8401a49bcbf062b7565239 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Wed, 5 Feb 2020 11:33:44 +0100 Subject: [PATCH 06/14] fonction listHosts fonctionnelle --- include/ObjectManager.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index 798aa6a..7dc02e8 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -602,9 +602,7 @@ public function modifyNotifierMethod($method_name, $method_type,$new_method_name /* LILAC - List Hosts */ public function listHosts( $hostName = false, $hostTemplate = false ){ - return $this->listNagiosObjects("hosts"); - //return("test"); - //return true; + return $this->listNagiosObjects("hosts")["default"]; } ########################################## GET From 405c23a881d0c7685aba1c5f23c0e17cb355252c Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Wed, 5 Feb 2020 12:09:23 +0100 Subject: [PATCH 07/14] ajout de la fonction getHostById --- include/ObjectManager.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index 7dc02e8..7374e75 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -629,6 +629,22 @@ public function getHost( $hostName){ return "Host named ".$hostName." doesn't exist."; } } + + /* LILAC - Get Host by ID */ + public function getHostById($id){ + $nhp = new NagiosHostPeer; + // Find host + $host = $nhp->getById($id); + if($host){ + return $host->toArray(); + }else{ + return "Host with ID ".$id." doesn't exist."; + } + } + + + + /* LILAC - Get Hosts by template name */ public function getHostsBytemplate( $templateHostName){ $nhtp = new NagiosHostTemplatePeer; From a369920a11e5c9fb610d5a13d917b17cc8920fe7 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Wed, 5 Feb 2020 12:14:46 +0100 Subject: [PATCH 08/14] ajout getHostById --- html/api/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/html/api/index.php b/html/api/index.php index 651d147..cf43136 100644 --- a/html/api/index.php +++ b/html/api/index.php @@ -29,6 +29,7 @@ addRoute('post', '/getHost', 'getHost', 'operator'); +addRoute('post', '/getHostById', 'getHostById', 'operator'); addRoute('post', '/getContact', 'getContact', 'operator'); addRoute('post', '/getCommand', 'getCommand', 'operator'); addRoute('post', '/getHostGroup', 'getHostGroup', 'operator'); From bf4705e76269b95e6e621f31093176316cb187c4 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Wed, 5 Feb 2020 13:43:56 +0100 Subject: [PATCH 09/14] add getHostById --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index aa949b3..e02832f 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ You will find below the updated list of actions (**"API_function"**) possible in | `getResources` | GET | None | "status": "authorized" | Return the list of resources. | | `getCommand` | POST | [**commandName**] | "http_code": "200 OK", "result": [with the executed actions] | Return the informations of a command | | `getHost` | POST | [**hostName**] | "http_code": "200 OK", "result": [with the executed actions] | return the given host | +| `getHostById` | POST | [**id**] | "http_code": "200 OK", "result": [with the executed actions] | return the given host | | `getHostGroup` | POST | [**hostGroupName**] | "http_code": "200 OK", "result": [with the executed actions] | return the given host group| | `getHostsByTemplate` | POST | [**templateHostName**] | "http_code": "200 OK", "result": [with the executed actions] | return hosts link with the given template host | | `getHostsByHostGroup` | POST | [**hostGroupName**] | "http_code": "200 OK", "result": [with the executed actions] | return hosts link with the given hostgroup | From e56e40ce1629d5d28ea36fdf43540af980a66bc8 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Fri, 7 Feb 2020 16:55:34 +0100 Subject: [PATCH 10/14] function deleteHostById + doc --- README.md | 1 + html/api/index.php | 1 + include/ObjectManager.php | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/README.md b/README.md index e02832f..2e25c5d 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ You will find below the updated list of actions (**"API_function"**) possible in | `deleteServiceTemplate` | POST | [**templateName**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | Delete the given Service template | | `deleteCommand` | POST | [**commandName**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | Delete a command to Nagios. | | `deleteHost` | POST | [**hostName, exportConfiguration**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | Delete a nagios host. | +| `deleteHostbyId` | POST | [**id, exportConfiguration**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | Delete a nagios host by its ID. | | `deleteContactGroupToContact` | POST | [**contactName, contactGroupName, exportConfiguration**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | delete a contact group to a nagios contact. | | `deleteContactNotificationCommandToContact` | POST | [**contactName, commandName, exportConfiguration**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | delete a contact notification command to a nagios contact. | | `deleteServiceGroupToServiceInHost` | POST | [**serviceGroupName, serviceName, hostName, exportConfiguration = FALSE**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | delete a service group in the given service of the specified host. | diff --git a/html/api/index.php b/html/api/index.php index cf43136..d39b64a 100644 --- a/html/api/index.php +++ b/html/api/index.php @@ -105,6 +105,7 @@ addRoute('post', '/deleteHost', 'deleteHost'); +addRoute('post', '/deleteHostbyId', 'deleteHostbyId'); addRoute('post', '/deleteContact', 'deleteContact'); addRoute('post', '/deleteService', 'deleteService'); addRoute('post', '/deleteCommand', 'deleteCommand'); diff --git a/include/ObjectManager.php b/include/ObjectManager.php index 7374e75..d05b9f8 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -5224,6 +5224,39 @@ public function deleteHost( $hostName, $exportConfiguration = FALSE ){ return array("code"=>$code,"description"=>$logs); } + + public function deleteHostbyId($id, $exportConfiguration = false) { + $error = ""; + $success = ""; + $code = 0; + try { + $nhp = new NagiosHostPeer; + $host = $nhp->getById($id); + if ($host) { + $host->delete(); + $success .= "Host with ID " . $id . " deleted\n"; + } + else { + $code = 1; + $error .= "Host with ID " . $id . " not found\n"; + } + + // Export + if ($exportConfiguration == true) $this->exportConfigurationToNagios(); + } + catch(Exception $e) { + $code = 1; + $error .= $e->getMessage() . "\n"; + } + + $logs = $this->getLogs($error, $success); + return array( + "code" => $code, + "description" => $logs + ); + } + + /* LILAC - Delete Templates Hosts */ public function deleteHostTemplate($templateHostName){ $error = ""; From 372abd819fb17b932a3bc8e1c26935845cb511d7 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Tue, 11 Feb 2020 12:12:22 +0100 Subject: [PATCH 11/14] typo correction --- include/ObjectManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index d05b9f8..b586736 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -5225,7 +5225,7 @@ public function deleteHost( $hostName, $exportConfiguration = FALSE ){ } - public function deleteHostbyId($id, $exportConfiguration = false) { + public function deleteHostById($id, $exportConfiguration = false) { $error = ""; $success = ""; $code = 0; From 20f21d517fe38c27d3a6a339a4b24799bba88113 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Tue, 11 Feb 2020 12:12:43 +0100 Subject: [PATCH 12/14] correction typo --- html/api/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/api/index.php b/html/api/index.php index d39b64a..1a09663 100644 --- a/html/api/index.php +++ b/html/api/index.php @@ -105,7 +105,7 @@ addRoute('post', '/deleteHost', 'deleteHost'); -addRoute('post', '/deleteHostbyId', 'deleteHostbyId'); +addRoute('post', '/deleteHostById', 'deleteHostById'); addRoute('post', '/deleteContact', 'deleteContact'); addRoute('post', '/deleteService', 'deleteService'); addRoute('post', '/deleteCommand', 'deleteCommand'); From 85acd56c734977990c2dc9924b0bef1470062e39 Mon Sep 17 00:00:00 2001 From: IPv777 <19636346+IPv777@users.noreply.github.com> Date: Tue, 11 Feb 2020 12:13:49 +0100 Subject: [PATCH 13/14] correction typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e25c5d..34f7bbe 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ You will find below the updated list of actions (**"API_function"**) possible in | `deleteServiceTemplate` | POST | [**templateName**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | Delete the given Service template | | `deleteCommand` | POST | [**commandName**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | Delete a command to Nagios. | | `deleteHost` | POST | [**hostName, exportConfiguration**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | Delete a nagios host. | -| `deleteHostbyId` | POST | [**id, exportConfiguration**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | Delete a nagios host by its ID. | +| `deleteHostById` | POST | [**id, exportConfiguration**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | Delete a nagios host by its ID. | | `deleteContactGroupToContact` | POST | [**contactName, contactGroupName, exportConfiguration**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | delete a contact group to a nagios contact. | | `deleteContactNotificationCommandToContact` | POST | [**contactName, commandName, exportConfiguration**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | delete a contact notification command to a nagios contact. | | `deleteServiceGroupToServiceInHost` | POST | [**serviceGroupName, serviceName, hostName, exportConfiguration = FALSE**] | "http_code": "200 OK", "result": ["code":returnCode,"description":"logs"] | delete a service group in the given service of the specified host. | From 39afc063624f2985c0def48a434226ca0873a28d Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 19 Feb 2020 14:02:19 +0100 Subject: [PATCH 14/14] annulation setDisplayName --- include/ObjectManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ObjectManager.php b/include/ObjectManager.php index b586736..558e989 100644 --- a/include/ObjectManager.php +++ b/include/ObjectManager.php @@ -1269,7 +1269,7 @@ public function createHost( $templateHostName="GENERIC_HOST", $hostName, $hostIp $tempHost = new NagiosHost(); $tempHost->setName($hostName); $tempHost->setAlias($hostAlias); - $tempHost->setDisplayName($hostName); + // $tempHost->setDisplayName($hostName); $tempHost->setAddress($hostIp); $tempHost->save(); $success .= "Host $hostName added\n";