2024-04-28 19:24:00 +00:00
|
|
|
{{ define "settings" }}
|
|
|
|
<section class="p-5">
|
|
|
|
<form action="/settings/triggers/{{ .Trigger.Id }}" method="post">
|
|
|
|
<h2>Configuration</h2>
|
|
|
|
<label for="script">Script</label>
|
2024-05-25 11:45:25 +00:00
|
|
|
<textarea required id="script" name="script" class="sm:col-span-2 h-96">
|
2024-05-14 19:38:45 +00:00
|
|
|
{{ ScriptUnescapeString .Trigger.Script }}</textarea
|
2024-04-28 19:24:00 +00:00
|
|
|
>
|
|
|
|
<div
|
2024-05-23 16:33:30 +00:00
|
|
|
id="editor-script"
|
2024-05-25 11:45:25 +00:00
|
|
|
class="hidden sm:col-span-2 block w-full h-96 rounded-lg border border-gray-300 overflow-hidden"
|
2024-04-28 19:24:00 +00:00
|
|
|
></div>
|
2024-05-25 11:45:25 +00:00
|
|
|
<p class="sm:col-span-2">
|
2024-05-18 20:18:28 +00:00
|
|
|
The trigger script executes for every matching <code>target</code>'s
|
|
|
|
execution of <code>trigger</code>. The outcome of that
|
|
|
|
<code>trigger</code> is passed to the script as a
|
|
|
|
<code>outcome</code> object. Based on that the trigger script should
|
|
|
|
decide if an incident should either be created or closed.
|
2024-04-28 19:24:00 +00:00
|
|
|
</p>
|
|
|
|
<button type="submit" onclick="save()">Save</button>
|
|
|
|
</form>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<div class="flex md:flex-row flex-col gap-4 h-min">
|
|
|
|
<section class="p-5 flex-1">
|
|
|
|
<h2 class="mb-2 flex flex-row gap-2">
|
|
|
|
Status
|
2024-05-18 20:18:28 +00:00
|
|
|
{{ if eq .Trigger.State "ACTIVE" }}
|
2024-04-28 19:24:00 +00:00
|
|
|
<span
|
|
|
|
class="self-center h-fit w-fit px-2 text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800"
|
|
|
|
>
|
|
|
|
ACTIVE
|
|
|
|
</span>
|
2024-05-18 20:18:28 +00:00
|
|
|
{{ else if eq .Trigger.State "PAUSED" }}
|
2024-04-28 19:24:00 +00:00
|
|
|
<span
|
|
|
|
class="self-center h-fit w-fit px-2 text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800"
|
|
|
|
>
|
|
|
|
PAUSED
|
|
|
|
</span>
|
|
|
|
{{ end }}
|
|
|
|
</h2>
|
|
|
|
<p class="text-sm mb-2">
|
|
|
|
Pausing the trigger will stop it from executing. This can be useful in
|
|
|
|
cases of expected downtime. Or when the trigger is not needed anymore.
|
|
|
|
</p>
|
2024-05-18 20:18:28 +00:00
|
|
|
{{ if eq .Trigger.State "ACTIVE" }}
|
2024-04-28 19:24:00 +00:00
|
|
|
<a
|
|
|
|
class="block text-center py-2.5 px-5 me-2 mb-2 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100"
|
|
|
|
href="/settings/triggers/{{ .Trigger.Id }}/disable"
|
|
|
|
>Pause</a
|
|
|
|
>
|
2024-05-18 20:18:28 +00:00
|
|
|
{{ else if eq .Trigger.State "PAUSED" }}
|
2024-04-28 19:24:00 +00:00
|
|
|
<a
|
|
|
|
class="block text-center py-2.5 px-5 me-2 mb-2 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100"
|
|
|
|
href="/settings/triggers/{{ .Trigger.Id }}/enable"
|
|
|
|
>Resume</a
|
|
|
|
>
|
|
|
|
{{ end }}
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<section class="p-2 flex-1 border-4 border-red-300">
|
|
|
|
<h2 class="mb-2">Danger Zone</h2>
|
|
|
|
<p class="text-sm mb-2">Permanently delete this trigger.</p>
|
|
|
|
<a
|
|
|
|
class="block text-center focus:outline-none text-white bg-red-700 hover:bg-red-800 focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2"
|
|
|
|
href="/settings/triggers/{{ .Trigger.Id }}/delete"
|
|
|
|
>Delete</a
|
|
|
|
>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<table>
|
|
|
|
<caption>
|
|
|
|
History
|
|
|
|
<p>Last 10 executions of trigger script.</p>
|
|
|
|
</caption>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Status</th>
|
|
|
|
<th>Created At</th>
|
|
|
|
<th>Duration</th>
|
|
|
|
<th>Note</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{{ range .History }}
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<span
|
|
|
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full {{ if eq .Status "SUCCESS" }}
|
|
|
|
bg-green-100 text-green-800
|
|
|
|
{{ else }}
|
|
|
|
bg-red-100 text-red-800
|
|
|
|
{{ end }}"
|
|
|
|
>
|
|
|
|
{{ .Status }}
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
{{ .CreatedAt.Time.Format "2006-01-02 15:04:05" }}
|
|
|
|
</td>
|
|
|
|
<td>{ .Duration }</td>
|
|
|
|
<td class="whitespace-normal">
|
|
|
|
{{ .Note }}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{{ end }}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<script src="/static/monaco/vs/loader.js"></script>
|
2024-05-23 16:33:30 +00:00
|
|
|
<script>
|
|
|
|
const items = [{ name: "script", language: "javascript" }];
|
2024-04-28 19:24:00 +00:00
|
|
|
|
2024-05-23 16:33:30 +00:00
|
|
|
function save() {
|
|
|
|
for (const { name } of items) {
|
|
|
|
const elem = window.editors[name].getValue();
|
|
|
|
document.getElementById(name).value = elem;
|
|
|
|
}
|
|
|
|
}
|
2024-04-28 19:24:00 +00:00
|
|
|
|
2024-05-23 16:33:30 +00:00
|
|
|
window.editors = {};
|
2024-05-25 11:45:25 +00:00
|
|
|
for (const { name, language, options = {} } of items) {
|
2024-05-23 16:33:30 +00:00
|
|
|
const textarea = document.getElementById(name);
|
|
|
|
const editor = document.getElementById("editor-" + name);
|
2024-04-28 19:24:00 +00:00
|
|
|
|
2024-05-23 16:33:30 +00:00
|
|
|
editor.classList.remove("hidden");
|
|
|
|
textarea.hidden = true;
|
2024-04-28 19:24:00 +00:00
|
|
|
|
2024-05-23 16:33:30 +00:00
|
|
|
require.config({ paths: { vs: "/static/monaco/vs" } });
|
|
|
|
require(["vs/editor/editor.main"], function () {
|
|
|
|
window.editors[name] = monaco.editor.create(editor, {
|
|
|
|
value: textarea.value,
|
|
|
|
language: language,
|
|
|
|
minimap: { enabled: false },
|
|
|
|
codeLens: false,
|
|
|
|
contextmenu: false,
|
|
|
|
scrollBeyondLastLine: false,
|
2024-05-25 11:45:25 +00:00
|
|
|
...options,
|
2024-05-23 16:33:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
|
|
window.editors[name].layout();
|
|
|
|
});
|
|
|
|
resizeObserver.observe(editor);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
2024-04-28 19:24:00 +00:00
|
|
|
{{ end }}
|