Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/components/agents/DetailsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { inject, reactive } from "vue";
import { useAgentStore } from "../../stores/agentStore";
import { useCoreDisplayStore } from "../../stores/coreDisplayStore";
import { storeToRefs } from "pinia";
import { getAgentStatus } from "@/utils/agentUtil.js";

const $api = inject("$api");

Expand All @@ -17,20 +18,6 @@ let validation = reactive({
watchdogTimer: ""
});

function getAgentStatus(agent) {
if (!agent.last_seen) return '';
let lastSeen = new Date(agent.last_seen).getTime();
let msSinceSeen = Date.now() - lastSeen;
// Give a buffer of 1 minute to mark an agent dead
let isAlive = (msSinceSeen < (agent.sleep_max * 1000));

if (msSinceSeen <= 60000 && agent.sleep_min === 3 && agent.sleep_max === 3 && agent.watchdog === 1) {
return 'pending kill'
} else {
return msSinceSeen <= 60000 || isAlive ? 'alive' : 'dead';
}
}

function saveAgent() {
// Validate group
if (!selectedAgent.value.group) {
Expand Down
20 changes: 1 addition & 19 deletions src/components/operations/AgentDetailsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { inject, reactive, ref } from "vue";
import { useAgentStore } from "../../stores/agentStore";
import { useCoreDisplayStore } from "../../stores/coreDisplayStore";
import { storeToRefs } from "pinia";
import { getAgentStatus } from "@/utils/agentUtil.js";

const $api = inject("$api");

Expand All @@ -19,25 +20,6 @@ let validation = reactive({
let showDetails = ref(false);
let showActions = ref(false);

function getAgentStatus(agent) {
if (!agent.last_seen) return "";
let lastSeen = new Date(agent.last_seen).getTime();
let msSinceSeen = Date.now() - lastSeen;
// Give a buffer of 1 minute to mark an agent dead
let isAlive = msSinceSeen < agent.sleep_max * 1000;

if (
msSinceSeen <= 60000 &&
agent.sleep_min === 3 &&
agent.sleep_max === 3 &&
agent.watchdog === 1
) {
return "pending kill";
} else {
return msSinceSeen <= 60000 || isAlive ? "alive" : "dead";
}
}

function saveAgent() {
// Validate group
if (!selectedAgent.value.group) {
Expand Down
7 changes: 1 addition & 6 deletions src/stores/agentStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,8 @@ export const useAgentStore = defineStore("agentStore", {
}
},
async killAgent($api, agentPaw) {
const reqBody = {
watchdog: 1,
sleep_min: 3,
sleep_max: 3
};
try {
const response = await $api.patch(`/api/v2/agents/${agentPaw}`, reqBody);
const response = await $api.post(`/api/v2/agents/kill/${agentPaw}`);
return response.data;
} catch(error) {
throw error;
Expand Down
12 changes: 1 addition & 11 deletions src/utils/agentUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,5 @@ export {
};

function getAgentStatus(agent) {
if (!agent.last_seen) return '';
let lastSeen = new Date(agent.last_seen).getTime();
let msSinceSeen = Date.now() - lastSeen;
// Give a buffer of 1 minute to mark an agent dead
let isAlive = (msSinceSeen < (agent.sleep_max * 1000));

if (msSinceSeen <= 60000 && agent.sleep_min === 3 && agent.sleep_max === 3 && agent.watchdog === 1) {
return 'pending kill'
} else {
return msSinceSeen <= 60000 || isAlive ? 'alive' : 'dead';
}
return agent.status;
}