예제 #1
0
 /**
  * Import configuration data.
  *
  * @todo   for 1.8 version import old class CXmlImport18 is used
  *
  * @throws Exception
  * @throws UnexpectedValueException
  * @return bool
  */
 public function import()
 {
     if (empty($this->reader)) {
         throw new UnexpectedValueException('Reader is not set.');
     }
     try {
         // hack to make api throw exceptions
         // this made to not check all api calls results for false return
         czbxrpc::$useExceptions = true;
         DBstart();
         $this->data = $this->reader->read($this->source);
         $version = $this->getImportVersion();
         // if import version is 1.8 we use old class that support it.
         // old import class process hosts, maps and screens separately.
         if ($version == '1.8') {
             CXmlImport18::import($this->source);
             if ($this->options['maps']['updateExisting'] || $this->options['maps']['createMissing']) {
                 CXmlImport18::parseMap($this->options);
             }
             if ($this->options['screens']['updateExisting'] || $this->options['screens']['createMissing']) {
                 CXmlImport18::parseScreen($this->options);
             }
             if ($this->options['hosts']['updateExisting'] || $this->options['hosts']['createMissing'] || $this->options['templates']['updateExisting'] || $this->options['templates']['createMissing']) {
                 CXmlImport18::parseMain($this->options);
             }
         } else {
             $this->formatter = $this->getFormatter($version);
             // pass data to formatter
             // export has root key "zabbix_export" which is not passed
             $this->formatter->setData($this->data['zabbix_export']);
             $this->referencer = new CImportReferencer();
             // parse all import for references to resolve them all together with less sql count
             $this->gatherReferences();
             $this->processGroups();
             $this->processTemplates();
             $this->processHosts();
             $this->processApplications();
             $this->processItems();
             $this->processDiscoveryRules();
             $this->processTriggers();
             $this->processGraphs();
             $this->processImages();
             $this->processMaps();
             // screens should be created after all other elements
             $this->processTemplateScreens();
             $this->processScreens();
         }
         // prevent api from throwing exception
         czbxrpc::$useExceptions = false;
         return DBend(true);
     } catch (Exception $e) {
         czbxrpc::$useExceptions = false;
         DBend(false);
         throw new Exception($e->getMessage(), $e->getCode());
     }
 }
예제 #2
0
 /**
  * Import configuration data.
  *
  * @todo   for 1.8 version import old class CXmlImport18 is used
  *
  * @throws Exception
  * @throws UnexpectedValueException
  *
  * @return bool
  */
 public function import()
 {
     if (empty($this->reader)) {
         throw new UnexpectedValueException('Reader is not set.');
     }
     $this->data = $this->reader->read($this->source);
     $version = $this->getImportVersion();
     // if import version is 1.8 we use old class that support it.
     // old import class process hosts, maps and screens separately.
     if ($version == '1.8') {
         CXmlImport18::import($this->source);
         if ($this->options['maps']['updateExisting'] || $this->options['maps']['createMissing']) {
             CXmlImport18::parseMap($this->options);
         }
         if ($this->options['screens']['updateExisting'] || $this->options['screens']['createMissing']) {
             CXmlImport18::parseScreen($this->options);
         }
         if ($this->options['hosts']['updateExisting'] || $this->options['hosts']['createMissing'] || $this->options['templates']['updateExisting'] || $this->options['templates']['createMissing']) {
             CXmlImport18::parseMain($this->options);
         }
     } else {
         $this->formatter = $this->getFormatter($version);
         // pass data to formatter
         // export has root key "zabbix_export" which is not passed
         $this->formatter->setData($this->data['zabbix_export']);
         // parse all import for references to resolve them all together with less sql count
         $this->gatherReferences();
         $this->processGroups();
         $this->processTemplates();
         $this->processHosts();
         // delete missing objects from processed hosts and templates
         $this->deleteMissingDiscoveryRules();
         $this->deleteMissingTriggers();
         $this->deleteMissingGraphs();
         $this->deleteMissingItems();
         $this->deleteMissingApplications();
         // import objects
         $this->processApplications();
         $this->processItems();
         $this->processDiscoveryRules();
         $this->processTriggers();
         $this->processGraphs();
         $this->processImages();
         $this->processMaps();
         $this->processTemplateScreens();
         $this->processScreens();
     }
     return true;
 }