Skip to content

Instantly share code, notes, and snippets.

@inebritov
Last active April 23, 2024 06:01
Show Gist options
  • Select an option

  • Save inebritov/8e9b27b8cb721a6ba93138e0c3681ca5 to your computer and use it in GitHub Desktop.

Select an option

Save inebritov/8e9b27b8cb721a6ba93138e0c3681ca5 to your computer and use it in GitHub Desktop.
Проверяет валидность конфигурации устройств в агенте
fetch(location.protocol + '//' + location.host + "/api/v1/devices")
.then(response => console.log(response.status) || response)
.then(response => response.text())
.then(body => {
let devices = JSON.parse(body).devices;
if (!devices) alert('Нет устройств');
console.log(devices);
let errors = 0;
for (let device of devices) {
let map = device.feature_mappings;
if (!map || Object.keys(map).length == 0) {
errors++;
addDeviceAlert(device)
}
}
alert('Неверно сконфигурированных устройств: ' + errors);
});
function addDeviceAlert(device, error) {
error = error || '';
let row = document.querySelector('[data-row-key="' + device.id + '"]');
if (!row) {alert('Не найдено устройство: ' + device.name + ' (' + device.id + ') ' + error);return;}
row.style.background = 'pink';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment