//die();
    }
    // Add the current down check
    $currentDown[$alert['id']] = time();
} elseif ($alert['status'] === "Up") {
    // Get downtime
    $alert['downtime'] = calcTimeDifference($currentDown[$alert['id']]);
    // Now that its up, delete the down record
    unset($currentDown[$alert['id']]);
}
// Write which hosts are currently down
writeCurrentDown($currentDown);
// Generate the message
$message = getMessage($alert);
// Post message to twitter
postTwitter($message);
/**
* Calculates how long the check was down for. I spent way to much time on this function
* @param  int $dt What time the check went down at in seconds since epoch
* @return string Properly formated time difference
*/
function calcTimeDifference($dt)
{
    // Used if there is no downtime record
    if (is_null($dt)) {
        return "";
    }
    $downDt = new DateTime("@{$dt}");
    $nowDt = new DateTime();
    $day = $downDt->diff($nowDt)->format('%a');
    $hour = $downDt->diff($nowDt)->format('%h');
Beispiel #2
0
        return false;
    }
}
function getCaminhoImagem($conn)
{
    $row = getImage($conn);
    $caminho = $row["IMG"];
    $filename = "/home/slutt241/www/images/" . $caminho;
    if ($row["TIPO"] == 'GIF') {
        $filename = $caminho;
    }
    return $filename;
}
function getImage($conn)
{
    $sql = "SELECT FLOOR(MAX(img.ID) * RAND()) AS ID\n            FROM IMAGENS img\n            INNER JOIN SITES s ON img.SITE_ID = s.ID\n            WHERE s.TIPO <> 'VID' AND s.ORIENTACAO = 'STR'";
    $stmt = $conn->query($sql);
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    $sql = "SELECT i.CAMINHO_IMAGEM AS IMG, s.TIPO AS TIPO\n            FROM IMAGENS i\n            INNER JOIN SITES s ON i.SITE_ID = s.ID\n            WHERE i.ID = " . $row["ID"];
    $stmt = $conn->query($sql);
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    if (empty($row) || empty($row["IMG"])) {
        $row = getImage($conn);
    }
    return $row;
}
// Inicia...
$counter = 0;
while (postTwitter() !== TRUE && $counter++ < 5) {
    sleep(3);
}