public function fetch($clients, $ms = -1) { $poller = new Poller(); $poll_ids = []; foreach ($clients as $i => $client) { $id = $poller->registerReadable($client); $poll_ids[$id] = $i; } $ms_left = $ms; $ret = []; do { $rset = []; $wset = []; $events = 0; if ($ms_left > 0) { $tv1_ms = gettimeofday(true) * 1000; $events = $poller->poll($rset, $wset, $ms_left); $tv2_ms = gettimeofday(true) * 1000; $ms_left -= $tv2_ms - $tv1_ms; if ($ms_left < 0) { $ms_left = 0; } } else { $events = $poller->poll($rset, $wset, $ms_left); } // $errors = $poller->getLastErrors(); // if (count($errors) > 0) { // $errno = -1; // $errstr = []; // foreach ($errors as $error) { // $errstr[] = $error; // } // $this->setErr_($errno, implode(',', $errstr)); // $ret = false; // } if ($events > 0) { foreach ($rset as $id) { $i = $poll_ids[$id]; $msg = $clients[$i]->recv(); if ($msg !== false && !$client->errno()) { $ret[$i] = $msg; } $poller->unregister($client); } } } while ($poller->count() && $ms_left > 0); return $ret; }
fclose($fp); } if ($hashPrevious !== $hash) { echo "Alert"; $this->basic->mail("*****@*****.**", "Soporte BSW", "*****@*****.**", "QoE Smart Agent Information " . $site, $portlet_table); //Configuration DB bsw_bi if (!is_null($server['mailAlert'])) { $this->basic->mail($server['mailAlert'], "Soporte BSW", "*****@*****.**", "QoE Smart Agent Information " . $site, $portlet_table); } } } else { continue; } } } } } $cmd = new Control(true, 'core.bi.node1.baking.cl', true); /* $cmd->parametro->remove('STDOUT'); $cmd->parametro->set('STDOUT', true); $cmd->parametro->remove('DEBUG'); $cmd->parametro->set('DEBUG', true); */ //Start Split $poller = new Poller($cmd); $poller->validStart(); //$poller->start(); $poller->sendMail(); ?>
//Create Table IF NOT EXIST $createAlertTable = $this->conexion->query("CREATE TABLE IF NOT EXISTS `bm_alert` (\r\n\t\t\t `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t `idHost` int(11) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t `idItemProfile` int(11) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t `idItemHost` int(11) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t `datetime` datetime DEFAULT NULL,\r\n\t\t\t `valueOk` int(11) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t `valueFail` int(11) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t `datetimeAlert` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',\r\n\t\t\t `countAlert` int(11) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t PRIMARY KEY (`id`)\r\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); $deleteOld = $this->conexion->query("DELETE FROM `bm_alert` WHERE `datetime` < DATE_SUB(NOW(), INTERVAL 2 HOUR);"); $getProbeSQL = "SELECT PI.`id_item`, PI.`cycles`,PI.`maxTh`,PI.`minTh`,PV.`id_monitor`\r\n\t\t\t\tFROM `bm_profiles_item` PI\r\n\t\t\t\tLEFT JOIN `bm_profiles_values` PV ON PI.`id_item`=PV.`id_item`\r\n\t\t\t\tWHERE `thold`='true'"; $getProbeRESULT = $this->conexion->queryFetch($getProbeSQL); if ($getProbeRESULT) { $insertAlertSQL = "INSERT INTO `bm_alert` (`datetime`,`idHost`, `idItemProfile`, `idItemHost`, `valueOk`, `valueFail`) VALUES "; foreach ($getProbeRESULT as $keyThold => $thold) { $getAlertSQL = "SELECT `id_host`, `id_item`, COUNT(*) AS Total,\r\n\t\t\t\t\t\tSUM(IF(`value` >= " . $thold['minTh'] . " AND `value` <= " . $thold['maxTh'] . " , 1, 0 )) as 'ok',\r\n\t\t\t\t\t\tSUM(IF(`value` >= " . $thold['minTh'] . " AND `value` <= " . $thold['maxTh'] . " , 0, 1 )) as 'fail'\r\n\t\t\t\t\tFROM `bm_history`\r\n\t\t\t\t\tWHERE `id_item` = " . $thold['id_monitor'] . " AND `clock` > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 HOUR))\r\n\t\t\t\t\tGROUP BY `id_host`, `id_item` "; $getAlertRESULT = $this->conexion->queryFetch($getAlertSQL); if ($getAlertRESULT) { $insertValueAlert = array(); foreach ($getAlertRESULT as $keyAlert => $alert) { $insertValueAlert[] = "(NOW()," . $alert['id_host'] . " , " . $thold['id_item'] . ", " . $alert['id_item'] . ", " . $alert['ok'] . ", " . $alert['fail'] . ")"; } $insertAlertRESULT = $this->conexion->query($insertAlertSQL . join(',', $insertValueAlert) . " ON DUPLICATE KEY UPDATE `valueOk`=VALUES(`valueOk`), `valueOk`=VALUES(`valueOk`), `datetime` = NOW() "); } } } } public function finish() { $this->_crontab("serverFix_crontab", "finish"); } } $cmd = new Control(true, 'core.bi.node1.baking.cl', true); //Start Split $poller = new Poller($cmd); $poller->validStart(); $poller->start(); //$poller->finish();