Added expected return value
This commit is contained in:
parent
b44b25c92e
commit
fc51df695d
|
@ -63,6 +63,7 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||
$host = $_POST['host'];
|
||||
$name = $_POST['name'];
|
||||
$delay = $_POST['delay'];
|
||||
$expected = $_POST['expected'];
|
||||
$nextrunObj = new DateTime($_POST['nextrun']);
|
||||
$nextrun = $nextrunObj->getTimestamp();
|
||||
|
||||
|
@ -76,8 +77,8 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||
}
|
||||
|
||||
|
||||
$stmt = $db->prepare("INSERT INTO jobs(user, name, url, host, delay, nextrun) VALUES(?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute(array($_SESSION["userID"], $name, $url, $host, $delay, $nextrun));
|
||||
$stmt = $db->prepare("INSERT INTO jobs(user, name, url, host, delay, nextrun, expected) VALUES(?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute(array($_SESSION["userID"], $name, $url, $host, $delay, $nextrun, $expected));
|
||||
|
||||
header("location:addjob.php?message=added");
|
||||
exit;
|
||||
|
|
|
@ -40,6 +40,7 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") {
|
|||
$url = $jobnameResult[0]['url'];
|
||||
$host = $jobnameResult[0]['host'];
|
||||
$delay = $jobnameResult[0]['delay'];
|
||||
$expected = $jobnameResult[0]['expected'];
|
||||
$nextrun = date("m/d/Y h:i A", $jobnameResult[0]['nextrun']);
|
||||
|
||||
|
||||
|
@ -59,7 +60,7 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") {
|
|||
}
|
||||
|
||||
|
||||
echo $twig->render('editjob.html.twig', array("name" => $name, "url" => $url, "host" => $host, "delay" => $delay, "nextrun" => $nextrun, "jobID" => $jobID, "error" => $error));
|
||||
echo $twig->render('editjob.html.twig', array("name" => $name, "url" => $url, "host" => $host, "delay" => $delay, "expected" => $expected, nextrun => $nextrun, "jobID" => $jobID, "error" => $error));
|
||||
}
|
||||
elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
|
||||
|
@ -72,6 +73,7 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||
$name = $_POST['name'];
|
||||
$delay = $_POST['delay'];
|
||||
$host = $_POST['host'];
|
||||
$expected = $_POST['expected'];
|
||||
$nextrunObj = new DateTime($_POST['nextrun']);
|
||||
$nextrun = $nextrunObj->getTimestamp();
|
||||
|
||||
|
@ -85,8 +87,8 @@ elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||
}
|
||||
|
||||
|
||||
$stmt = $db->prepare("UPDATE jobs SET name = ?, url = ?, host = ?, delay = ?, nextrun = ? WHERE jobID = ?");
|
||||
$stmt->execute(array($name, $url, $host, $delay, $nextrun, $jobID));
|
||||
$stmt = $db->prepare("UPDATE jobs SET name = ?, url = ?, host = ?, delay = ?, nextrun = ?, expected = ? WHERE jobID = ?");
|
||||
$stmt->execute(array($name, $url, $host, $delay, $nextrun, $expected, $jobID));
|
||||
|
||||
header("location:overview.php?message=edited");
|
||||
exit;
|
||||
|
|
|
@ -46,4 +46,8 @@ $(document).ready(function() {
|
|||
$('#resultmodal').modal('show');
|
||||
});
|
||||
});
|
||||
$("body").on("change", ".input[name=url]", function() {
|
||||
$(".label[for=expected]").html("Capture services after reboot? (1: yes; 0: no)");
|
||||
$(".input[name=url]").attr("placeholder", "1");
|
||||
})
|
||||
});
|
||||
|
|
|
@ -69,7 +69,7 @@ if (filter_var($jobnameResult[0]["url"], FILTER_VALIDATE_URL)) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if($nosave !== true) {
|
||||
if($nosave !== true && $statuscode != $jobnameResult[0]["expected"]) {
|
||||
$stmt = $db->prepare("INSERT INTO runs(job, statuscode, result, timestamp) VALUES(?, ?, ?, ?)");
|
||||
$stmt->execute(array($jobID, $statuscode, $body, $timestamp));
|
||||
}
|
||||
|
|
|
@ -56,6 +56,10 @@
|
|||
<input type="text" class="form-control" name="nextrun">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="expected">Expected exit code</label>
|
||||
<input type="text" name="expected" class="form-control" id="host" placeholder="200">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -51,6 +51,10 @@
|
|||
<input type="text" class="form-control" name="nextrun" value="{{ nextrun }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="expected">Expected exit code</label>
|
||||
<input type="text" name="expected" class="form-control" id="host" value="{{ expected }}">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</form>
|
||||
|
||||
|
|
16
webcron.php
16
webcron.php
|
@ -40,7 +40,7 @@ if (file_exists("cache/get-services.trigger")) {
|
|||
$rebootjobs = unserialize(file_get_contents("cache/get-services.trigger"));
|
||||
|
||||
foreach($rebootjobs as $job) {
|
||||
|
||||
if($job['expected'] != 0) {
|
||||
$services = array();
|
||||
$url = "ssh " . $job['host'] . " '" . "sudo systemctl list-units | cat" . "' 2>&1";
|
||||
exec($url, $services);
|
||||
|
@ -48,19 +48,14 @@ if (file_exists("cache/get-services.trigger")) {
|
|||
|
||||
$stmt = $db->prepare("INSERT INTO runs(job, statuscode, result, timestamp) VALUES(?, ?, ?, ?)");
|
||||
$stmt->execute(array($job['jobID'], '200', $services, time()));
|
||||
|
||||
$nextrun = ($job['nextrun'] < time()) ? $job['nextrun'] + $job['delay'] : $job['nextrun'];
|
||||
if ($nextrun < time() ) { $nextrun = time() + $job['delay']; }
|
||||
|
||||
$nexttime = $db->prepare("UPDATE jobs SET nextrun = ? WHERE jobID = ?");
|
||||
$nexttime->execute(array($nextrun, $result["jobID"]));
|
||||
}
|
||||
}
|
||||
unlink("cache/get-services.trigger");
|
||||
unlink("cache/reboot-time.trigger");
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $db->query('SELECT jobID, url, host, delay, nextrun FROM jobs WHERE nextrun < ' . time());
|
||||
$stmt = $db->query('SELECT jobID, url, host, delay, nextrun, expected FROM jobs WHERE nextrun < ' . time());
|
||||
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$client = new \GuzzleHttp\Client();
|
||||
|
||||
|
@ -97,16 +92,15 @@ foreach ($results as $result) {
|
|||
|
||||
}
|
||||
}
|
||||
if($nosave !== true) {
|
||||
if($nosave !== true && $statuscode != $result["expected"]) {
|
||||
$stmt = $db->prepare("INSERT INTO runs(job, statuscode, result, timestamp) VALUES(?, ?, ?, ?)");
|
||||
$stmt->execute(array($result['jobID'], $statuscode, $body, time()));
|
||||
|
||||
}
|
||||
$nextrun = $result['nextrun'] + $result['delay'];
|
||||
if ($nextrun < time() ) { $nextrun = time() + $result['delay']; }
|
||||
|
||||
$nexttime = $db->prepare("UPDATE jobs SET nextrun = ? WHERE jobID = ?");
|
||||
$nexttime->execute(array($nextrun, $result["jobID"]));
|
||||
}
|
||||
$nosave = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user