ENHANCEMENT: taking number of days in account for failed notifications

This commit is contained in:
Jeroen De Meerleer 2021-08-03 17:23:41 +02:00
parent 282e37cf56
commit d2454d96ac
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
5 changed files with 25 additions and 10 deletions

View File

@ -128,8 +128,8 @@ function initContainerType()
}
function initRangeInput() {
document.querySelector('.range-input-errorlevel').addEventListener('input', event => {
document.querySelector('.range-value-errorlevel').innerHTML = event.target.value + '%';
document.querySelector('.range-input-fail-pct').addEventListener('input', event => {
document.querySelector('.range-value-fail-pct').innerHTML = event.target.value + '%';
})
}

View File

@ -28,9 +28,9 @@ class Job extends Repository
$job['service'] = $job['data']['service'] ?? '';
$job['norun'] = isset($job['lastrun']) && $job['nextrun'] > $job['lastrun'];
$job['running'] = $job['running'] != 0;
$failed = count($runRepo->getRunsForJob($job['id'], true));
$all = count($runRepo->getRunsForJob($job['id']));
$job['needschecking'] = $all > 0 && (($failed / $all) * 100) > $job['data']['errorlevel'];
$failed = count($runRepo->getRunsForJob($job['id'], true, $job['data']['fail-days']));
$all = count($runRepo->getRunsForJob($job['id'], false, $job['data']['fail-days']));
$job['needschecking'] = $all > 0 && (($failed / $all) * 100) > $job['data']['fail-pct'];
if(!empty($job['data']['containertype']) && $job['data']['containertype'] != 'none') {
$job['host-displayname'] = $job['data']['service'] . ' on ' . $job['data']['host'];
}
@ -406,7 +406,8 @@ class Job extends Repository
$values['data']['crontype'] = $values['crontype'];
$values['data']['hosttype'] = $values['hosttype'];
$values['data']['containertype'] = $values['containertype'];
$values['data']['errorlevel'] = $values['errorlevel'];
$values['data']['fail-pct'] = $values['fail-pct'] ?? 50;
$values['data']['fail-days'] = $values['fail-days'] ?? 7;
if(empty($values['data']['crontype'])) {
throw new \InvalidArgumentException("Crontype cannot be empty");

View File

@ -13,13 +13,17 @@ class Run extends Repository
const SUCCESS = 'S';
const MANUAL = 'M';
public function getRunsForJob(int $id, bool $onlyfailed = false, bool $ordered = true): array
public function getRunsForJob(int $id, bool $onlyfailed = false, int $maxage = NULL, bool $ordered = true): array
{
$runsSql = "SELECT * FROM run WHERE job_id = :job";
$params = [':job' => $id];
if ($onlyfailed) {
$runsSql .= ' AND flags LIKE "%' . Run::FAILED . '%"';
}
if($maxage !== NULL) {
$runsSql .= ' AND timestamp > :timestamp';
$params[':timestamp'] = time() - ($maxage * 24 * 60 * 60);
}
if ($ordered) $runsSql .= ' ORDER by timestamp DESC';
$runsStmt = $this->dbcon->prepare($runsSql);
$runsRslt = $runsStmt->executeQuery($params);

View File

@ -60,6 +60,11 @@
</div>
</div>
<div class="mb-3">
<label for="fail-days">Number of days calculated for fail percentage</label>
<input type="number" name="fail-days" class="form-control" id="fail-days" placeholder="7">
</div>
<h3>Job details</h3>
<div class="mb-3 btn-group croncategory-selector">
<div class="dropdown croncategory-group crontype-group">

View File

@ -47,15 +47,20 @@
</div>
<div class="mb-3">
<label for="errorlevel">Max fail percentage</label>
<label for="fail-pct">Max fail percentage</label>
<div class="input-group d-flex">
<div class="range-value range-value-errorlevel pe-1">{% if attribute(data, 'errorlevel') is not empty %}{{ attribute(data, 'errorlevel') }}{% else %}50{% endif %}%</div>
<div class="range-value range-value-fail-pct pe-1">{% if attribute(data, 'fail-pct') is not empty %}{{ attribute(data, 'fail-pct') }}{% else %}50{% endif %}%</div>
<div class="range-input ps-1 flex-grow-1">
<input type="range" name="errorlevel" class="form-range range-input-errorlevel" id="errorlevel" max="100" step="5" value="{% if attribute(data, 'errorlevel') is not empty %}{{ attribute(data, 'errorlevel') }}{% else %}50{% endif %}">
<input type="range" name="fail-pct" class="form-range range-input-fail-pct" id="fail-pct" max="100" step="5" value="{% if attribute(data, 'fail-pct') is not empty %}{{ attribute(data, 'fail-pct') }}{% else %}50{% endif %}">
</div>
</div>
</div>
<div class="mb-3">
<label for="fail-days">Number of days calculated for fail percentage</label>
<input type="number" name="fail-days" class="form-control" id="fail-days" placeholder="7" value="{% if attribute(data, 'fail-days') is not empty %}{{ attribute(data, 'fail-days') }}{% endif %}">
</div>
<h3>Job details</h3>
<div class="mb-3 btn-group croncategory-selector">
<div class="dropdown croncategory-group crontype-group{% if data.crontype != 'http' %} btn-group{% endif %}">