Added most framework for Policies in Checks and Tasks. Added MongoDB to docker setup and configured for MeshCentral

This commit is contained in:
Josh Krawczyk
2020-04-19 17:54:27 -04:00
parent fefb74815b
commit 4ca723a3f1
16 changed files with 338 additions and 27 deletions

View File

@@ -183,6 +183,7 @@ export default {
policyRowSelected(pk) {
this.$store.commit("setSelectedPolicy", pk);
this.$store.dispatch("loadPolicyChecks", pk);
this.$store.dispatch("loadPolicyAutomatedTasks", pk);
},
clearRow() {
this.$store.commit("setSelectedPolicy", null);

View File

@@ -0,0 +1,223 @@
<template>
<div v-if="Object.keys(automatedTasks).length === 0">No Tasks</div>
<div class="row" v-else>
<div class="col-12">
<q-btn size="sm" color="grey-5" icon="fas fa-plus" label="Add Task" text-color="black" @click="showAddAutomatedTask = true" />
<q-btn dense flat push @click="refreshTasks(automatedTasks.pk)" icon="refresh" />
<template v-if="tasks === undefined || tasks.length === 0">
<p>No Tasks</p>
</template>
<template v-else>
<q-table
dense
class="autotasks-tbl-sticky"
:data="tasks"
:columns="columns"
:row-key="row => row.id"
binary-state-sort
:pagination.sync="pagination"
hide-bottom
>
<!-- header slots -->
<template v-slot:header-cell-enabled="props">
<q-th auto-width :props="props">
<small>Enabled</small>
</q-th>
</template>
<!-- body slots -->
<template slot="body" slot-scope="props" :props="props">
<q-tr @contextmenu="editTaskPk = props.row.id">
<!-- 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-section side>
<q-icon name="play_arrow" />
</q-item-section>
<q-item-section>Run task now</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="showEditAutomatedTask = true">
<q-item-section side>
<q-icon name="edit" />
</q-item-section>
<q-item-section>Edit</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="deleteTask(props.row.name, props.row.id)">
<q-item-section side>
<q-icon name="delete" />
</q-item-section>
<q-item-section>Delete</q-item-section>
</q-item>
<q-separator></q-separator>
<q-item clickable v-close-popup>
<q-item-section>Close</q-item-section>
</q-item>
</q-list>
</q-menu>
<!-- tds -->
<q-td>
<q-checkbox
dense
@input="taskEnableorDisable(props.row.id, props.row.enabled)"
v-model="props.row.enabled"
/>
</q-td>
<q-td>{{ props.row.name }}</q-td>
<q-td v-if="props.row.retcode || props.row.stdout || props.row.stderr">
<span
style="cursor:pointer;color:blue;text-decoration:underline"
@click="scriptMoreInfo(props.row)"
>output</span>
</q-td>
<q-td v-else>Awaiting output</q-td>
<q-td v-if="props.row.last_run">{{ props.row.last_run }}</q-td>
<q-td v-else>Has not run yet</q-td>
<q-td>{{ props.row.schedule }}</q-td>
<q-td>{{ props.row.assigned_check }}</q-td>
</q-tr>
</template>
</q-table>
</template>
</div>
<!-- modals -->
<q-dialog v-model="showAddAutomatedTask" position="top">
<AddAutomatedTask @close="showAddAutomatedTask = false" />
</q-dialog>
<q-dialog v-model="showScriptOutput">
<ScriptOutput @close="showScriptOutput = false; scriptInfo = {}" :scriptInfo="scriptInfo" />
</q-dialog>
</div>
</template>
<script>
import axios from "axios";
import { mapState } from "vuex";
import { mapGetters } from "vuex";
import mixins from "@/mixins/mixins";
import AddAutomatedTask from "@/components/modals/automation/AddAutomatedTask";
import ScriptOutput from "@/components/modals/checks/ScriptOutput";
export default {
name: "AutomatedTasksTab",
components: { AddAutomatedTask, ScriptOutput },
mixins: [mixins],
data() {
return {
showAddAutomatedTask: false,
showEditAutomatedTask: false,
showScriptOutput: false,
editTaskPk: null,
showScriptOutput: false,
scriptInfo: {},
columns: [
{ name: "enabled", align: "left", field: "enabled" },
{ name: "name", label: "Name", field: "name", align: "left" },
{
name: "moreinfo",
label: "More Info",
field: "more_info",
align: "left"
},
{
name: "datetime",
label: "Last Run Time",
field: "last_run",
align: "left"
},
{
name: "schedule",
label: "Schedule",
field: "schedule",
align: "left"
},
{
name: "assignedcheck",
label: "Assigned Check",
field: "assigned_check",
align: "left"
}
],
pagination: {
rowsPerPage: 9999
}
};
},
methods: {
taskEnableorDisable(pk, action) {
const data = { enableordisable: action };
axios
.patch(`/automation/${pk}/automatedtasks/`, data)
.then(r => {
this.$store.dispatch("loadPolicyAutomatedTasks", this.automatedTasks.pk);
this.notifySuccess(r.data);
})
.catch(e => this.notifyError("Something went wrong"));
},
refreshTasks(id) {
this.$store.dispatch("loadPolicyAutomatedTasks", id);
},
scriptMoreInfo(props) {
this.scriptInfo = props;
this.showScriptOutput = true;
},
runTask(pk, enabled) {
if (!enabled) {
this.notifyError("Task cannot be run when it's disabled. Enable it first.");
return;
}
axios
.get(`/automation/runwintask/${pk}/`)
.then(r => this.notifySuccess(r.data))
.catch(() => this.notifyError("Something went wrong"));
},
deleteTask(name, pk) {
this.$q
.dialog({
title: "Are you sure?",
message: `Delete ${name} task`,
cancel: true,
persistent: true
})
.onOk(() => {
axios
.delete(`/automation/${pk}/automatedtasks/`)
.then(r => {
this.$store.dispatch("loadPolicyChecks", this.automatedTasks.pk);
this.notifySuccess(r.data);
})
.catch(e => this.notifyError("Something went wrong"));
});
}
},
computed: {
...mapGetters(["selectedPolicyPk"]),
...mapState({
automatedTasks: state => state.policyAutomatedTasks
}),
tasks() {
return this.automatedTasks.autotasks;
}
}
};
</script>
<style lang="stylus">
.autotasks-tbl-sticky {
.q-table__middle {
max-height: 25vh;
}
.q-table__top, .q-table__bottom, thead tr:first-child th {
background-color: #f5f4f2;
}
thead tr:first-child th {
position: sticky;
top: 0;
opacity: 1;
z-index: 1;
}
}
</style>

View File

@@ -12,23 +12,29 @@
no-caps
>
<q-tab name="checks" icon="fas fa-check-double" label="Checks" />
<q-tab name="tasks" icon="fas fa-check-double" label="Tasks" />
</q-tabs>
<q-separator />
<q-tab-panels v-model="subtab" :animated="false">
<q-tab-panel name="checks">
<PolicyChecksTab />
</q-tab-panel>
<q-tab-panel name="tasks">
<PolicyAutomatedTasksTab />
</q-tab-panel>
</q-tab-panels>
</div>
</template>
<script>
import PolicyChecksTab from '@/components/PolicyChecksTab';
import PolicyAutomatedTasksTab from '@/components/PolicyAutomatedTasksTab';
export default {
name: "PolicySubTableTabs",
components: {
PolicyChecksTab,
PolicyAutomatedTasksTab,
},
data() {
return {

View File

@@ -56,7 +56,7 @@ export default {
pk = (this.policypk) ? {policy: policypk} : {pk: agentpk}
const data = {
pk,
...pk,
check_type: "cpuload",
threshold: this.threshold,
failure: this.failure

View File

@@ -45,7 +45,7 @@ import { mapState } from "vuex";
import mixins from "@/mixins/mixins";
export default {
name: "AddDiskSpaceCheck",
props: ["agentpk"],
props: ["agentpk", "policypk"],
mixins: [mixins],
data() {
return {
@@ -58,14 +58,16 @@ export default {
},
methods: {
getDisks() {
axios.get(`/checks/getdisks/${this.agentpk}/`).then(r => {
axios.get(`/checks/getdisks/policies/`).then(r => {
this.disks = Object.keys(r.data);
this.firstdisk = Object.keys(r.data)[0];
});
},
addCheck() {
pk = (this.policypk) ? {policy: policypk} : {pk: agentpk}
const data = {
pk: this.agentpk,
...pk,
check_type: "diskspace",
disk: this.firstdisk,
threshold: this.threshold,
@@ -75,7 +77,13 @@ export default {
.post("/checks/addstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess(`Disk check for drive ${data.disk} was added!`);
})
.catch(e => this.notifyError(e.response.data.error));

View File

@@ -42,7 +42,7 @@ import { mapState } from "vuex";
import mixins from "@/mixins/mixins";
export default {
name: "AddMemCheck",
props: ["agentpk"],
props: ["agentpk", "policypk"],
mixins: [mixins],
data() {
return {
@@ -53,8 +53,10 @@ export default {
},
methods: {
addCheck() {
pk = (this.policypk) ? {policy: policypk} : {pk: agentpk}
const data = {
pk: this.agentpk,
...pk,
check_type: "mem",
threshold: this.threshold,
failure: this.failure
@@ -63,7 +65,13 @@ export default {
.post("/checks/addstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess("Memory check was added!");
})
.catch(e => this.notifyError(e.response.data.error));

View File

@@ -66,7 +66,7 @@ export default {
name: this.pingname,
ip: this.pingip,
};
console.log(data)
axios.post("/checks/addstandardcheck/", data)
.then(r => {
this.$emit("close");

View File

@@ -65,7 +65,7 @@ import { mapGetters } from "vuex";
import mixins from "@/mixins/mixins";
export default {
name: "AddScriptCheck",
props: ["agentpk"],
props: ["agentpk", "policypk"],
mixins: [mixins],
data() {
return {
@@ -80,8 +80,10 @@ export default {
this.$store.dispatch("getScripts");
},
addScriptCheck() {
pk = (this.policypk) ? {policy: policypk} : {pk: agentpk}
const data = {
pk: this.agentpk,
...pk,
check_type: "script",
scriptPk: this.scriptPk,
timeout: this.timeout,
@@ -91,7 +93,13 @@ export default {
.post("/checks/addstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess(r.data);
})
.catch(e => this.notifyError(e.response.data));

View File

@@ -48,7 +48,7 @@ import { mapState } from "vuex";
import mixins from "@/mixins/mixins";
export default {
name: "AddWinSvcCheck",
props: ["agentpk"],
props: ["agentpk", "policypk"],
mixins: [mixins],
data() {
return {
@@ -69,7 +69,7 @@ export default {
methods: {
async getServices() {
try {
let r = await axios.get(`/services/${this.agentpk}/services/`);
let r = await axios.get(`/services/policies/`);
this.servicesData = Object.freeze([r.data][0].services);
} catch (e) {
console.log(`ERROR!: ${e}`);
@@ -82,8 +82,11 @@ export default {
this.rawName = [svc].map(j => j.name);
},
addCheck() {
pk = (this.policypk) ? {policy: policypk} : {pk: agentpk}
const data = {
pk: this.agentpk,
...pk,
check_type: "winsvc",
displayname: this.displayName,
rawname: this.rawName[0],
@@ -95,7 +98,13 @@ export default {
.post("/checks/addstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess(`${data.displayname} service check added!`);
})
.catch(e => this.notifyError(e.response.data.error));

View File

@@ -42,7 +42,7 @@ import { mapState } from "vuex";
import mixins from "@/mixins/mixins";
export default {
name: "EditCpuLoadCheck",
props: ["agentpk", "editCheckPK"],
props: ["agentpk", "policypk", "editCheckPK"],
mixins: [mixins],
data() {
return {
@@ -71,7 +71,13 @@ export default {
.patch("/checks/editstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess("CPU load check was edited!");
})
.catch(e => this.notifyError(e.response.data.error));

View File

@@ -58,7 +58,7 @@ export default {
methods: {
getCheck() {
axios
.get(`/checks/getstandardcheck/diskspace/${this.editCheckPK}/`)
.get(`/checks/getstandardcheck/polcies/`)
.then(r => {
this.disks = [r.data.disk];
this.diskToEdit = r.data.disk;
@@ -77,7 +77,13 @@ export default {
.patch("/checks/editstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess("Disk space check was edited!");
})
.catch(e => this.notifyError(e.response.data.error));

View File

@@ -42,7 +42,7 @@ import { mapState } from "vuex";
import mixins from "@/mixins/mixins";
export default {
name: "EditMemCheck",
props: ["agentpk", "editCheckPK"],
props: ["agentpk", "policypk", "editCheckPK"],
mixins: [mixins],
data() {
return {
@@ -69,7 +69,13 @@ export default {
.patch("/checks/editstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess("Memory check was edited!");
})
.catch(e => this.notifyError(e.response.data.error));

View File

@@ -45,7 +45,7 @@ import { mapState } from "vuex";
import mixins from "@/mixins/mixins";
export default {
name: "EditPingCheck",
props: ["agentpk", "editCheckPK"],
props: ["agentpk", "policypk", "editCheckPK"],
mixins: [mixins],
data() {
return {
@@ -77,7 +77,13 @@ export default {
.patch("/checks/editstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess("Ping check was edited!");
})
.catch(e => this.notifyError(e.response.data.error));

View File

@@ -45,7 +45,7 @@ import axios from "axios";
import mixins from "@/mixins/mixins";
export default {
name: "EditScriptCheck",
props: ["agentpk", "editCheckPK"],
props: ["agentpk", "policypk", "editCheckPK"],
mixins: [mixins],
data() {
return {
@@ -76,7 +76,13 @@ export default {
.patch("/checks/editstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess(r.data);
})
.catch(e => this.notifyError(e.response.data.error));

View File

@@ -76,7 +76,13 @@ export default {
.patch("/checks/editstandardcheck/", data)
.then(r => {
this.$emit("close");
this.$store.dispatch("loadChecks", this.agentpk);
if (this.policypk) {
this.$store.dispatch("loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.notifySuccess("Windows service check was edited!");
})
.catch(e => this.notifyError(e.response.data.error));

View File

@@ -26,6 +26,7 @@ export const store = new Vuex.Store({
automatedTasks: {},
selectedPolicy: null,
policyChecks: {},
PolicyAutomatedTasks: {},
agentTableLoading: false,
treeLoading: false,
installedSoftware: [],
@@ -41,6 +42,9 @@ export const store = new Vuex.Store({
selectedAgentPk(state) {
return state.agentSummary.id;
},
selectedPolicyPk(state) {
return state.selectedPolicy;
},
managedByWsus(state) {
return state.agentSummary.managed_by_wsus;
},
@@ -113,6 +117,9 @@ export const store = new Vuex.Store({
setPolicyChecks(state, checks) {
state.policyChecks = checks;
},
setPolicyAutomatedTasks(state, tasks) {
state.policyAutomatedTasks = tasks;
},
destroySubTable(state) {
(state.agentSummary = {}),
(state.agentChecks = {}),
@@ -141,6 +148,11 @@ export const store = new Vuex.Store({
context.commit("SET_AUTOMATED_TASKS", r.data);
})
},
loadPolicyAutomatedTasks(context, pk) {
axios.get(`/automation/${pk}/policyautomatedtasks/`).then(r => {
context.commit("setPolicyAutomatedTasks", r.data);
})
},
getScripts(context) {
axios.get("/checks/getscripts/").then(r => {
context.commit("SET_SCRIPTS", r.data);