2024-04-28 19:24:00 +00:00
|
|
|
{{ define "settings" }}
|
|
|
|
<section class="p-5">
|
|
|
|
<form action="/settings/triggers/create" method="post">
|
|
|
|
<label for="name">Name</label>
|
2024-05-14 19:38:45 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="name"
|
|
|
|
id="name"
|
|
|
|
value="Five subsequent failures trigger notification"
|
|
|
|
/>
|
2024-04-28 19:24:00 +00:00
|
|
|
<p>Name of the trigger can be anything.</p>
|
|
|
|
<label for="script">Script</label>
|
|
|
|
<textarea required id="script" name="script" class="h-96">
|
2024-05-14 19:38:45 +00:00
|
|
|
{{ ScriptUnescapeString .Example }}</textarea
|
2024-04-28 19:24:00 +00:00
|
|
|
>
|
|
|
|
<div
|
2024-05-23 16:33:30 +00:00
|
|
|
id="editor-script"
|
2024-04-28 19:24:00 +00:00
|
|
|
class="hidden block w-full h-96 rounded-lg border border-gray-300 overflow-hidden"
|
|
|
|
></div>
|
|
|
|
<p>
|
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()">Create</button>
|
|
|
|
</form>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<script src="/static/monaco/vs/loader.js"></script>
|
|
|
|
<script>
|
2024-05-23 16:33:30 +00:00
|
|
|
const items = [{ name: "script", language: "javascript" }];
|
2024-04-28 19:24:00 +00:00
|
|
|
|
|
|
|
function save() {
|
2024-05-23 16:33:30 +00:00
|
|
|
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 = {};
|
|
|
|
for (const { name, language } of items) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
|
|
|
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
|
|
window.editors[name].layout();
|
|
|
|
});
|
|
|
|
resizeObserver.observe(editor);
|
2024-04-28 19:24:00 +00:00
|
|
|
});
|
2024-05-23 16:33:30 +00:00
|
|
|
}
|
2024-04-28 19:24:00 +00:00
|
|
|
</script>
|
|
|
|
{{ end }}
|