feat : ajout page monitoring
This commit is contained in:
45
server/api/disk.get.ts
Normal file
45
server/api/disk.get.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { exec } from "child_process"
|
||||
|
||||
const remoteCommand =
|
||||
process.env.DISK_REMOTE_COMMAND ||
|
||||
"ssh malio-b@192.168.0.179 'cd /home/malio-b/Scripts-Serveur && bash check_storage.sh && exit'"
|
||||
|
||||
const localCommand =
|
||||
process.env.DISK_LOCAL_COMMAND ||
|
||||
"bash /home/kevin/check_storage.sh"
|
||||
|
||||
function runCommand(command: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(stderr || error.message)
|
||||
return
|
||||
}
|
||||
resolve(stdout)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
const [remoteResult, localResult] = await Promise.allSettled([
|
||||
runCommand(remoteCommand),
|
||||
runCommand(localCommand)
|
||||
])
|
||||
|
||||
return {
|
||||
remote: {
|
||||
ok: remoteResult.status === "fulfilled",
|
||||
output:
|
||||
remoteResult.status === "fulfilled"
|
||||
? remoteResult.value
|
||||
: `Erreur: ${String(remoteResult.reason)}`
|
||||
},
|
||||
local: {
|
||||
ok: localResult.status === "fulfilled",
|
||||
output:
|
||||
localResult.status === "fulfilled"
|
||||
? localResult.value
|
||||
: `Erreur: ${String(localResult.reason)}`
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user