Beispiel #1
0
function DoTest($test, $param, $hostname = "", $timeout = -1, $params = 0, $nodeid = "")
{
    global $NATS;
    if (!is_array($params)) {
        $params = array();
        for ($a = 0; $a < 10; $a++) {
            $params[$a] = "";
        }
    }
    switch ($test) {
        case "web":
        case "wsize":
            // Don't bother with pre-resolution as size only
            return WebTest($param, $timeout);
            break;
            /* -- modularised
            	case "tcp": // nb TCP does not support timeouts currently
            		$ip=ip_lookup($hostname);
            		if ($ip=="0") return 0;
            		$fp=@fsockopen($ip,$param);
            		if ($fp<=0) return 0;
            		@fclose($fp);
            		return 1;
            		break;
            	*/
        /* -- modularised
        	case "tcp": // nb TCP does not support timeouts currently
        		$ip=ip_lookup($hostname);
        		if ($ip=="0") return 0;
        		$fp=@fsockopen($ip,$param);
        		if ($fp<=0) return 0;
        		@fclose($fp);
        		return 1;
        		break;
        	*/
        case "wtime":
            $timer = new TFNTimer();
            // Do a pre-lookup
            $ip = url_lookup($param);
            if ($ip == "0") {
                return -1;
            }
            // dns lookup failed
            $timer->Start();
            $r = WebTest($param, $timeout);
            $elapsedTime = $timer->Stop();
            $elapsedTime = round($elapsedTime, 4);
            if ($r < 0) {
                return -1;
            }
            // open failed
            if ($r == 0) {
                return -2;
            }
            // no chars shown as returned
            if ($elapsedTime <= 0) {
                return 0.0001;
            }
            return $elapsedTime;
            break;
        case "host":
            $timer = new TFNTimer();
            if (preg_match("/[a-zA-Z]/", $param) > 0) {
                $is_ip = false;
            } else {
                $is_ip = true;
            }
            $timer->Start();
            if ($is_ip) {
                $result = gethostbyaddr($param);
            } else {
                $result = gethostbyname($param);
            }
            $elapsedTime = $timer->Stop();
            if ($result == $param) {
                // lookup failed
                return -1;
            }
            if ($result == "") {
                // lookup failed
                return -1;
            }
            $elapsedTime = round($elapsedTime, 4);
            if ($elapsedTime <= 0) {
                return 0.0001;
            }
            return $elapsedTime;
            break;
        case "testloop":
            return $param;
            break;
        case "testrand":
            mt_srand(microtime() * 1000000);
            if ($param == "" || $param == 0) {
                $param = 100;
            }
            return mt_rand(0, $param);
            break;
        case "ping":
            return PingTest($param, $timeout);
            break;
        default:
            if (isset($NATS)) {
                if (isset($NATS->Tests->QuickList[$test])) {
                    $NATS->Tests->Tests[$test]->Create();
                    return $NATS->Tests->Tests[$test]->instance->DoTest($test, $param, $hostname, $timeout, $params);
                }
            }
    }
    return -1;
    // did not run any test so untested
}
Beispiel #2
0
 $pingpassed = false;
 // this will only be set to true if a test is done and passes - for the "child" nodes
 if ($row['pingtest'] && $dotests) {
     db(" Ping Test: Yes");
     $NATS->Event("Tester " . $trid . " Pinging Node " . $row['nodeid'], 10, "Tester", "Ping");
     $ptr = PingTest($row['hostname']);
     $NATS->Event("Tester " . $trid . " Ping Node " . $row['nodeid'] . " Returned " . $ptr, 10, "Tester", "Ping");
     db(" Ping Returned: " . $ptr);
     if ($ptr <= 0 && $NATS->Cfg->Get("test.icmp.attempts", "2") > 1) {
         $att = $NATS->Cfg->Get("test.icmp.attempts", "2");
         for ($a = 2; $a <= $att; $a++) {
             // try again...
             test_sleep();
             db(" Trying Ping Again - X" . $a);
             $NATS->Event("Tester " . $trid . " Ping X" . $a . " Node " . $row['nodeid'], 10, "Tester", "Ping");
             $ptr = PingTest($row['hostname']);
             $NATS->Event("Tester " . $trid . " Ping Node " . $row['nodeid'] . " Returned " . $ptr, 10, "Tester", "Ping");
             db(" Ping Returned: " . $ptr);
             if ($ptr > 0) {
                 $a = $att + 1;
             }
             // break out of the loop
         }
     }
     if ($ptr <= 0) {
         $alertlevel = 2;
         db(" Ping Test: Failed");
         $alerts[$alertc++] = "ping failed";
         $pal = 2;
     } else {
         db(" Ping Test: Passed");