<commit_before><?php

define('clientID', "");
define('token', "");

/*
 *  You're clearly welcome to edit what comes later, but you shouldn't need to.
 *
 *  A few notes:
 *      - The script uses a sleep(5) before submitting the job and checking the first
 *      time, and then before every subsequent check. This is a long time in computing
 *      worlds, but remember that the server has to do a lot of work. Dropping this to
 *      zero is a great way to get throttled.
 *      - http_build_query() wories about escaping for us
 *      - Designed to integrate with Nagios it uses return codes 0, 2, and 3. Which
 *      represent Success, Failure, and Unknown respectively. This simple implementaiton
 *      doesn't present warn.
 *      - When the check fails it immediately requests a second check against that URL,
 *      including Traceroute, Ping, and DNS lookups. While the results of these lookups
 *      aren't available in the echo'd result, the link to them is. This should help
 *      diagnose problems.
 *
 *      Source: https://github.com/preinheimer/wiu-scripts
 *      Integrates with: http://api.wheresitup.com/ 
 */

if(!isset($argv[1]) OR !isset($argv[2]))
{
    echo "Usage: {$argv[0]} <server name> <check source> <maximum acceptable time in ms>\n";
    echo "Example: {$argv[0]} http://example.com newyork 2500\n";
    exit(3);
}

$uri = $argv[1];
$server = $argv[2];
$maxTime = $argv[3];

$jobID = submitJob($uri, $server, array('fast'));

$done = false;
$attemptCount = 0;

do {
    sleep(5);
    unset($ch);
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, "http://adev.wheresitup.com/v2/retrieve/$jobID");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Auth: Bearer " . clientID . ' ' . token));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    $results = json_decode($ret, true);
    
    //var_dump($results);
    
    if (isset($results['return']['summary'][$server]['fast']['status']))
    {
        $status = $results['return']['summary'][$server]['fast']['status'];
        $time = $results['return']['summary'][$server]['fast']['time'];
        if ($status != "success")
        {
            echo "[{$jobID}] Page load failure\n";
            return 2;
        }
        
        if ($time > $maxTime)
        {
            echo "[{$jobID}] Maxtime exceeded, limit was {$maxTime}ms, page took {$time}ms\n";
            exit(2);<commit_msg> - Different handling to support tools like cacti graphing over time<commit_after><?php

define('clientID', "");
define('token', "");

/*
 *  You're clearly welcome to edit what comes later, but you shouldn't need to.
 *
 *  A few notes:
 *      - The script uses a sleep(5) before submitting the job and checking the first
 *      time, and then before every subsequent check. This is a long time in computing
 *      worlds, but remember that the server has to do a lot of work. Dropping this to
 *      zero is a great way to get throttled.
 *      - http_build_query() wories about escaping for us
 *      - Designed to integrate with Nagios it uses return codes 0, 2, and 3. Which
 *      represent Success, Failure, and Unknown respectively. This simple implementaiton
 *      doesn't present warn.
 *      - When the check fails it immediately requests a second check against that URL,
 *      including Traceroute, Ping, and DNS lookups. While the results of these lookups
 *      aren't available in the echo'd result, the link to them is. This should help
 *      diagnose problems.
 *
 *      Source: https://github.com/preinheimer/wiu-scripts
 *      Integrates with: http://api.wheresitup.com/ 
 */

if(!isset($argv[1]) OR !isset($argv[2]))
{
    echo "Usage: {$argv[0]} <server name> <check source> [maximum acceptable time in ms]\n";
    echo "Example: {$argv[0]} http://example.com newyork 2500\n";
    echo "or\n";
    echo "Example: {$argv[0]} http://example.com newyork\n";
    exit(3);
}

$uri = $argv[1];
$server = $argv[2];
$maxTime = isset($argv[3]) ? $argv[3] : null;

$jobID = submitJob($uri, $server, array('fast'));

$done = false;
$attemptCount = 0;

do {
    sleep(5);
    unset($ch);
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, "http://adev.wheresitup.com/v2/retrieve/$jobID");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Auth: Bearer " . clientID . ' ' . token));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    $results = json_decode($ret, true);
    
    //var_dump($results);
    
    if (isset($results['return']['summary'][$server]['fast']['status']))
    {
        $status = $results['return']['summary'][$server]['fast']['status'];
        $time = $results['return']['summary'][$server]['fast']['time'];
        if ($status != "success")
        {
            echo "[{$jobID}] Page load failure\n";
            return 2;
        }
        
        //Handle people who just want the time, not in nagios
        if (is_null($maxTime))
        {
            echo $time;
            return 0;
        }
        
        if ($time > $maxTime)
        {
            echo "[{$jobID}] Maxtime exceeded, limit was {$maxTime}ms, page took {$time}ms\n";
            exit(2);
{'fraction_non_alphanumeric': 0.14872685185185186, 'fraction_numerical': 0.009066358024691358, 'mean_word_length': 2.823746312684366, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5169900', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1586, 'n_words': 508}