-
Notifications
You must be signed in to change notification settings - Fork 3
Functions listHosts/getHostById/deleteHostById working #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
29d2e90
08356a6
1b5b8f4
4c8e51b
d050cb2
8c3df3f
dffd091
405c23a
a369920
bf4705e
c91722c
e56e40c
973c170
372abd8
20f21d5
85acd56
39afc06
57a6194
f81d7eb
f6ef159
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 true; | ||
|
|
||
| return $this->listNagiosObjects("hosts")["default"]; | ||
| } | ||
|
|
||
| ########################################## GET | ||
|
|
@@ -631,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; | ||
|
|
@@ -944,6 +958,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 ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to test a value of a boolean: |
||
| $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 = ""; | ||
|
|
@@ -1198,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"; | ||
|
|
@@ -4171,6 +4242,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 ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to test a value of a boolean: if($exportConfiguration) |
||
| $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 = ""; | ||
|
|
@@ -5102,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 = ""; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a defense on the "default" key, in the doubt that the returned array is empty.