public function testGenerate()
 {
     $fileList = array();
     $pollerId = 1;
     $hostMacroEvent = new HostMacroEvent($pollerId);
     HostTemplateRepository::generate($fileList, $pollerId, $this->tmpDir . '/', 'hosttemplates.cfg', $hostMacroEvent);
     $this->assertEquals(array('cfg_dir' => array($this->tmpDir . '/1/')), $fileList);
     $content = file_get_contents($this->tmpDir . '/1/hosttemplates.cfg');
     /* Remove line with the generate date */
     $lines = explode("\n", $content);
     $lines = preg_grep('/^#\\s+Last.*#$/', $lines, PREG_GREP_INVERT);
     $content = join("\n", $lines);
     $resultContent = file_get_contents(dirname(__DIR__) . '/data/configfiles/hosttemplate1.cfg');
     $this->assertEquals($resultContent, $content);
 }
예제 #2
0
 /**
  * Generate all object files (host, service, etc...)
  *
  */
 public static function generateObjectsFiles()
 {
     $event = static::$event;
     /* Generate Configuration files */
     CommandRepository::generate(static::$fileList, $event->getPollerId(), static::$path, "check-command.cfg", CommandRepository::CHECK_TYPE);
     $event->setOutput('check-command.cfg');
     CommandRepository::generate(static::$fileList, $event->getPollerId(), static::$path, "misc-command.cfg", CommandRepository::NOTIF_TYPE);
     $event->setOutput('misc-command.cfg');
     ConfigGenerateResourcesRepository::generate(static::$fileList, $event->getPollerId(), static::$path, "resources.cfg");
     $event->setOutput('resources.cfg');
     ConfigGenerateModulesRepository::generate(static::$fileList, $event->getPollerId(), static::$path, $event);
     TimePeriodRepository::generate(static::$fileList, $event->getPollerId(), static::$path, "timeperiods.cfg");
     $event->setOutput('timeperiods.cfg');
     ConnectorRepository::generate(static::$fileList, $event->getPollerId(), static::$path, "connectors.cfg");
     $event->setOutput('connectors.cfg');
     /* Retrieve all extra macros by emitting event */
     $events = Di::getDefault()->get('events');
     $hostMacroEvent = new HostMacroEvent($event->getPollerId());
     $events->emit('centreon-engine.get.macro.host', array($hostMacroEvent));
     $serviceMacroEvent = new ServiceMacroEvent($event->getPollerId());
     $events->emit('centreon-engine.get.macro.service', array($serviceMacroEvent));
     $notificationRulesEvent = new NotificationRuleEvent($event->getPollerId());
     $events->emit('centreon-engine.set.notifications.rules', array($notificationRulesEvent));
     /* Templates config files */
     HostTemplateRepository::generate(static::$fileList, $event->getPollerId(), static::$path, "hostTemplates.cfg", $hostMacroEvent);
     $event->setOutput('hostTemplates.cfg');
     ServicetemplateRepository::generate(static::$fileList, $event->getPollerId(), static::$path, "serviceTemplates.cfg", $serviceMacroEvent);
     $event->setOutput('serviceTemplate.cfg');
     /* Monitoring Resources files */
     HostRepository::generate(static::$fileList, $event->getPollerId(), static::$path, "resources/", $hostMacroEvent, $serviceMacroEvent);
     $event->setOutput('host configuration files');
 }