Skip to content

Commit

Permalink
fix(index devices device): monitor stop and delete now working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
steledama committed Jan 9, 2022
1 parent a14da63 commit 3ab38b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
12 changes: 6 additions & 6 deletions components/Device.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ function Device({ conf, device, onDelete, onStop }) {

const handleClose = () => setShow(false);
const handleShow = () => setShow(true);

const deviceIp = device.tags.find((el) => el.tag === 'deviceIp').value;
const latestUrl = `http://${conf.server}/zabbix.php?action=latest.view&filter_hostids%5B%5D=${device.hostId}&filter_set=1`;
const configUrl = `http://${conf.server}/hosts.php?form=update&hostid=${device.hostId}`;
const deviceUrl = `http://${device.ip}`;
const deviceUrl = `http://${deviceIp}`;

async function monitorDevice() {
setDeviceMessage({
Expand All @@ -21,8 +21,8 @@ function Device({ conf, device, onDelete, onStop }) {
});
const deviceResponse = await axios.post('/api/monitor', {
conf,
serial: device.serial,
ip: device.ip,
serial: device.host,
ip: deviceIp,
});
// console.log(deviceResponse);
setDeviceMessage({
Expand All @@ -39,7 +39,7 @@ function Device({ conf, device, onDelete, onStop }) {
<Card.Link href={configUrl}>{device.name}</Card.Link>
</Card.Title>
<Card.Text>
Ip address: <Card.Link href={deviceUrl}>{device.ip}</Card.Link>
Ip address: <Card.Link href={deviceUrl}>{deviceIp}</Card.Link>
</Card.Text>
<Card.Link className="pr-3" href={latestUrl}>
Latest data
Expand All @@ -54,7 +54,7 @@ function Device({ conf, device, onDelete, onStop }) {
<Button
className="mx-3"
variant="warning"
onClick={() => onStop(device.host, device.hostId, device.ip)}
onClick={() => onStop(device.host, device.hostId, deviceIp)}
>
Stop monitor
</Button>
Expand Down
2 changes: 1 addition & 1 deletion components/Devices.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function Devices({ conf, devices, onDelete, onStop }) {
<>
{devices.map((device) => (
<Device
key={device.serial}
key={device.host}
conf={conf}
device={device}
onDelete={onDelete}
Expand Down
11 changes: 1 addition & 10 deletions pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,7 @@ export default function Home({ confProp, confAutoProp, confMessageProp }) {
conf.token,
conf.id
);
if (devicesFromZabbix.result) {
const devicesFull = devicesFromZabbix.result.map((device) => ({
agentId: device.tags.find((el) => el.tag === 'agentId').value,
hostId: device.hostid,
ip: device.tags.find((el) => el.tag === 'deviceIp').value,
name: device.name,
serial: device.host,
}));
setDevices(devicesFull);
}
if (devicesFromZabbix.result) setDevices(devicesFromZabbix.result);
}
updateDevices();
}, [conf.id, conf.server, conf.token]);
Expand Down

0 comments on commit 3ab38b4

Please sign in to comment.