| 1 | <template> |
| 2 | <n-spin :show="loading"> |
| 3 | <CardStatsMulti |
| 4 | title="Healthcheck" |
| 5 | hovered |
| 6 | class="h-full cursor-pointer" |
| 7 | :values |
| 8 | @click="routeHealthcheck().navigate()" |
| 9 | > |
| 10 | <template #icon> |
| 11 | <CardStatsIcon |
| 12 | :icon-name="HealthcheckIcon" |
| 13 | boxed |
| 14 | :box-size="30" |
| 15 | :color="criticalTotal ? style['warning-color'] : undefined" |
| 16 | ></CardStatsIcon> |
| 17 | </template> |
| 18 | </CardStatsMulti> |
| 19 | </n-spin> |
| 20 | </template> |
| 21 | |
| 22 | <script setup lang="ts"> |
| 23 | import type { ItemProps } from "@/components/common/cards/CardStatsMulti.vue" |
| 24 | import type { InfluxDBAlert } from "@/types/healthchecks.d" |
| 25 | import { NSpin, useMessage } from "naive-ui" |
| 26 | import { computed, onBeforeMount, ref } from "vue" |
| 27 | import Api from "@/api" |
| 28 | import CardStatsIcon from "@/components/common/cards/CardStatsIcon.vue" |
| 29 | import CardStatsMulti from "@/components/common/cards/CardStatsMulti.vue" |
| 30 | import { useNavigation } from "@/composables/useNavigation" |
| 31 | import { useThemeStore } from "@/stores/theme" |
| 32 | import { InfluxDBAlertSeverity } from "@/types/healthchecks.d" |
| 33 | |
| 34 | const HealthcheckIcon = "ph:heartbeat" |
| 35 | const { routeHealthcheck } = useNavigation() |
| 36 | const message = useMessage() |
| 37 | const loading = ref(false) |
| 38 | const healthcheck = ref<InfluxDBAlert[]>([]) |
| 39 | const style = computed(() => useThemeStore().style) |
| 40 | |
| 41 | const total = computed<number>(() => { |
| 42 | return healthcheck.value.length || 0 |
| 43 | }) |
| 44 | |
| 45 | const criticalTotal = computed<number>(() => { |
| 46 | return healthcheck.value.filter(o => o.severity === InfluxDBAlertSeverity.Critical).length || 0 |
| 47 | }) |
| 48 | |
| 49 | const values = computed<ItemProps[]>(() => [ |
| 50 | { value: total.value, label: "Total" }, |
| 51 | { value: criticalTotal.value, label: "Critical", status: criticalTotal.value ? "warning" : undefined } |
| 52 | ]) |
| 53 | |
| 54 | function getData() { |
| 55 | loading.value = true |
| 56 | |
| 57 | Api.healthchecks |
| 58 | .getHealthchecks({ |
| 59 | days: 1, |
| 60 | status: "active", |
| 61 | exclude_ok: true |
| 62 | }) |
| 63 | .then(res => { |
| 64 | if (res.data.success) { |
| 65 | healthcheck.value = res.data.alerts || [] |
| 66 | } else { |
| 67 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 68 | } |
| 69 | }) |
| 70 | .catch(err => { |
| 71 | healthcheck.value = [] |
| 72 | |
| 73 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 74 | }) |
| 75 | .finally(() => { |
| 76 | loading.value = false |
| 77 | }) |
| 78 | } |
| 79 | |
| 80 | onBeforeMount(() => { |
| 81 | getData() |
| 82 | }) |
| 83 | </script> |
| 84 | |
| 85 | <style lang="scss" scoped> |
| 86 | .n-spin-container { |
| 87 | :deep() { |
| 88 | .n-spin-content { |
| 89 | height: 100%; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | </style> |