fix automation components and rework some views and urls

This commit is contained in:
sadnub
2021-10-22 13:13:18 -04:00
parent aa4572f4d3
commit e87a42ebb6
8 changed files with 81 additions and 160 deletions

View File

@@ -5,4 +5,11 @@ const baseUrl = "/automation"
export async function sendPatchPolicyReset(payload) {
const { data } = await axios.post(`${baseUrl}/patchpolicy/reset/`, payload)
return data
}
export async function fetchPolicyChecks(id) {
try {
const { data } = await axios.get(`${baseUrl}/policies/${id}/checks/`)
return data
} catch (e) { console.error(e) }
}

View File

@@ -8,7 +8,7 @@
icon="fas fa-plus"
label="Add Task"
text-color="black"
@click="showAddTask = true"
@click="showAddTask"
/>
<q-btn v-if="!!selectedPolicy" dense flat push @click="getTasks" icon="refresh" />
<q-table
@@ -75,7 +75,7 @@
<!-- context menu -->
<q-menu context-menu>
<q-list dense style="min-width: 200px">
<q-item clickable v-close-popup @click="runTask(props.row.id, props.row.enabled)">
<q-item clickable v-close-popup @click="runTask(props.row)">
<q-item-section side>
<q-icon name="play_arrow" />
</q-item-section>
@@ -110,7 +110,7 @@
<q-td>
<q-checkbox
dense
@update:model-value="taskEnableorDisable(props.row.id, props.row.enabled)"
@update:model-value="editTask(props.row, { enabled: !props.row.enabled })"
v-model="props.row.enabled"
/>
</q-td>
@@ -118,7 +118,7 @@
<q-td>
<q-checkbox
dense
@update:model-value="taskAlert(props.row.id, 'Text', props.row.text_alert)"
@update:model-value="editTask(props.row, { text_alert: !props.row.text_alert })"
v-model="props.row.text_alert"
/>
</q-td>
@@ -126,7 +126,7 @@
<q-td>
<q-checkbox
dense
@update:model-value="taskAlert(props.row.id, 'Email', props.row.email_alert)"
@update:model-value="editTask(props.row, { email_alert: !props.row.email_alert })"
v-model="props.row.email_alert"
/>
</q-td>
@@ -134,7 +134,7 @@
<q-td>
<q-checkbox
dense
@update:model-value="taskAlert(props.row.id, 'Dashboard', props.row.dashboard_alert)"
@update:model-value="editTask(props.row, { dashboard_alert: !props.row.dashboard_alert })"
v-model="props.row.dashboard_alert"
/>
</q-td>
@@ -160,16 +160,6 @@
</template>
</q-table>
</div>
<!-- modals -->
<q-dialog v-model="showAddTask" position="top">
<AddAutomatedTask
:policypk="selectedPolicy"
@close="
getTasks();
showAddTask = false;
"
/>
</q-dialog>
</div>
</template>
@@ -182,14 +172,12 @@ import PolicyStatus from "@/components/automation/modals/PolicyStatus";
export default {
name: "PolicyAutomatedTasksTab",
mixins: [mixins],
components: { AddAutomatedTask },
props: {
selectedPolicy: !Number,
},
data() {
return {
tasks: [],
showAddTask: false,
columns: [
{ name: "enabled", align: "left", field: "enabled" },
{ name: "smsalert", field: "text_alert", align: "left" },
@@ -235,7 +223,7 @@ export default {
getTasks() {
this.$q.loading.show();
this.$axios
.get(`/automation/${this.selectedPolicy}/policyautomatedtasks/`)
.get(`/automation/policies/${this.selectedPolicy}/tasks/`)
.then(r => {
this.tasks = r.data;
this.$q.loading.hide();
@@ -244,45 +232,27 @@ export default {
this.$q.loading.hide();
});
},
taskEnableorDisable(pk, action) {
this.$q.loading.show();
const data = { id: pk, enableordisable: !action };
editTask(task, data) {
this.$axios
.patch(`/tasks/${pk}/automatedtasks/`, data)
.put(`/tasks/${task.pk}/`, data)
.then(r => {
this.getTasks();
this.$q.loading.hide();
this.notifySuccess("Task has edited successfully");
this.notifySuccess(r.data);
this.getTasks();
})
.catch(e => {
this.$q.loading.hide();
});
},
taskAlert(pk, alert_type, action) {
this.$q.loading.show();
const data = {
id: pk,
};
if (alert_type === "Email") {
data.email_alert = !action;
} else if (alert_type === "Text") {
data.text_alert = !action;
} else {
data.dashboard_alert = !action;
}
const act = !action ? "enabled" : "disabled";
this.$axios
.put(`/tasks/${pk}/automatedtasks/`, data)
.then(r => {
this.$q.loading.hide();
this.notifySuccess(`${alert_type} alerts ${act}`);
showAddTask() {
this.$q
.dialog({
component: AddAutomatedTask,
componentProps: {
parent: { policy: this.selectedPolicy },
},
})
.catch(e => {
this.$q.loading.hide();
});
.onOk(this.getTasks);
},
showEditTask(task) {
this.$q
@@ -292,9 +262,7 @@ export default {
task: task,
},
})
.onOk(() => {
this.getTasks();
});
.onOk(this.getTasks);
},
showStatus(task) {
this.$q.dialog({
@@ -313,7 +281,7 @@ export default {
this.$q.loading.show();
this.$axios
.put(`/automation/runwintask/${pk}/`)
.post(`/automation/tasks/${pk}/run/`)
.then(r => {
this.$q.loading.hide();
this.notifySuccess("The task was initated on all affected agents");
@@ -333,7 +301,7 @@ export default {
.onOk(() => {
this.$q.loading.show();
this.$axios
.delete(`/tasks/${pk}/automatedtasks/`)
.delete(`/tasks/${pk}/`)
.then(r => {
this.getTasks();
this.$q.loading.hide();

View File

@@ -4,43 +4,43 @@
<q-btn v-if="!!selectedPolicy" size="sm" color="grey-5" icon="fas fa-plus" label="Add Check" text-color="black">
<q-menu>
<q-list dense style="min-width: 200px">
<q-item clickable v-close-popup @click="showAddDialog('DiskSpaceCheck')">
<q-item clickable v-close-popup @click="showCheckModal('diskspace')">
<q-item-section side>
<q-icon size="xs" name="far fa-hdd" />
</q-item-section>
<q-item-section>Disk Space Check</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showAddDialog('PingCheck')">
<q-item clickable v-close-popup @click="showCheckModal('ping')">
<q-item-section side>
<q-icon size="xs" name="fas fa-network-wired" />
</q-item-section>
<q-item-section>Ping Check</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showAddDialog('CpuLoadCheck')">
<q-item clickable v-close-popup @click="showCheckModal('cpuload')">
<q-item-section side>
<q-icon size="xs" name="fas fa-microchip" />
</q-item-section>
<q-item-section>CPU Load Check</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showAddDialog('MemCheck')">
<q-item clickable v-close-popup @click="showCheckModal('memory')">
<q-item-section side>
<q-icon size="xs" name="fas fa-memory" />
</q-item-section>
<q-item-section>Memory Check</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showAddDialog('WinSvcCheck')">
<q-item clickable v-close-popup @click="showCheckModal('winsvc')">
<q-item-section side>
<q-icon size="xs" name="fas fa-cogs" />
</q-item-section>
<q-item-section>Windows Service Check</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showAddDialog('ScriptCheck')">
<q-item clickable v-close-popup @click="showCheckModal('script')">
<q-item-section side>
<q-icon size="xs" name="fas fa-terminal" />
</q-item-section>
<q-item-section>Script Check</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showAddDialog('EventLogCheck')">
<q-item clickable v-close-popup @click="showCheckModal('eventlog')">
<q-item-section side>
<q-icon size="xs" name="fas fa-clipboard-list" />
</q-item-section>
@@ -97,11 +97,11 @@
</template>
<!-- body slots -->
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer" @dblclick="showEditDialog(props.row)">
<q-tr :props="props" class="cursor-pointer" @dblclick="showCheckModal(props.row.check_type, props.row)">
<!-- context menu -->
<q-menu context-menu>
<q-list dense style="min-width: 200px">
<q-item clickable v-close-popup @click="showEditDialog(props.row)">
<q-item clickable v-close-popup @click="showCheckModal(props.row.check_type, props.row)">
<q-item-section side>
<q-icon name="edit" />
</q-item-section>
@@ -161,27 +161,15 @@
>See Status</span
>
</q-td>
<q-td v-if="props.row.assignedtask !== null && props.row.assignedtask.length === 1">{{
<q-td v-if="!!props.row.assignedtask && props.row.assignedtask.length === 1">{{
props.row.assignedtask[0].name
}}</q-td>
<q-td v-else-if="props.row.assignedtask">{{ props.row.assignedtask.length }} Tasks</q-td>
<q-td v-else-if="!!props.row.assignedtask">{{ props.row.assignedtask.length }} Tasks</q-td>
<q-td v-else></q-td>
</q-tr>
</template>
</q-table>
</div>
<!-- add/edit modals -->
<q-dialog v-model="showDialog" @hide="hideDialog">
<component
v-if="dialogComponent !== null"
:is="dialogComponent"
@close="hideDialog"
:policypk="selectedPolicy"
:checkpk="editCheckPK"
:mode="!!editCheckPK ? 'edit' : 'add'"
/>
</q-dialog>
</div>
</template>
@@ -198,15 +186,6 @@ import EventLogCheck from "@/components/checks/EventLogCheck";
export default {
name: "PolicyChecksTab",
components: {
DiskSpaceCheck,
PingCheck,
CpuLoadCheck,
MemCheck,
WinSvcCheck,
ScriptCheck,
EventLogCheck,
},
mixins: [mixins],
props: {
selectedPolicy: !Number,
@@ -214,9 +193,6 @@ export default {
data() {
return {
checks: [],
dialogComponent: null,
showDialog: false,
editCheck: null,
columns: [
{ name: "smsalert", field: "text_alert", align: "left" },
{ name: "emailalert", field: "email_alert", align: "left" },
@@ -241,7 +217,7 @@ export default {
getChecks() {
this.$q.loading.show();
this.$axios
.get(`/automation/${this.selectedPolicy}/policychecks/`)
.get(`/automation/policies/${this.selectedPolicy}/checks/`)
.then(r => {
this.checks = r.data;
this.$q.loading.hide();
@@ -266,7 +242,7 @@ export default {
const act = !action ? "enabled" : "disabled";
const color = !action ? "positive" : "warning";
this.$axios
.patch(`/checks/${id}/check/`, data)
.put(`/checks/${id}/`, data)
.then(r => {
this.$q.loading.hide();
this.$q.notify({
@@ -279,45 +255,6 @@ export default {
this.$q.loading.hide();
});
},
showAddDialog(component) {
this.dialogComponent = component;
this.showDialog = true;
},
showEditDialog(check) {
switch (check.check_type) {
case "diskspace":
this.dialogComponent = "DiskSpaceCheck";
break;
case "ping":
this.dialogComponent = "PingCheck";
break;
case "cpuload":
this.dialogComponent = "CpuLoadCheck";
break;
case "memory":
this.dialogComponent = "MemCheck";
break;
case "winsvc":
this.dialogComponent = "WinSvcCheck";
break;
case "script":
this.dialogComponent = "ScriptCheck";
break;
case "eventlog":
this.dialogComponent = "EventLogCheck";
break;
default:
return null;
}
this.editCheck = check;
this.showDialog = true;
},
hideDialog() {
this.getChecks();
this.showDialog = false;
this.dialogComponent = null;
this.editCheckPK = null;
},
deleteCheck(check) {
this.$q
.dialog({
@@ -328,7 +265,7 @@ export default {
.onOk(() => {
this.$q.loading.show();
this.$axios
.delete(`/checks/${check.id}/check/`)
.delete(`/checks/${check.id}/`)
.then(r => {
this.getChecks();
this.$q.loading.hide();
@@ -348,6 +285,28 @@ export default {
},
});
},
showCheckModal(type, check) {
let component;
if (type === "diskspace") component = DiskSpaceCheck;
else if (type === "memory") component = MemCheck;
else if (type === "cpuload") component = CpuLoadCheck;
else if (type === "ping") component = PingCheck;
else if (type === "winsvc") component = WinSvcCheck;
else if (type === "eventlog") component = EventLogCheck;
else if (type === "script") component = ScriptCheck;
else return;
this.$q
.dialog({
component: component,
componentProps: {
check: check,
parent: !check ? { policy: this.selectedPolicy } : undefined,
},
})
.onOk(this.getChecks);
},
},
created() {
this.getChecks();

View File

@@ -33,6 +33,7 @@
<template v-slot:body="props" :props="props">
<q-tr>
<!-- tds -->
<!-- agent hostname -->
<q-td>{{ props.row.hostname }}</q-td>
<!-- status icon -->
<q-td v-if="props.row.status === 'passing'">
@@ -88,7 +89,7 @@
<q-td v-else-if="props.row.check_type === 'eventlog'">
<span
style="cursor: pointer; text-decoration: underline"
@click="eventLogMoreInfo(props.row)"
@click="showEventInfo(props.row)"
class="eventlog-cell text-primary"
>output</span
>
@@ -104,10 +105,6 @@
</template>
</q-table>
</q-card-section>
<q-dialog v-model="showEventLogOutput" @hide="closeEventLogOutput">
<EventLogCheckOutput @close="closeEventLogOutput" :evtlogdata="evtLogData" />
</q-dialog>
</q-card>
</q-dialog>
</template>
@@ -119,9 +116,6 @@ import EventLogCheckOutput from "@/components/checks/EventLogCheckOutput";
export default {
name: "PolicyStatus",
emits: ["hide", "ok", "cancel"],
components: {
EventLogCheckOutput,
},
props: {
item: {
required: true,
@@ -138,8 +132,6 @@ export default {
},
data() {
return {
showEventLogOutput: false,
evtLogData: {},
data: [],
columns: [
{ name: "agent", label: "Hostname", field: "agent", align: "left", sortable: true },
@@ -183,7 +175,7 @@ export default {
getCheckData() {
this.$q.loading.show();
this.$axios
.patch(`/automation/policycheckstatus/${this.item.id}/check/`)
.get(`/automation/checks/${this.item.id}/status/`)
.then(r => {
this.$q.loading.hide();
this.data = r.data;
@@ -195,7 +187,7 @@ export default {
getTaskData() {
this.$q.loading.show();
this.$axios
.patch(`/automation/policyautomatedtaskstatus/${this.item.id}/task/`)
.get(`/automation/tasks/${this.item.id}/status/`)
.then(r => {
this.$q.loading.hide();
this.data = r.data;
@@ -204,14 +196,6 @@ export default {
this.$q.loading.hide();
});
},
closeEventLogOutput() {
this.showEventLogOutput = false;
this.evtLogdata = {};
},
closeScriptOutput() {
this.showScriptOutput = false;
this.scriptInfo = {};
},
pingInfo(check) {
this.$q.dialog({
title: check.readable_desc,
@@ -220,9 +204,13 @@ export default {
html: true,
});
},
eventLogMoreInfo(check) {
this.evtLogData = check;
this.showEventLogOutput = true;
showEventInfo(data) {
this.$q.dialog({
component: EventLogCheckOutput,
componentProps: {
evtLogData: data,
},
});
},
showScriptOutput(script) {
this.$q.dialog({

View File

@@ -2,7 +2,7 @@
<q-dialog ref="dialogRef" @hide="onDialogHide">
<q-card class="q-dialog-plugin" style="width: 60vw">
<q-bar>
{{ check ? `Edit Memory Check` : "Add Memory Check" }}
{{ check ? `Edit Service Check` : "Add Service Check" }}
<q-space />
<q-btn dense flat icon="close" v-close-popup>
<q-tooltip class="bg-white text-primary">Close</q-tooltip>

View File

@@ -240,7 +240,7 @@ export default {
// editing patch policy
if (this.editing) {
this.$axios
.put(`/automation/winupdatepolicy/${this.winupdatepolicy.id}/`, this.winupdatepolicy)
.put(`/automation/patchpolicy/${this.winupdatepolicy.id}/`, this.winupdatepolicy)
.then(response => {
this.$q.loading.hide();
this.$emit("close");
@@ -252,7 +252,7 @@ export default {
} else {
// adding patch policy
this.$axios
.post("/automation/winupdatepolicy/", this.winupdatepolicy)
.post("/automation/patchpolicy/", this.winupdatepolicy)
.then(response => {
this.$q.loading.hide();
this.$emit("close");
@@ -274,7 +274,7 @@ export default {
.onOk(() => {
this.$q.loading.show();
this.$axios
.delete(`/automation/winupdatepolicy/${policy.id}/`)
.delete(`/automation/patchpolicy/${policy.id}/`)
.then(r => {
this.$q.loading.hide();
this.$emit("close");

View File

@@ -184,7 +184,6 @@
<script>
// composition imports
import { ref, computed, watch, onMounted } from "vue";
import { useStore } from "vuex";
import { useDialogPluginComponent } from "quasar";
import { saveTask } from "@/api/tasks";
import { useScriptDropdown } from "@/composables/scripts";

View File

@@ -2,7 +2,7 @@
import { ref, onMounted } from "vue"
import { updateCheck, saveCheck } from "@/api/checks"
import { fetchAgentChecks } from "@/api/agents";
//import { fetchPolicyChecks } from "@/api/automation";
import { fetchPolicyChecks } from "@/api/automation";
import { formatCheckOptions } from "@/utils/format";
import { fetchAgent } from "@/api/agents"
import { isValidThreshold } from "@/utils/validation";