/** * @param \CentreonConfiguration\Events\EngineProcess $event * @throws \Centreon\Internal\Exception * @todo send command to centreon.d */ public static function execute(EngineProcessEvent $event) { /*$action = $event->getAction(); if (!in_array($action, array('reload', 'restart', 'forcereload'))) { throw new Exception(sprintf('Invalid action for Engine: %s', $action)); } $engineParams = Engine::get($event->getPollerId(), 'init_script'); if (!isset($engineParams['init_script'])) { throw new Exception(sprintf("Could not find init script for poller %s", $event->getPollerId())); } $initScript = $engineParams['init_script']; $command = "sudo {$initScript} {$action} 2>&1"; $status = 0; $output = array(); exec($command, $output, $status); foreach ($output as $line) { $event->setOutput($line); } $event->setStatus( $status ? false : true );*/ $action = $event->getAction(); if ($action == "restart") { $cmd = "[%u] RESTART_PROGRAM\n"; } else { if ($action == "reload") { $cmd = "[%u] RELOAD_PROGRAM\n"; } else { throw new \Exception("Bad type of command."); } } $extCommand = new ExternalCommand($event->getPollerId(), sprintf($cmd, time()), 'engine'); Di::getDefault()->get('events')->emit('centreon-realtime.command.send', array($extCommand)); }
/** * * @param array $element * @return array */ public static function addValidation($element) { $validations = parent::addValidation($element); $validationUrl = Di::getDefault()->get('router')->getPathFor('/validator/email'); $validations['eventValidation'] .= ' $("#' . $element['name'] . '").on("blur", function() { $.ajax({ url: "' . $validationUrl . '", type: "POST", data: {"email":$("#' . $element['name'] . '").val()}, context: document.body }) .success(function(data, status, jqxhr) { if (data.success) { $("#' . $element['name'] . '_email").removeClass("has-error has-feedback"); $("#' . $element['name'] . '_email_span").removeClass("glyphicon glyphicon-remove form-control-feedback"); $("#' . $element['name'] . '_email").addClass("has-success has-feedback"); $("#' . $element['name'] . '_email_span").addClass("glyphicon glyphicon-ok form-control-feedback"); } else { $("#' . $element['name'] . '_email").removeClass("has-error has-feedback"); $("#' . $element['name'] . '_email_span").removeClass("glyphicon glyphicon-ok form-control-feedback"); $("#' . $element['name'] . '_email").addClass("has-error has-feedback"); $("#' . $element['name'] . '_email_span").addClass("glyphicon glyphicon-remove form-control-feedback"); } }); });'; return $validations; }
public static function execute(SlideMenuEvent $event) { $router = Di::getDefault()->get('router'); try { $event->setDefaultMenu(array('name' => 'service', 'url' => $router->getPathFor('/centreon-configuration/service/snapshotslide/') . $event->getId(), 'icon' => '', 'order' => 0, 'tpl' => "/viewtpl/CentreonConfigurationModule/service_slide")); $event->addMenu(array('name' => 'template', 'url' => $router->getPathFor('/centreon-configuration/servicetemplate/viewconfslide/') . $event->getId(), 'icon' => '', 'order' => 2, 'tpl' => "/viewtpl/CentreonConfigurationModule/service_templates_slide")); $event->addMenu(array('name' => 'tag', 'url' => $router->getPathFor('/centreon-configuration/service/' . $event->getId() . '/tags'), 'icon' => '', 'order' => 1, 'tpl' => "/viewtpl/CentreonConfigurationModule/tags_slide", 'default' => 1)); /* $event->addMenu( array( 'name' => 'service', 'url' => $router->getPathFor('/centreon-configuration/host/'.$event->getId().'/service'), 'icon' => '', 'order' => 4, 'tpl' => "/viewtpl/CentreonConfigurationModule/services_slide" ) ); $event->addMenu( array( 'name' => 'command', 'url' => $router->getPathFor('/centreon-configuration/host/'.$event->getId().'/command'), 'icon' => '', 'order' => 5, 'tpl' => "/viewtpl/CentreonConfigurationModule/command_slide" ) ); */ } catch (Exception $e) { } }
/** * Generate modules configuration files * @param array $filesList * @param int $pollerId * @param string $path * @param object $event * @return value */ public function generate(&$filesList, $pollerId, $path, $event) { $di = Di::getDefault(); /* Get Database Connexion */ $dbconn = $di->get('db_centreon'); $modules = array(); /* Retrieve broker modules */ $events = Di::getDefault()->get('events'); $moduleEvent = new BrokerModuleEvent($pollerId); $events->emit('centreon-configuration.broker.module', array($moduleEvent)); $brokerModules = $moduleEvent->getModules(); foreach ($brokerModules as $brokerModule) { $modules[]['broker_module'] = $brokerModule; } /* External command module */ $moduleDir = Engine::getParameters($pollerId, 'module_dir'); $modules[]['broker_module'] = rtrim($moduleDir['module_dir'], '/') . '/externalcmd.so'; /* Write modules configuration files */ foreach ($modules as $module) { $filename = preg_match('/\\/?(\\w+)\\.so/', $module['broker_module'], $matches); if (!empty($matches[1])) { WriteConfigFile::writeParamsFile($module, $path . $pollerId . "/conf.d/" . $matches[1] . '.cfg', $filesList, $user = "******"); } } }
/** * * @param \CentreonConfiguration\Events\RunTest $event */ public static function execute(RunTestEvent $event) { $di = Di::getDefault(); $dbconn = $di->get('db_centreon'); $tmpdir = $di->get('config')->get('global', 'centreon_generate_tmp_dir'); $pollerId = $event->getPollerId(); $enginePath = '/usr/sbin/centengine'; $path = "{$tmpdir}/engine/generate/{$pollerId}/centengine-testing.cfg"; $command = "sudo {$enginePath} -v {$path} 2>&1"; exec($command, $output, $status); if ($status == 0) { // We are only selecting warning/errors here // Colors/formatting is performed either in Command (centreonConsole) or JS (web => API thru JSON) foreach ($output as $out) { if (preg_match("/warning|error/i", $out)) { $out = preg_replace("/\\[\\d+\\] /", "", $out); $event->setOutput($out); } } } else { $event->setOutput('Error while executing test command'); foreach ($output as $out) { $event->setOutput($out); } } }
public function pollerStatus() { $router = Di::getDefault()->get('router'); $orgId = Di::getDefault()->get('organization'); $dbconn = Di::getDefault()->get('db_centreon'); $query = 'SELECT c.name, r.last_alive, r.running, r.instance_id FROM cfg_pollers c LEFT OUTER JOIN rt_instances r ON r.instance_id = c.poller_id WHERE c.organization_id = :org_id'; $stmt = $dbconn->prepare($query); $stmt->bindParam(':org_id', $orgId, \PDO::PARAM_INT); $stmt->execute(); $now = time(); $pollers = array(); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $row['latency'] = 0; if (is_null($row['last_alive']) || $row['last_alive'] - $now > 60) { $row['disconnect'] = 1; } else { $row['disconnect'] = 0; } $pollers[] = $row; } return $pollers; }
/** * * @param int $id * @param string $object * @return string */ public static function getUseNumber($id, $object) { $di = Di::getDefault(); /* Get Database Connexion */ $dbconn = $di->get('db_centreon'); $result = ""; if ($object == 'host') { $objectTable = 'cfg_hosts'; } elseif ($object == 'service') { $objectTable = 'cfg_services'; } /* Get Object Stats */ for ($i = 1; $i != -1; $i--) { $stmt = $dbconn->prepare("SELECT count(*) AS number " . "FROM {$objectTable} " . "WHERE (command_command_id = '{$id}' " . "OR command_command_id2 = '{$id}') " . "AND " . $object . "_register = '{$i}'"); $stmt->execute(); $row = $stmt->fetch(\PDO::FETCH_ASSOC); if (isset($row["number"])) { if ($i) { $result .= $row["number"]; } else { $result .= " (" . $row["number"] . ")"; } } } return $result; }
/** * Constructor * * @param int $serviceId The service ID * @param int $startTime The start time for graph * @param int $endTime The end time for graph */ public function __construct($serviceId, $startTime, $endTime) { $di = Di::getDefault(); $dbconn = $di->get('db_centreon'); /* Get the list of metrics */ $query = "SELECT i.index_id, i.service_description, m.metric_id, m.metric_name, m.unit_name, m.warn, m.warn_low, m.crit, m.crit_low, m.min, m.max\n FROM rt_index_data i, rt_metrics m\n WHERE i.service_id = :service_id\n AND i.index_id = m.index_id\n AND m.hidden = '0'"; $stmt = $dbconn->prepare($query); $stmt->bindParam(':service_id', $serviceId); $stmt->execute(); /* List of service template */ $svcTmpls = ServiceRepository::getListTemplates($serviceId); /* Get the graph template */ $graphInfos = null; foreach ($svcTmpls as $svcTmplId) { $graphInfos = GraphTemplate::getByServiceTemplate($svcTmplId); if (count($graphInfos) > 0) { break; } } while ($row = $stmt->fetch()) { $metric = array('id' => $row['metric_id'], 'unit' => $row['unit_name'], 'color' => null, 'legend' => $row['metric_name'], 'is_negative' => false, 'graph_type' => 'line'); if (count($graphInfos) > 0 && isset($graphInfos['metrics'][$row['metric_name']])) { $metric = array_merge($metric, $graphInfos['metrics'][$row['metric_name']]); } $this->metrics[] = $metric; } parent::__construct($startTime, $endTime); }
/** * Send command for each object returned by the sql query. * * @param int $cmdId * @param str $sql * @param array $additionalParams */ public static function doCommand($cmdId, $sql, $additionalParams) { $db = Di::getDefault()->get('db_centreon'); $stmt = $db->prepare($sql); $stmt->execute(); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { switch ($cmdId) { case static::SCHEDULE_CHECK: $options = array(time()); break; case static::ACKNOWLEDGE: $options = array(isset($additionalParams['sticky']) ? 1 : 0, isset($additionalParams['notify']) ? $additionalParams['notify'] : 0, isset($additionalParams['persistent']) ? 1 : 0, $additionalParams['author'], $additionalParams['comment']); break; case static::DOWNTIME: $options = array($additionalParams['start_time'], $additionalParams['end_time'], isset($additionalParams['fixed']) ? 1 : 0, 0, isset($additionalParams['fixed']) ? 0 : $additionalParams['duration'], $additionalParams['author'], $additionalParams['comment']); break; case static::REMOVE_ACKNOWLEDGE: break; case static::REMOVE_DOWNTIME: break; default: $options = array(); break; } $instanceId = $row['instance_id']; unset($row['instance_id']); self::sendCommand($cmdId, $instanceId, array_merge($row, $options)); } }
/** * * @param array $resultSet */ protected function formatDatas(&$resultSet) { $previousType = ''; foreach ($resultSet as &$myBaSet) { $sideMenuCustom = new SlideMenu($myBaSet['ba_id']); $events = Di::getDefault()->get('events'); $events->emit('centreon-bam.slide.menu.business.activity', array($sideMenuCustom)); $myBaSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu(); $myBaSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu(); // Set business activity type $baType = \CentreonBam\Models\BusinessActivityType::getParameters($myBaSet['ba_type_id'], array('name')); $myBaSet['ba_type_id'] = $baType['name']; if ($myBaSet['ba_type_id'] === $previousType) { $myBaSet['ba_type_id'] = ''; } else { $previousType = $myBaSet['ba_type_id']; } // set business activity name $myBaSet['name'] = BusinessActivityRepository::getIconImage($myBaSet['name']) . $myBaSet['name']; /* Tags */ $myBaSet['tagname'] = ""; $aTags = TagsRepository::getList('ba', $myBaSet['ba_id'], 2); foreach ($aTags as $oTags) { $myBaSet['tagname'] .= TagsRepository::getTag('ba', $myBaSet['ba_id'], $oTags['id'], $oTags['text'], $oTags['user_id'], $oTags['template_id']); } $myBaSet['tagname'] .= TagsRepository::getAddTag('ba', $myBaSet['ba_id']); } }
/** * * @param int $pollerId * @return type */ public function __construct($pollerId) { $this->di = Di::getDefault(); $this->output = array(); $this->pollerId = $pollerId; $this->status = true; }
/** * * @param array $element * @return array */ public static function addValidation($element) { $validations = parent::addValidation($element); $resolveUrl = Di::getDefault()->get('router')->getPathFor('/validator/resolvedns'); $validations['eventValidation']['extraJs'] = '$("#' . $element['name'] . '_resolve_dns").on("click", function(){ $.ajax({ url: "' . $resolveUrl . '", type: "POST", data: {"dnsname":$("#' . $element['name'] . '").val()}, dataType: "json", context: document.body }) .success(function(data, status, jqxhr) { alertClose(); if (data["success"]) { $("#' . $element['name'] . '").val(data["value"]); $("#' . $element['name'] . '").trigger("blur"); } else { alertMessage(data["error"], "alert-danger"); } }); });'; $validations['eventValidation'][$element['name']] = array('ipaddress' => array()); return $validations; }
/** * */ public static function migrateCentreon() { if (!self::checkForMigration()) { Install::installCentreon(); } else { $di = Di::getDefault(); $config = $di->get('config'); $dbName = $config->get('db_centreon', 'dbname'); echo Colorize::colorizeMessage("Starting to migrate to Centreon 3.0", "info") . "\n"; echo "Preparing Migration... "; self::prepareDb(); echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n"; echo "Migrating " . Colorize::colorizeText('centreon', 'blue', 'black', true) . " database... "; Db::update($dbName); echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n"; $modulesToInstall = self::getCoreModules(); $dependencyResolver = new Dependency($modulesToInstall['modules']); $installOrder = $dependencyResolver->resolve(); foreach ($installOrder as $moduleName) { $currentModule = $modulesToInstall['modules'][$moduleName]; $moduleInstaller = new $currentModule['classCall']($currentModule['directory'], $currentModule['infos'], 'console'); echo "Installing " . Colorize::colorizeText($moduleName, 'purple', 'black', true) . " module... "; $moduleInstaller->install(false); echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n"; } echo Colorize::colorizeMessage("Your Centreon has been successfully migrated to Centreon 3.0", "success") . "\n"; } }
function smarty_modifier_url($url) { $di = \Centreon\Internal\Di::getDefault(); $config = $di->get('config'); $fullUrl = rtrim($config->get('global', 'base_url'), '/') . $url; return $fullUrl; }
/** * * @cmdForm /centreon-administration/aclresource/update optional * @cmdObject string aclresource the acl resource * @cmdParam boolean|true all-hosts optional all host * @cmdParam boolean|true all-bas optional all bas * @cmdParam boolean|false no-hosts optional no host * @cmdParam boolean|false no-bas optional no bas */ public function updateAction($object, $params) { $events = Di::getDefault()->get('events'); $aclTagsEvent = new aclTagsEvent($params); $events->emit('centreon-administration.acl.tag', array($aclTagsEvent)); $params = $aclTagsEvent->getParams(); parent::updateAction($object, $params); }
/** * The page structure for display * * @method get * @route /indicator/realtime/list */ public function listAction() { $di = Di::getDefault(); $router = $di->get('router'); $myDatatable = new $this->datatableObject($this->getParams('get'), $this->objectClass); $myDataForDatatable = $myDatatable->getDatas(); $router->response()->json($myDataForDatatable); }
public function testExecute() { $eventParams = new GenerateEngineEvent(1); GenerateEngine::execute($eventParams); $genPath = Di::getDefault()->get('config')->get('global', 'centreon_generate_tmp_dir'); $this->assertFileExists($genPath . "/1/centengine.cfg"); $this->assertFileExists($genPath . "/1/centengine-testing.cfg"); }
function smarty_modifier_img($imgFile) { $di = \Centreon\Internal\Di::getDefault(); $config = $di->get('config'); $baseUrl = rtrim($config->get('global', 'base_url'), '/') . '/static/centreon/img/'; $imgIncludeLine = '<img alt="' . $imgFile . '"' . 'src="' . $baseUrl . $imgFile . '" />'; return $imgIncludeLine; }
/** * * @method get * @route /businessactivitytype/configuration */ public function listAction() { $router = Di::getDefault()->get('router'); $this->tpl->addJs('hogan-3.0.0.min.js'); $urls = array(); $this->tpl->append('jsUrl', $urls, true); parent::listAction(); }
/** * * @method get * @route /businessview/configuration */ public function listAction() { $router = Di::getDefault()->get('router'); $this->tpl->addJs('hogan-3.0.0.min.js')->addJs('centreon.tag.js', 'bottom', 'centreon-administration'); $urls = array('tag' => array('add' => $router->getPathFor('/centreon-administration/tag/add'), 'del' => $router->getPathFor('/centreon-administration/tag/delete'))); $this->tpl->append('jsUrl', $urls, true); parent::listAction(); }
/** * Used for deleting relation from database * * @param int $fkey * @param int $skey * @return void */ public static function delete($skey, $fkey = null) { $sql = "UPDATE cfg_bam_kpi SET id_ba = NULL WHERE id_ba = ?"; $args = array($fkey); $db = Di::getDefault()->get('db_centreon'); $stmt = $db->prepare($sql); $stmt->execute($args); }
/** * Get business activities for a specific acl resource * * @method get * @route /aclresource/[i:id]/businessactivity/tag */ public function businessActivitiesForAclResourceAction() { $di = Di::getDefault(); $router = $di->get('router'); $requestParam = $this->getParams('named'); $finalBaTagList = BusinessActivityTagRepository::getBusinessActivityTagsByAclResourceId($requestParam['id']); $router->response()->json($finalBaTagList); }
/** * Used for deleting relation from database * * @param int $fkey * @param int $skey * @return void */ public static function delete($skey, $fkey = null) { $sql = "UPDATE cfg_commands SET connector_id = NULL WHERE connector_id = ?"; $args = array($skey); $db = Di::getDefault()->get('db_centreon'); $stmt = $db->prepare($sql); $stmt->execute($args); }
/** * Get service tags for a specific acl resource * * @method get * @route /aclresource/[i:id]/service/tag */ public function serviceTagsForAclResourceAction() { $di = Di::getDefault(); $router = $di->get('router'); $requestParam = $this->getParams('named'); $finalServiceTagList = ServiceTagRepository::getServiceTagsByAclResourceId($requestParam['id']); $router->response()->json($finalServiceTagList); }
public function testAddJs() { $tpl = Di::getDefault()->get('template'); $tpl->addJs('jquery.min.js')->addJs('bootstrap.min.js'); $printedResult = $tpl->fetch('template/testAddJs.tpl'); $this->assertContains('jquery.min.js', $printedResult); $this->assertContains('bootstrap.min.js', $printedResult); }
public static function execute(SlideMenuEvent $event) { $router = Di::getDefault()->get('router'); try { $event->addMenu(array('name' => 'incident', 'url' => $router->getPathFor('/centreon-realtime/host/' . $event->getId() . '/issues'), 'icon' => '', 'order' => 5, 'tpl' => "/viewtpl/CentreonRealtimeModule/incidents_slide")); } catch (Exception $e) { } }
public static function deleteAllForArId($ar_id) { $di = Di::getDefault(); $dbconn = $di->get('db_centreon'); $sql = "DELETE FROM cfg_auth_resources_servers WHERE auth_resource_id = ?"; $stmt = $dbconn->prepare($sql); $stmt->bindValue(1, $ar_id, \PDO::PARAM_INT); $stmt->execute(); }
/** * * @param type $moduleCanonicalName */ public function __construct($moduleCanonicalName) { $this->moduleCanonicalName = $moduleCanonicalName; $config = Di::getDefault()->get('config'); $centreonPath = rtrim($config->get('global', 'centreon_path'), '/'); $this->licensePath = $centreonPath . '/infos/header.txt'; $this->moduleFolderPath = $centreonPath . '/modules/' . $moduleCanonicalName . 'Module'; $this->defineModuleFolderStructure(); }
/** * Return the HTML ouput of the checkbox field * * @param array $element * @return array */ public static function renderHtmlInput(array $element) { if (!isset($element['id']) || isset($element['id']) && empty($element['id'])) { $element['id'] = $element['name']; } $tpl = Di::getDefault()->get('template'); $tpl->assign('element', $element); return array('html' => $tpl->fetch('file:[Core]/form/component/singlecheckbox.tpl')); }
/** * Execute hook * * @param array $params */ public static function execute($params) { $router = Di::getDefault()->get('router'); if (!preg_match("/^\\/centreon-performance/", $router->getCurrentUri())) { return; } $bookmarkedGraphs = GraphView::getList(); return array('template' => 'displayLeftMenuForGraph.tpl', 'variables' => array('bookmarkedGraphs' => $bookmarkedGraphs)); }