mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-13 12:42:09 +08:00
Enhancement: Checkmk widget (#5301)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
40
src/widgets/checkmk/component.jsx
Normal file
40
src/widgets/checkmk/component.jsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import Block from "components/services/widget/block";
|
||||
import Container from "components/services/widget/container";
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: servicesData, error: servicesError } = useWidgetAPI(widget, "services_info", {
|
||||
columns: "state",
|
||||
query: '{"op": "!=", "left": "state", "right": "0"}',
|
||||
});
|
||||
const { data: hostsData, error: hostsError } = useWidgetAPI(widget, "hosts_info", {
|
||||
columns: "state",
|
||||
query: '{"op": "!=", "left": "state", "right": "0"}',
|
||||
});
|
||||
|
||||
if (servicesError || hostsError) {
|
||||
return <Container service={service} error={servicesError ?? hostsError} />;
|
||||
}
|
||||
|
||||
if (!servicesData || !hostsData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="checkmk.serviceErrors" />
|
||||
<Block label="checkmk.hostErrors" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="checkmk.serviceErrors" value={t("common.number", { value: servicesData.value.length })} />
|
||||
<Block label="checkmk.hostErrors" value={t("common.number", { value: hostsData.value.length })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user