/** * Performs all switches ping test and returns dead devices array * * @global object $ubillingConfig * @return array */ function zb_SwitchesRepingAll() { global $ubillingConfig; $altCfg = $ubillingConfig->getAlter(); $allswitches = zb_SwitchesGetAllLocationOrder(); $deadswitches = array(); $deathTime = zb_SwitchesGetAllDeathTime(); if (!empty($allswitches)) { foreach ($allswitches as $io => $eachswitch) { if (!ispos($eachswitch['desc'], 'NP')) { if (!zb_PingICMP($eachswitch['ip'])) { $secondChance = zb_PingICMP($eachswitch['ip']); if (!$secondChance) { $lastChance = zb_PingICMP($eachswitch['ip']); if (!$lastChance) { if (empty($altCfg['SWITCH_PING_CUSTOM_SCRIPT'])) { //yep, switch looks like it really down $deadswitches[$eachswitch['ip']] = $eachswitch['location']; if (!isset($deathTime[$eachswitch['ip']])) { zb_SwitchDeathTimeSet($eachswitch['ip']); } } else { //really last-last chance $customTestCommand = $altCfg['SWITCH_PING_CUSTOM_SCRIPT'] . ' ' . $eachswitch['ip']; $customScriptRun = shell_exec($customTestCommand); $customScriptRun = trim($customScriptRun); if ($customScriptRun != '1') { $deadswitches[$eachswitch['ip']] = $eachswitch['location']; if (!isset($deathTime[$eachswitch['ip']])) { zb_SwitchDeathTimeSet($eachswitch['ip']); } } else { zb_SwitchDeathTimeResurrection($eachswitch['ip']); } } } else { zb_SwitchDeathTimeResurrection($eachswitch['ip']); } } else { zb_SwitchDeathTimeResurrection($eachswitch['ip']); } } else { zb_SwitchDeathTimeResurrection($eachswitch['ip']); } } } } $newdata = serialize($deadswitches); zb_StorageSet('SWDEAD', $newdata); return $deadswitches; }
private function doAction($taskID = NULL) { if (!empty($taskID)) { switch ($this->taskData[$taskID]['checktype']) { //do the system icmp ping case 'icmpping': if (!empty($this->taskData[$taskID]['param'])) { $result = zb_PingICMP($this->taskData[$taskID]['param']); $storeValue = $result ? 'true' : 'false'; $this->setOldValue($taskID, $storeValue); $this->setCurValue($taskID, $storeValue); } else { throw new Exception(self::PARAM_EX . "ICMPPING"); } break; //run some script //run some script case 'script': if (!empty($this->taskData[$taskID]['param'])) { $command = $this->taskData[$taskID]['param']; $result = shell_exec($command); $result = trim($result); $this->setOldValue($taskID, $result); $this->setCurValue($taskID, $result); } else { throw new Exception(self::PARAM_EX . "SCRIPT"); } break; //do the tcp ping via some port //do the tcp ping via some port case 'tcpping': if (!empty($this->taskData[$taskID]['param'])) { if (ispos($this->taskData[$taskID]['param'], ':')) { $tcpPingData = explode(':', $this->taskData[$taskID]['param']); $tcpPingHost = $tcpPingData[0]; $tcpPingPort = $tcpPingData[1]; $tcpPingTimeout = 2; @($connection = fsockopen($tcpPingHost, $tcpPingPort, $tcperrno, $tcperrstr, $tcpPingTimeout)); if (!$connection) { $result = false; } else { $result = true; } $storeValue = $result ? 'true' : 'false'; $this->setOldValue($taskID, $storeValue); $this->setCurValue($taskID, $storeValue); } else { throw new Exception(self::PARAMFMT_EX . "TCPPING"); } } else { throw new Exception(self::PARAM_EX . "TCPPING"); } break; // gets some user traffic by his login // gets some user traffic by his login case 'getusertraff': if (!empty($this->taskData[$taskID]['param'])) { $userLoging = mysql_real_escape_string($this->taskData[$taskID]['param']); $traffQuery = "SELECT SUM(`D0`+`U0`) from `users` WHERE login='******'"; $traffData = simple_query($traffQuery); $result = $traffData['SUM(`D0`+`U0`)']; $this->setOldValue($taskID, $result); $this->setCurValue($taskID, $result); } else { throw new Exception(self::PARAM_EX . "GETUSERTRAFF"); } break; //check is some file exist? //check is some file exist? case 'fileexists': if (!empty($this->taskData[$taskID]['param'])) { $result = file_exists($this->taskData[$taskID]['param']); $storeValue = $result ? 'true' : 'false'; $this->setOldValue($taskID, $storeValue); $this->setCurValue($taskID, $storeValue); } else { throw new Exception(self::PARAM_EX . "FILEEXISTS"); } break; } } else { $result = 0; } return $result; }