Exemplo n.º 1
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityHostImporter beginning to import Host Configuration.");
     // Hosts
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts", PDO::FETCH_ASSOC) as $hostData) {
         $this->importHost($hostData);
     }
     // Host parents
     // go through, check if the host actually exists in our system
     // now, then add the parents, if it's found.
     // First the host table,
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts", PDO::FETCH_ASSOC) as $hostData) {
         if (empty($hostData['parents'])) {
             continue;
         }
         // Okay, there's actually an parent in here.
         // Get the name.
         $name = $this->getHostNameById($hostData['parents'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Host Importer: Could not find host with id: " . $hostData['parents'] . " to add as parent.");
         } else {
             // Okay, $name is equal to the parent host name.  Let's get the name
             // of the host this parent belongs to
             $childName = $this->getHostNameById($hostData['host_id'], $this->dbConn);
             // Okay, fetch our host which should have this name.
             $host = NagiosHostPeer::getByName($childName);
             if (!$host) {
                 $job->addWarning("Fruity Host Importer: Could not find host in Lilac with name: " . $childName);
             } else {
                 $host->addParentByName($name);
                 $host->save();
             }
         }
     }
     // then the nagios_host_parents table
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_parents", PDO::FETCH_ASSOC) as $hostData) {
         // Get the name.
         $name = $this->getHostNameById($hostData['parent_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Host Importer: Could not find host with id: " . $hostData['parents'] . " to add as parent.");
         } else {
             // Okay, $name is equal to the parent host name.  Let's get the name
             // of the host this parent belongs to
             $childName = $this->getHostNameById($hostData['child_id'], $this->dbConn);
             // Okay, fetch our host which should have this name.
             $host = NagiosHostPeer::getByName($childName);
             if (!$host) {
                 $job->addWarning("Fruity Host Importer: Could not find host in Lilac with name: " . $childName);
             } else {
                 $host->addParentByName($name);
                 $host->save();
             }
         }
     }
     // Host Check Command Parameters
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts_check_command_parameters WHERE host_id IS NOT NULL", PDO::FETCH_ASSOC) as $commandParameterInfo) {
         $hostName = $this->getHostNameById($commandParameterInfo['host_id']);
         if (!$hostName) {
             $job->addNotice("Fruity Host Check Command Parameter Importer: Could not find host with id " . $commandParameterInfo['host_id']);
             continue;
         }
         // Get the host
         $host = NagiosHostPeer::getByName($hostName);
         if (!$host) {
             $job->addNotice("Fruity Host Check Command Parameter Importer: Could not find host with name " . $hostTemplateName);
             continue;
         }
         $newParameter = new NagiosHostCheckCommandParameter();
         $newParameter->setHost($host->getId());
         $newParameter->setParameter($commandParameterInfo['parameter']);
         $newParameter->save();
     }
     // Host Contact Groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_contactgroups", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostName = $this->getHostNameById($membershipInfo['host_id']);
         if (!$hostName) {
             $job->addNotice("Fruity Host Contact Group Importer: Could not find host with id " . $membershipInfo['host_id']);
             continue;
         }
         // Get the template
         $host = NagiosHostPeer::getByName($hostName);
         if (!$host) {
             $job->addNotice("Fruity Host Contact Group Importer: Could not find host with name " . $hostName);
             continue;
         }
         // Now get Contact Group Name
         $contactGroupName = $this->getContactGroupNameById($membershipInfo['contactgroup_id']);
         if (!$contactGroupName) {
             $job->addNotice("Fruity Host Contact Group Importer: Could not find contact group with id: " . $membershipInfo['contactgroup_id']);
             continue;
         }
         $contactGroup = NagiosContactGroupPeer::getByName($contactGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Host Contact Group Importer: Could not find contact group with name: " . $contactGroupName);
             continue;
         }
         $membership = new NagiosHostContactGroup();
         $membership->setHost($host->getId());
         $membership->setNagiosContactGroup($contactGroup);
         $membership->save();
     }
     // Host Extended Information
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts_extended_info", PDO::FETCH_ASSOC) as $extInfo) {
         $hostName = $this->getHostNameById($extInfo['host_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Extended Info Importer: Could not find host with id " . $extInfo['host_id']);
             continue;
         }
         // Get the host
         $host = NagiosHostPeer::getByName($hostName);
         if (!$hostName) {
             $job->addNotice("Fruity Host Extended Info Importer: Could not find host with name " . $hostTemplateName);
             continue;
         }
         // Go through the extended info, and set it on the template.
         $host->setNotes($extInfo['notes']);
         $host->setNotesUrl($extInfo['notes_url']);
         $host->setActionUrl($extInfo['action_url']);
         $host->setIconImage($extInfo['icon_image']);
         $host->setIconImageAlt($extInfo['icon_image_alt']);
         $host->setVrmlImage($extInfo['vrml_image']);
         $host->setStatusmapImage($extInfo['statusmap_image']);
         $host->setTwoDCoords($extInfo['two_d_coords']);
         $host->setThreeDCoords($extInfo['three_d_coords']);
         $host->save();
     }
     // Host group memberships
     foreach ($this->dbConn->query("SELECT * FROM nagios_hostgroup_membership", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostName = $this->getHostNameById($membershipInfo['host_id']);
         if (!$hostName) {
             $job->addNotice("Fruity Host Host Group Importer: Could not find host with id " . $membershipInfo['host_id']);
             continue;
         }
         // Get the template
         $host = NagiosHostPeer::getByName($hostName);
         if (!$host) {
             $job->addNotice("Fruity Host Host Group Importer: Could not find host with name " . $hostName);
             continue;
         }
         // Now get Host Group Name
         $hostGroupName = $this->getHostGroupNameById($membershipInfo['hostgroup_id']);
         if (!$hostGroupName) {
             $job->addNotice("Fruity Host Host Group Importer: Could not find host group with id: " . $membershipInfo['hostgroup_id']);
             continue;
         }
         $hostGroup = NagiosHostGroupPeer::getByName($hostGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Host Host Group Importer: Could not find host group with name: " . $hostGroupName);
             continue;
         }
         $membership = new NagiosHostgroupMembership();
         $membership->setHost($host->getId());
         $membership->setNagiosHostGroup($hostGroup);
         $membership->save();
     }
     $job->addNotice("FruityHostImported: Finished importing a total of " . $this->totalImported . " hosts.");
 }
