Feature: Zabbix service widget (#3905)
Co-Authored-By: shamoon <4887959+shamoon@users.noreply.github.com>pull/3915/head
parent
4c6150a545
commit
44f8e9d4da
@ -0,0 +1,19 @@
|
||||
---
|
||||
title: Zabbix
|
||||
description: Zabbix Widget Configuration
|
||||
---
|
||||
|
||||
Learn more about [Zabbix](https://github.com/zabbix/zabbix).
|
||||
|
||||
See the [Zabbix documentation](https://www.zabbix.com/documentation/current/en/manual/web_interface/frontend_sections/users/api_tokens) for details on generating API tokens.
|
||||
|
||||
The widget supports (at least) Zibbax server version 7.0.
|
||||
|
||||
Allowed fields: `["warning", "average", "high", "disaster"]`.
|
||||
|
||||
```yaml
|
||||
widget:
|
||||
type: zabbix
|
||||
url: http://zabbix.host.or.ip/zabbix
|
||||
key: your-api-key
|
||||
```
|
@ -0,0 +1,46 @@
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
const PriorityWarning = "2";
|
||||
const PriorityAverage = "3";
|
||||
const PriorityHigh = "4";
|
||||
const PriorityDisaster = "5";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
|
||||
const { data: zabbixData, error: zabbixError } = useWidgetAPI(widget, "trigger");
|
||||
|
||||
if (zabbixError) {
|
||||
return <Container service={service} error={zabbixError} />;
|
||||
}
|
||||
|
||||
if (!zabbixData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="zabbix.warning" />
|
||||
<Block label="zabbix.average" />
|
||||
<Block label="zabbix.high" />
|
||||
<Block label="zabbix.disaster" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const warning = zabbixData.filter((item) => item.priority === PriorityWarning).length;
|
||||
const average = zabbixData.filter((item) => item.priority === PriorityAverage).length;
|
||||
const high = zabbixData.filter((item) => item.priority === PriorityHigh).length;
|
||||
const disaster = zabbixData.filter((item) => item.priority === PriorityDisaster).length;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="zabbix.warning" value={t("common.number", { value: warning })} />
|
||||
<Block label="zabbix.average" value={t("common.number", { value: average })} />
|
||||
<Block label="zabbix.high" value={t("common.number", { value: high })} />
|
||||
<Block label="zabbix.disaster" value={t("common.number", { value: disaster })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import jsonrpcProxyHandler from "utils/proxy/handlers/jsonrpc";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api_jsonrpc.php",
|
||||
proxyHandler: jsonrpcProxyHandler,
|
||||
|
||||
mappings: {
|
||||
trigger: {
|
||||
endpoint: "trigger.get",
|
||||
params: {
|
||||
output: ["triggerid", "description", "priority"],
|
||||
filter: {
|
||||
value: 1,
|
||||
},
|
||||
sortfield: "priority",
|
||||
sortorder: "DESC",
|
||||
monitored: "true",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
Loading…
Reference in new issue