refactor ping checks
This commit is contained in:
parent
503f2e7071
commit
81e4f29ca1
|
@ -11,7 +11,7 @@
|
|||
</q-item-section>
|
||||
<q-item-section>Disk Space Check</q-item-section>
|
||||
</q-item>
|
||||
<q-item clickable v-close-popup @click="showAddPingCheck = true">
|
||||
<q-item clickable v-close-popup @click="showCheck('add', 'ping')">
|
||||
<q-item-section side>
|
||||
<q-icon size="xs" name="fas fa-network-wired" />
|
||||
</q-item-section>
|
||||
|
@ -192,17 +192,15 @@
|
|||
:checkpk="checkpk"
|
||||
/>
|
||||
</q-dialog>
|
||||
<!-- refactor below -->
|
||||
<q-dialog v-model="showAddPingCheck">
|
||||
<AddPingCheck @close="showAddPingCheck = false" :agentpk="selectedAgentPk" />
|
||||
</q-dialog>
|
||||
<q-dialog v-model="showEditPingCheck">
|
||||
<EditPingCheck
|
||||
@close="showEditPingCheck = false"
|
||||
:editCheckPK="editCheckPK"
|
||||
<q-dialog v-model="showPingCheck">
|
||||
<PingCheck
|
||||
@close="showPingCheck = false"
|
||||
:agentpk="selectedAgentPk"
|
||||
:mode="mode"
|
||||
:checkpk="checkpk"
|
||||
/>
|
||||
</q-dialog>
|
||||
<!-- refactor below -->
|
||||
<q-dialog v-model="showAddWinSvcCheck">
|
||||
<AddWinSvcCheck @close="showAddWinSvcCheck = false" :agentpk="selectedAgentPk" />
|
||||
</q-dialog>
|
||||
|
@ -254,9 +252,8 @@ 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";
|
||||
import PingCheck from "@/components/modals/checks/PingCheck";
|
||||
// refactor below
|
||||
import AddPingCheck from "@/components/modals/checks/AddPingCheck";
|
||||
import EditPingCheck from "@/components/modals/checks/EditPingCheck";
|
||||
import AddWinSvcCheck from "@/components/modals/checks/AddWinSvcCheck";
|
||||
import EditWinSvcCheck from "@/components/modals/checks/EditWinSvcCheck";
|
||||
import AddScriptCheck from "@/components/modals/checks/AddScriptCheck";
|
||||
|
@ -272,8 +269,7 @@ export default {
|
|||
DiskSpaceCheck,
|
||||
MemCheck,
|
||||
CpuLoadCheck,
|
||||
AddPingCheck,
|
||||
EditPingCheck,
|
||||
PingCheck,
|
||||
AddWinSvcCheck,
|
||||
EditWinSvcCheck,
|
||||
AddScriptCheck,
|
||||
|
@ -291,9 +287,8 @@ export default {
|
|||
showDiskSpaceCheck: false,
|
||||
showMemCheck: false,
|
||||
showCpuLoadCheck: false,
|
||||
showPingCheck: false,
|
||||
// refactor below
|
||||
showAddPingCheck: false,
|
||||
showEditPingCheck: false,
|
||||
showAddWinSvcCheck: false,
|
||||
showEditWinSvcCheck: false,
|
||||
showAddScriptCheck: false,
|
||||
|
@ -351,6 +346,9 @@ export default {
|
|||
case "cpuload":
|
||||
this.showCpuLoadCheck = true;
|
||||
break;
|
||||
case "ping":
|
||||
this.showPingCheck = true;
|
||||
break;
|
||||
}
|
||||
},
|
||||
checkAlertAction(pk, category, alert_type, alert_action) {
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
<template>
|
||||
<q-card style="min-width: 400px">
|
||||
<q-card-section class="row items-center">
|
||||
<div class="text-h6">Add Ping 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="pingname"
|
||||
label="Descriptive Name"
|
||||
:rules="[val => !!val || '*Required']"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-input
|
||||
outlined
|
||||
v-model="pingip"
|
||||
label="Hostname or IP"
|
||||
:rules="[val => !!val || '*Required']"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-select
|
||||
outlined
|
||||
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: "AddPingCheck",
|
||||
props: ["agentpk", "policypk"],
|
||||
mixins: [mixins],
|
||||
data() {
|
||||
return {
|
||||
failure: 5,
|
||||
failures: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
pingname: "",
|
||||
pingip: ""
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
addCheck() {
|
||||
let pk = this.policypk ? { policy: this.policypk } : { pk: this.agentpk };
|
||||
|
||||
const data = {
|
||||
...pk,
|
||||
check_type: "ping",
|
||||
failures: this.failure,
|
||||
name: this.pingname,
|
||||
ip: this.pingip
|
||||
};
|
||||
|
||||
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("Ping check was added!");
|
||||
})
|
||||
.catch(e => {
|
||||
this.notifyError(e.response.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -1,94 +0,0 @@
|
|||
<template>
|
||||
<q-card style="min-width: 400px">
|
||||
<q-card-section class="row items-center">
|
||||
<div class="text-h6">Edit Ping 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="pingname"
|
||||
label="Descriptive Name"
|
||||
:rules="[val => !!val || '*Required']"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-input
|
||||
outlined
|
||||
v-model="pingip"
|
||||
label="Hostname or IP"
|
||||
:rules="[val => !!val || '*Required']"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-select
|
||||
outlined
|
||||
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: "EditPingCheck",
|
||||
props: ["agentpk", "policypk", "editCheckPK"],
|
||||
mixins: [mixins],
|
||||
data() {
|
||||
return {
|
||||
failure: null,
|
||||
failures: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
pingname: "",
|
||||
pingip: ""
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getCheck() {
|
||||
axios.get(`/checks/getstandardcheck/ping/${this.editCheckPK}/`).then(r => {
|
||||
this.failure = r.data.failures;
|
||||
this.pingname = r.data.name;
|
||||
this.pingip = r.data.ip;
|
||||
});
|
||||
},
|
||||
editCheck() {
|
||||
const data = {
|
||||
pk: this.editCheckPK,
|
||||
check_type: "ping",
|
||||
failures: this.failure,
|
||||
name: this.pingname,
|
||||
ip: this.pingip
|
||||
};
|
||||
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("Ping check was edited!");
|
||||
})
|
||||
.catch(e => this.notifyError(e.response.data.error));
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getCheck();
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -0,0 +1,111 @@
|
|||
<template>
|
||||
<q-card style="min-width: 400px">
|
||||
<q-card-section class="row items-center">
|
||||
<div v-if="mode === 'add'" class="text-h6">Add Ping Check</div>
|
||||
<div v-else-if="mode === 'edit'" class="text-h6">Edit Ping 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="pingcheck.name"
|
||||
label="Descriptive Name"
|
||||
:rules="[val => !!val || '*Required']"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-input
|
||||
outlined
|
||||
v-model="pingcheck.ip"
|
||||
label="Hostname or IP"
|
||||
:rules="[val => !!val || '*Required']"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-select
|
||||
outlined
|
||||
dense
|
||||
v-model="pingcheck.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: "PingCheck",
|
||||
props: {
|
||||
agentpk: Number,
|
||||
policypk: Number,
|
||||
mode: String,
|
||||
checkpk: Number
|
||||
},
|
||||
mixins: [mixins],
|
||||
data() {
|
||||
return {
|
||||
pingcheck: {
|
||||
check_type: "ping",
|
||||
name: null,
|
||||
ip: null,
|
||||
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.pingcheck = r.data));
|
||||
},
|
||||
addCheck() {
|
||||
const pk = this.policypk ? { policy: this.policypk } : { pk: this.agentpk };
|
||||
const data = {
|
||||
...pk,
|
||||
check: this.pingcheck
|
||||
};
|
||||
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.pingcheck)
|
||||
.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>
|
Loading…
Reference in New Issue