Exemplo n.º 2
0
         $host->save();
         // Remove session data
         unset($modifiedData);
         $success = "Host modified.";
         unset($_GET['edit']);
     }
 } else {
     if ($_POST['request'] == 'add_member_command') {
         $c = new Criteria();
         $c->add(NagiosHostgroupMembershipPeer::HOST, $_GET['id']);
         $c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $modifiedData['hostgroup_id']);
         $tempMembership = NagiosHostgroupMembershipPeer::doSelectOne($c);
         if ($tempMembership) {
             $error = "That host group already exists in that list!";
         } else {
             $membership = new NagiosHostgroupMembership();
             $membership->setNagiosHost($host);
             $membership->setHostgroup($modifiedData['hostgroup_id']);
             $membership->save();
             $success = "Host Added To Host Group.";
             unset($modifiedData);
         }
     } else {
         if ($_POST['request'] == 'command_parameter_add') {
             // All is well for error checking, modify the command.
             $lilac->add_host_command_parameter($_GET['id'], $modifiedData);
             // Remove session data
             unset($host);
             $success = "Command Parameter added.";
         }
     }
Exemplo n.º 3
0
 function addHostgroupByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosHostgroupPeer::NAME, $name);
     $c->setIgnoreCase(true);
     $hostgroup = NagiosHostgroupPeer::doSelectOne($c);
     if (!$hostgroup) {
         return false;
     }
     // Okay, hostgroup is valid, check for relationship
     $id = $this->getId();
     if (!empty($id)) {
         $c = new Criteria();
         $c->add(NagiosHostgroupMembershipPeer::HOST_TEMPLATE, $this->getId());
         $c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $hostgroup->getId());
         $relationship = NagiosHostgroupMembershipPeer::doSelectOne($c);
         if ($relationship) {
             return false;
         }
     }
     $relationship = new NagiosHostgroupMembership();
     $relationship->setNagiosHostTemplate($this);
     $relationship->setNagiosHostgroup($hostgroup);
     $relationship->save();
     return true;
 }
Exemplo n.º 4
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityHostTemplateImporter beginning to import Host Template Configuration.");
     // Host templates
     $queuedHostTemplates = array();
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_templates", PDO::FETCH_ASSOC) as $hostTemplate) {
         if (!$this->importHostTemplate($hostTemplate)) {
             $queuedHostTemplates[] = $hostTemplate;
         }
     }
     while (count($queuedHostTemplates)) {
         for ($counter = 0; $counter < count($queuedHostTemplates); $counter++) {
             if ($this->importHostTemplate($queuedHostTemplates[$counter])) {
                 unset($queuedHostTemplates[$counter]);
             }
         }
     }
     // Host Template Check Command Parameters
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts_check_command_parameters WHERE host_template_id IS NOT NULL", PDO::FETCH_ASSOC) as $commandParameterInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($commandParameterInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Check Command Parameter Importer: Could not find host template with id " . $commandParameterInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Check Command Parameter Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         $newParameter = new NagiosHostCheckCommandParameter();
         $newParameter->setTemplate($hostTemplate->getId());
         $newParameter->setParameter($commandParameterInfo['parameter']);
         $newParameter->save();
     }
     // Host Template Contact Groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_template_contactgroups", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($membershipInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find host template with id " . $membershipInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         // Now get Contact Group Name
         $contactGroupName = $this->getContactGroupNameById($membershipInfo['contactgroup_id']);
         if (!$contactGroupName) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find contact group with id: " . $membershipInfo['contactgroup_id']);
             continue;
         }
         $contactGroup = NagiosContactGroupPeer::getByName($contactGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find contact group with name: " . $contactGroupName);
             continue;
         }
         $membership = new NagiosHostContactGroup();
         $membership->setHostTemplate($hostTemplate->getId());
         $membership->setNagiosContactGroup($contactGroup);
         $membership->save();
     }
     // Host Template Extended Information
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_template_extended_info", PDO::FETCH_ASSOC) as $extInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($extInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Extended Info Importer: Could not find host template with id " . $extInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Extended Info Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         // Go through the extended info, and set it on the template.
         $hostTemplate->setNotes($extInfo['notes']);
         $hostTemplate->setNotesUrl($extInfo['notes_url']);
         $hostTemplate->setActionUrl($extInfo['action_url']);
         $hostTemplate->setIconImage($extInfo['icon_image']);
         $hostTemplate->setIconImageAlt($extInfo['icon_image_alt']);
         $hostTemplate->setVrmlImage($extInfo['vrml_image']);
         $hostTemplate->setStatusmapImage($extInfo['statusmap_image']);
         $hostTemplate->setTwoDCoords($extInfo['two_d_coords']);
         $hostTemplate->setThreeDCoords($extInfo['three_d_coords']);
         $hostTemplate->save();
     }
     // Host group template memberships
     foreach ($this->dbConn->query("SELECT * FROM nagios_hostgroup_template_membership", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($membershipInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host template with id " . $membershipInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         // Now get Contact Group Name
         $hostGroupName = $this->getHostGroupNameById($membershipInfo['hostgroup_id']);
         if (!$hostGroupName) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host group with id: " . $membershipInfo['hostgroup_id']);
             continue;
         }
         $hostGroup = NagiosHostgroupPeer::getByName($hostGroupName);
         if (!$hostGroup) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host group with name: " . $hostGroupName);
             continue;
         }
         $membership = new NagiosHostgroupMembership();
         $membership->setHostTemplate($hostTemplate->getId());
         $membership->setNagiosHostgroup($hostGroup);
         $membership->save();
     }
     $job->addNotice("FruityHostTemplateImporter finished importing Host Template Configuration.");
     $job->addNotice("FruityHostTemplateImporter: Finished importing a total of " . $this->totalImported . " host templates.");
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      NagiosHostgroupMembership $value A NagiosHostgroupMembership object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosHostgroupMembership $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Exemplo n.º 6
0
 public function addMemberByName($name)
 {
     // Support for adding ALL hosts
     if ($name == "*") {
         $hosts = NagiosHostPeer::doSelect(new Criteria());
         foreach ($hosts as $host) {
             $this->addMemberByName($host->getName());
         }
         return true;
     }
     $host = NagiosHostPeer::getByName($name);
     if (!$host) {
         return false;
     }
     $id = $this->getId();
     if (!empty($id)) {
         $c = new Criteria();
         $c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $this->getId());
         $c->add(NagiosHostgroupMembershipPeer::HOST, $host->getId());
         $relationship = NagiosHostgroupMembershipPeer::doSelectOne($c);
         if ($relationship) {
             return true;
         }
         // Already exists.
     }
     // Create new relationship
     $relationship = new NagiosHostgroupMembership();
     $relationship->setNagiosHost($host);
     $relationship->setNagiosHostgroup($this);
     $relationship->save();
     return true;
 }