refactor cpu checks
This commit is contained in:
parent
78f6ddd9f4
commit
503f2e7071
|
@ -17,7 +17,7 @@
|
|||
</q-item-section>
|
||||
<q-item-section>Ping Check</q-item-section>
|
||||
</q-item>
|
||||
<q-item clickable v-close-popup @click="showAddCpuLoadCheck = true">
|
||||
<q-item clickable v-close-popup @click="showCheck('add', 'cpuload')">
|
||||
<q-item-section side>
|
||||
<q-icon size="xs" name="fas fa-microchip" />
|
||||
</q-item-section>
|
||||
|
@ -133,25 +133,7 @@
|
|||
<q-td v-else-if="props.row.status === 'failing'">
|
||||
<q-icon style="font-size: 1.3rem;" color="negative" name="error" />
|
||||
</q-td>
|
||||
<q-td v-if="props.row.check_type === 'diskspace'">{{ props.row.readable_desc }}</q-td>
|
||||
<q-td
|
||||
v-else-if="props.row.check_type === 'cpuload'"
|
||||
>Avg CPU Load > {{ props.row.cpuload }}%</q-td>
|
||||
<q-td
|
||||
v-else-if="props.row.check_type === 'script'"
|
||||
>Script check: {{ props.row.script.name }}</q-td>
|
||||
<q-td
|
||||
v-else-if="props.row.check_type === 'ping'"
|
||||
>Ping {{ props.row.name }} ({{ props.row.ip }})</q-td>
|
||||
<q-td
|
||||
v-else-if="props.row.check_type === 'memory'"
|
||||
>Avg memory usage > {{ props.row.threshold }}%</q-td>
|
||||
<q-td
|
||||
v-else-if="props.row.check_type === 'winsvc'"
|
||||
>Service Check - {{ props.row.svc_display_name }}</q-td>
|
||||
<q-td
|
||||
v-else-if="props.row.check_type === 'eventlog'"
|
||||
>Event Log Check - {{ props.row.desc }}</q-td>
|
||||
<q-td>{{ props.row.readable_desc }}</q-td>
|
||||
<q-td v-if="props.row.status === 'pending'">Awaiting First Synchronization</q-td>
|
||||
<q-td v-else-if="props.row.status === 'passing'">
|
||||
<q-badge color="positive">Passing</q-badge>
|
||||
|
@ -202,6 +184,14 @@
|
|||
:checkpk="checkpk"
|
||||
/>
|
||||
</q-dialog>
|
||||
<q-dialog v-model="showCpuLoadCheck">
|
||||
<CpuLoadCheck
|
||||
@close="showCpuLoadCheck = false"
|
||||
:agentpk="selectedAgentPk"
|
||||
:mode="mode"
|
||||
:checkpk="checkpk"
|
||||
/>
|
||||
</q-dialog>
|
||||
<!-- refactor below -->
|
||||
<q-dialog v-model="showAddPingCheck">
|
||||
<AddPingCheck @close="showAddPingCheck = false" :agentpk="selectedAgentPk" />
|
||||
|
@ -213,17 +203,6 @@
|
|||
:agentpk="selectedAgentPk"
|
||||
/>
|
||||
</q-dialog>
|
||||
<q-dialog v-model="showAddCpuLoadCheck">
|
||||
<AddCpuLoadCheck @close="showAddCpuLoadCheck = false" :agentpk="selectedAgentPk" />
|
||||
</q-dialog>
|
||||
<q-dialog v-model="showEditCpuLoadCheck">
|
||||
<EditCpuLoadCheck
|
||||
@close="showEditCpuLoadCheck = false"
|
||||
:editCheckPK="editCheckPK"
|
||||
:agentpk="selectedAgentPk"
|
||||
/>
|
||||
</q-dialog>
|
||||
|
||||
<q-dialog v-model="showAddWinSvcCheck">
|
||||
<AddWinSvcCheck @close="showAddWinSvcCheck = false" :agentpk="selectedAgentPk" />
|
||||
</q-dialog>
|
||||
|
@ -274,11 +253,10 @@ import { mapState, mapGetters } from "vuex";
|
|||
import mixins from "@/mixins/mixins";
|
||||
import DiskSpaceCheck from "@/components/modals/checks/DiskSpaceCheck";
|
||||
import MemCheck from "@/components/modals/checks/MemCheck";
|
||||
import CpuLoadCheck from "@/components/modals/checks/CpuLoadCheck";
|
||||
// refactor below
|
||||
import AddPingCheck from "@/components/modals/checks/AddPingCheck";
|
||||
import EditPingCheck from "@/components/modals/checks/EditPingCheck";
|
||||
import AddCpuLoadCheck from "@/components/modals/checks/AddCpuLoadCheck";
|
||||
import EditCpuLoadCheck from "@/components/modals/checks/EditCpuLoadCheck";
|
||||
import AddWinSvcCheck from "@/components/modals/checks/AddWinSvcCheck";
|
||||
import EditWinSvcCheck from "@/components/modals/checks/EditWinSvcCheck";
|
||||
import AddScriptCheck from "@/components/modals/checks/AddScriptCheck";
|
||||
|
@ -293,10 +271,9 @@ export default {
|
|||
components: {
|
||||
DiskSpaceCheck,
|
||||
MemCheck,
|
||||
CpuLoadCheck,
|
||||
AddPingCheck,
|
||||
EditPingCheck,
|
||||
AddCpuLoadCheck,
|
||||
EditCpuLoadCheck,
|
||||
AddWinSvcCheck,
|
||||
EditWinSvcCheck,
|
||||
AddScriptCheck,
|
||||
|
@ -313,11 +290,10 @@ export default {
|
|||
checkpk: null,
|
||||
showDiskSpaceCheck: false,
|
||||
showMemCheck: false,
|
||||
showCpuLoadCheck: false,
|
||||
// refactor below
|
||||
showAddPingCheck: false,
|
||||
showEditPingCheck: false,
|
||||
showAddCpuLoadCheck: false,
|
||||
showEditCpuLoadCheck: false,
|
||||
showAddWinSvcCheck: false,
|
||||
showEditWinSvcCheck: false,
|
||||
showAddScriptCheck: false,
|
||||
|
@ -372,6 +348,9 @@ export default {
|
|||
case "memory":
|
||||
this.showMemCheck = true;
|
||||
break;
|
||||
case "cpuload":
|
||||
this.showCpuLoadCheck = true;
|
||||
break;
|
||||
}
|
||||
},
|
||||
checkAlertAction(pk, category, alert_type, alert_action) {
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
<template>
|
||||
<q-card style="min-width: 400px">
|
||||
<q-card-section class="row items-center">
|
||||
<div class="text-h6">Add CPU Load Check</div>
|
||||
<q-space />
|
||||
<q-btn icon="close" flat round dense v-close-popup />
|
||||
</q-card-section>
|
||||
|
||||
<q-form @submit.prevent="addCheck">
|
||||
<q-card-section>
|
||||
<q-input
|
||||
outlined
|
||||
v-model.number="threshold"
|
||||
label="Alert if average utilization > (%)"
|
||||
:rules="[
|
||||
val => !!val || '*Required',
|
||||
val => val >= 1 || 'Minimum threshold is 1',
|
||||
val => val < 100 || 'Maximum threshold is 99'
|
||||
]"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-select
|
||||
outlined
|
||||
dense
|
||||
v-model="failure"
|
||||
:options="failures"
|
||||
label="Number of consecutive failures before alert"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-actions align="right">
|
||||
<q-btn label="Add" color="primary" type="submit" />
|
||||
<q-btn label="Cancel" v-close-popup />
|
||||
</q-card-actions>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from "axios";
|
||||
import { mapState } from "vuex";
|
||||
import mixins from "@/mixins/mixins";
|
||||
export default {
|
||||
name: "AddCpuLoadCheck",
|
||||
props: ["agentpk", "policypk"],
|
||||
mixins: [mixins],
|
||||
data() {
|
||||
return {
|
||||
threshold: 85,
|
||||
failure: 5,
|
||||
failures: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
addCheck() {
|
||||
const pk = this.policypk ? { policy: this.policypk } : { pk: this.agentpk };
|
||||
|
||||
const data = {
|
||||
...pk,
|
||||
check_type: "cpuload",
|
||||
threshold: this.threshold,
|
||||
failure: this.failure
|
||||
};
|
||||
axios
|
||||
.post("/checks/addstandardcheck/", data)
|
||||
.then(r => {
|
||||
this.$emit("close");
|
||||
|
||||
if (this.policypk) {
|
||||
this.$store.dispatch("automation/loadPolicyChecks", this.policypk);
|
||||
} else {
|
||||
this.$store.dispatch("loadChecks", this.agentpk);
|
||||
}
|
||||
|
||||
this.notifySuccess("CPU load check was added!");
|
||||
})
|
||||
.catch(e => this.notifyError(e.response.data.error));
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -0,0 +1,106 @@
|
|||
<template>
|
||||
<q-card style="min-width: 400px">
|
||||
<q-card-section class="row items-center">
|
||||
<div v-if="mode === 'add'" class="text-h6">Add CPU Load Check</div>
|
||||
<div v-else-if="mode === 'edit'" class="text-h6">Edit CPU Load Check</div>
|
||||
<q-space />
|
||||
<q-btn icon="close" flat round dense v-close-popup />
|
||||
</q-card-section>
|
||||
|
||||
<q-form @submit.prevent="mode === 'add' ? addCheck() : editCheck()">
|
||||
<q-card-section>
|
||||
<q-input
|
||||
outlined
|
||||
v-model.number="cpuloadcheck.threshold"
|
||||
label="Threshold (%)"
|
||||
:rules="[
|
||||
val => !!val || '*Required',
|
||||
val => val >= 1 || 'Minimum threshold is 1',
|
||||
val => val < 100 || 'Maximum threshold is 99'
|
||||
]"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-select
|
||||
outlined
|
||||
dense
|
||||
v-model="cpuloadcheck.fails_b4_alert"
|
||||
:options="failOptions"
|
||||
label="Number of consecutive failures before alert"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-actions align="right">
|
||||
<q-btn v-if="mode === 'add'" label="Add" color="primary" type="submit" />
|
||||
<q-btn v-else-if="mode === 'edit'" label="Edit" color="primary" type="submit" />
|
||||
<q-btn label="Cancel" v-close-popup />
|
||||
</q-card-actions>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from "axios";
|
||||
import mixins from "@/mixins/mixins";
|
||||
export default {
|
||||
name: "CpuLoadCheck",
|
||||
props: {
|
||||
agentpk: Number,
|
||||
policypk: Number,
|
||||
mode: String,
|
||||
checkpk: Number
|
||||
},
|
||||
mixins: [mixins],
|
||||
data() {
|
||||
return {
|
||||
cpuloadcheck: {
|
||||
check_type: "cpuload",
|
||||
threshold: 85,
|
||||
fails_b4_alert: 1
|
||||
},
|
||||
failOptions: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getCheck() {
|
||||
axios.get(`/checks/${this.checkpk}/check/`).then(r => (this.cpuloadcheck = r.data));
|
||||
},
|
||||
addCheck() {
|
||||
const pk = this.policypk ? { policy: this.policypk } : { pk: this.agentpk };
|
||||
const data = {
|
||||
...pk,
|
||||
check: this.cpuloadcheck
|
||||
};
|
||||
axios
|
||||
.post("/checks/checks/", data)
|
||||
.then(r => {
|
||||
this.$emit("close");
|
||||
this.reloadChecks();
|
||||
this.notifySuccess(r.data);
|
||||
})
|
||||
.catch(e => this.notifyError(e.response.data.non_field_errors));
|
||||
},
|
||||
editCheck() {
|
||||
axios
|
||||
.patch(`/checks/${this.checkpk}/check/`, this.cpuloadcheck)
|
||||
.then(r => {
|
||||
this.$emit("close");
|
||||
this.reloadChecks();
|
||||
this.notifySuccess(r.data);
|
||||
})
|
||||
.catch(e => this.notifyError(e.response.data.non_field_errors));
|
||||
},
|
||||
reloadChecks() {
|
||||
if (this.policypk) {
|
||||
this.$store.dispatch("automation/loadPolicyChecks", this.policypk);
|
||||
} else {
|
||||
this.$store.dispatch("loadChecks", this.agentpk);
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
if (this.mode === "edit") {
|
||||
this.getCheck();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -1,88 +0,0 @@
|
|||
<template>
|
||||
<q-card style="min-width: 400px">
|
||||
<q-card-section class="row items-center">
|
||||
<div class="text-h6">Edit CPU Load Check</div>
|
||||
<q-space />
|
||||
<q-btn icon="close" flat round dense v-close-popup />
|
||||
</q-card-section>
|
||||
|
||||
<q-form @submit.prevent="editCheck">
|
||||
<q-card-section>
|
||||
<q-input
|
||||
outlined
|
||||
v-model.number="threshold"
|
||||
label="Alert if average utilization > (%)"
|
||||
:rules="[
|
||||
val => !!val || '*Required',
|
||||
val => val >= 1 || 'Minimum threshold is 1',
|
||||
val => val < 100 || 'Maximum threshold is 99'
|
||||
]"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-select
|
||||
outlined
|
||||
dense
|
||||
v-model="failure"
|
||||
:options="failures"
|
||||
label="Number of consecutive failures before alert"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-actions align="right">
|
||||
<q-btn label="Edit" color="primary" type="submit" />
|
||||
<q-btn label="Cancel" v-close-popup />
|
||||
</q-card-actions>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from "axios";
|
||||
import { mapState } from "vuex";
|
||||
import mixins from "@/mixins/mixins";
|
||||
export default {
|
||||
name: "EditCpuLoadCheck",
|
||||
props: ["agentpk", "policypk", "editCheckPK"],
|
||||
mixins: [mixins],
|
||||
data() {
|
||||
return {
|
||||
threshold: null,
|
||||
failure: null,
|
||||
failures: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getCheck() {
|
||||
axios.get(`/checks/getstandardcheck/cpuload/${this.editCheckPK}/`).then(r => {
|
||||
this.threshold = r.data.cpuload;
|
||||
this.failure = r.data.failures;
|
||||
});
|
||||
},
|
||||
editCheck() {
|
||||
const data = {
|
||||
pk: this.editCheckPK,
|
||||
check_type: "cpuload",
|
||||
threshold: this.threshold,
|
||||
failure: this.failure
|
||||
};
|
||||
axios
|
||||
.patch("/checks/editstandardcheck/", data)
|
||||
.then(r => {
|
||||
this.$emit("close");
|
||||
|
||||
if (this.policypk) {
|
||||
this.$store.dispatch("automation/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));
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getCheck();
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue