Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,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. |
Expand Down
7 changes: 6 additions & 1 deletion html/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -58,6 +59,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');
Expand Down Expand Up @@ -103,6 +105,7 @@


addRoute('post', '/deleteHost', 'deleteHost');
addRoute('post', '/deleteHostById', 'deleteHostById');
addRoute('post', '/deleteContact', 'deleteContact');
addRoute('post', '/deleteService', 'deleteService');
addRoute('post', '/deleteCommand', 'deleteCommand');
Expand All @@ -112,6 +115,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');
Expand Down Expand Up @@ -151,6 +155,7 @@
addRoute('post', '/listNagiosStates', 'listNagiosStates', 'readonly');
addRoute('post', '/listNagiosObjects', 'listNagiosObjects', 'readonly');
addRoute('post', '/listNagiosBackends', 'listNagiosBackends', 'readonly');
addRoute('post', '/listHosts', 'listHosts', 'readonly');

//==============================================================================
//eonweb
Expand Down Expand Up @@ -235,4 +240,4 @@ function addRoute($httpMethod, $routeName, $methodName, $right="admin"){

$app->run();

?>
?>
163 changes: 159 additions & 4 deletions include/ObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

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.

}

########################################## GET
Expand All @@ -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;
Expand Down Expand Up @@ -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 )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to test a value of a boolean: if($exportConfiguration)
is enough isn't it?

$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 = "";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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 )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to test a value of a boolean: if($exportConfiguration)
is enough isn't it?

$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 = "";
Expand Down Expand Up @@ -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 = "";
Expand Down