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.

Revisions

  1. inebritov revised this gist Apr 23, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion agent-validator.bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    javascript:fetch("https://gist.githubusercontent.com/inebritov/8e9b27b8cb721a6ba93138e0c3681ca5/raw/agent-validator.js").then((t=>t.text())).then((js=>{eval(js),window.__AgentValidator()})).catch((t=>console.error(t)));
    javascript:fetch("https://gist.githubusercontent.com/inebritov/8e9b27b8cb721a6ba93138e0c3681ca5/raw/agent-validator.js?cachebust="+Math.floor(1000*Math.random())).then((t=>t.text())).then((js=>{eval(js),window.__AgentValidator()})).catch((t=>console.error(t)));
  2. inebritov revised this gist Apr 23, 2024. 2 changed files with 3 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion agent-validator.bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    javascript:!function(){function e(e,t){return t=t||"",document.querySelector('[data-row-key="'+e.id+'"]').style.background="pink",e.name+" "+t+"\n"}fetch(location.protocol+"//"+location.host+"/api/v1/devices").then((e=>console.log(e.status)||e)).then((e=>e.text())).then((t=>{let o=JSON.parse(t).devices;o||alert("Нет устройств"),console.log(o);let n=0,l="";for(let t of o){let o=t.feature_mappings;if(o&&0!=Object.keys(o).length)for(let s in o)if(o[s].mappings&&0!=o[s].mappings.length)for(let a of o[s].mappings)a.status_object||(n++,l+=e(t,"- пустой топик статуса"));else n++,l+=e(t,"- нет функций");else n++,l+=e(t,"- стерлись функции")}alert("Неверно сконфигурированных устройств: "+n+"\n"+l),console.log("Неверно сконфигурированных устройств: "+n+"\n"+l)}))}();
    javascript:fetch("https://gist.githubusercontent.com/inebritov/8e9b27b8cb721a6ba93138e0c3681ca5/raw/agent-validator.js").then((t=>t.text())).then((js=>{eval(js),window.__AgentValidator()})).catch((t=>console.error(t)));
    3 changes: 2 additions & 1 deletion agent-validator.js
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    */

    window['__AgentValidator'] = function () {
    window.__AgentValidator = () => {

    fetch(location.protocol + '//' + location.host + "/api/v1/devices")
    .then(response => console.log(response.status) || response)
    @@ -58,6 +58,7 @@ window['__AgentValidator'] = function () {
    }
    }
    }

    let text = 'Неверно сконфигурированных устройств: ' + errors + '\n' + message;
    console.log(text);
    alert(text);
  3. inebritov revised this gist Apr 23, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions agent-validator.js
    Original file line number Diff line number Diff line change
    @@ -58,8 +58,8 @@ window['__AgentValidator'] = function () {
    }
    }
    }
    let message = 'Неверно сконфигурированных устройств: ' + errors + '\n' + message;
    console.log(message);
    alert(message);
    let text = 'Неверно сконфигурированных устройств: ' + errors + '\n' + message;
    console.log(text);
    alert(text);
    }
    }
  4. inebritov revised this gist Apr 23, 2024. 1 changed file with 22 additions and 21 deletions.
    43 changes: 22 additions & 21 deletions agent-validator.js
    Original file line number Diff line number Diff line change
    @@ -14,12 +14,21 @@
    */

    (function () {
    window['__AgentValidator'] = function () {

    fetch(location.protocol + '//' + location.host + "/api/v1/devices")
    .then(response => console.log(response.status) || response)
    .then(response => response.text())
    .then(body => {
    fetch(location.protocol + '//' + location.host + "/api/v1/devices")
    .then(response => console.log(response.status) || response)
    .then(response => response.text())
    .then(body => validateDevices(body));

    function addDeviceAlert(device, error) {
    error = error || '';
    let row = document.querySelector('[data-row-key="' + device.id + '"]');
    row.style.background = 'pink';
    return device.name + ' - ' + error + '\n';
    }

    function validateDevices(body) {
    let devices = JSON.parse(body).devices;
    if (!devices) alert('Нет устройств');

    @@ -30,35 +39,27 @@ fetch(location.protocol + '//' + location.host + "/api/v1/devices")
    let map = device.feature_mappings;
    if (!map || Object.keys(map).length == 0) {
    errors++;
    message += addDeviceAlert(device, '- стерлись функции');
    message += addDeviceAlert(device, 'стёрлись функции');
    continue;
    }

    for (let key in map) {
    if (!map[key].mappings || map[key].mappings.length == 0) {
    errors++;
    message += addDeviceAlert(device, '- нет функций');
    message += addDeviceAlert(device, 'нет функций');
    continue;
    }
    for (let item of map[key].mappings) {
    if (!item.status_object) {
    errors++;
    message += addDeviceAlert(device, '- пустой топик статуса');
    message += addDeviceAlert(device, 'пустой топик статуса');
    continue;
    }
    }
    }
    }

    alert('Неверно сконфигурированных устройств: ' + errors + '\n' + message);
    console.log('Неверно сконфигурированных устройств: ' + errors + '\n' + message);
    });

    function addDeviceAlert(device, error) {
    error = error || '';
    let row = document.querySelector('[data-row-key="' + device.id + '"]');
    row.style.background = 'pink';
    return device.name + ' ' + error + '\n';
    let message = 'Неверно сконфигурированных устройств: ' + errors + '\n' + message;
    console.log(message);
    alert(message);
    }
    }

    })();
  5. inebritov revised this gist Apr 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion agent-validator.bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    javascript:!function(){function e(e,t){t=t||"";let o=document.querySelector('[data-row-key="'+e.id+'"]');o?o.style.background="pink":alert("Не найдено устройство: "+e.name+" ("+e.id+") "+t)}fetch(location.protocol+"//"+location.host+"/api/v1/devices").then((e=>console.log(e.status)||e)).then((e=>e.text())).then((t=>{let o=JSON.parse(t).devices;o||alert("Нет устройств"),console.log(o);let l=0;for(let t of o){let o=t.feature_mappings;o&&0!=Object.keys(o).length||(l++,e(t))}alert("Неверно сконфигурированных устройств: "+l)}))}();
    javascript:!function(){function e(e,t){return t=t||"",document.querySelector('[data-row-key="'+e.id+'"]').style.background="pink",e.name+" "+t+"\n"}fetch(location.protocol+"//"+location.host+"/api/v1/devices").then((e=>console.log(e.status)||e)).then((e=>e.text())).then((t=>{let o=JSON.parse(t).devices;o||alert("Нет устройств"),console.log(o);let n=0,l="";for(let t of o){let o=t.feature_mappings;if(o&&0!=Object.keys(o).length)for(let s in o)if(o[s].mappings&&0!=o[s].mappings.length)for(let a of o[s].mappings)a.status_object||(n++,l+=e(t,"- пустой топик статуса"));else n++,l+=e(t,"- нет функций");else n++,l+=e(t,"- стерлись функции")}alert("Неверно сконфигурированных устройств: "+n+"\n"+l),console.log("Неверно сконфигурированных устройств: "+n+"\n"+l)}))}();
  6. inebritov revised this gist Apr 22, 2024. 1 changed file with 39 additions and 23 deletions.
    62 changes: 39 additions & 23 deletions agent-validator.js
    Original file line number Diff line number Diff line change
    @@ -16,33 +16,49 @@

    (function () {

    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) {
    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, message = '';
    for (let device of devices) {
    let map = device.feature_mappings;
    if (!map || Object.keys(map).length == 0) {
    errors++;
    message += addDeviceAlert(device, '- стерлись функции');
    continue;
    }

    for (let key in map) {
    if (!map[key].mappings || map[key].mappings.length == 0) {
    errors++;
    addDeviceAlert(device)
    message += addDeviceAlert(device, '- нет функций');
    continue;
    }
    for (let item of map[key].mappings) {
    if (!item.status_object) {
    errors++;
    message += addDeviceAlert(device, '- пустой топик статуса');
    continue;
    }
    }
    }
    }

    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';
    }
    alert('Неверно сконфигурированных устройств: ' + errors + '\n' + message);
    console.log('Неверно сконфигурированных устройств: ' + errors + '\n' + message);
    });

    function addDeviceAlert(device, error) {
    error = error || '';
    let row = document.querySelector('[data-row-key="' + device.id + '"]');
    row.style.background = 'pink';
    return device.name + ' ' + error + '\n';
    }

    })();
  7. inebritov revised this gist Apr 22, 2024. 2 changed files with 17 additions and 0 deletions.
    1 change: 1 addition & 0 deletions agent-validator.bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    javascript:!function(){function e(e,t){t=t||"";let o=document.querySelector('[data-row-key="'+e.id+'"]');o?o.style.background="pink":alert("Не найдено устройство: "+e.name+" ("+e.id+") "+t)}fetch(location.protocol+"//"+location.host+"/api/v1/devices").then((e=>console.log(e.status)||e)).then((e=>e.text())).then((t=>{let o=JSON.parse(t).devices;o||alert("Нет устройств"),console.log(o);let l=0;for(let t of o){let o=t.feature_mappings;o&&0!=Object.keys(o).length||(l++,e(t))}alert("Неверно сконфигурированных устройств: "+l)}))}();
    16 changes: 16 additions & 0 deletions agent-validator.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,19 @@
    /*
    Валидация устройств агента.
    Как использовать:
    1. Открываем страницу агента
    2. Нажимаем Ctrl+Shift+B - отобразить панель закладок браузера
    3. В панели закладок нажимаем правой кнопкой, выбираем добавить
    4. Название "agent validate", а в URL вставляем содержимое файла agent-validator.bookmarklet.js
    5. Сохраняем закладку
    Теперь если на странице агента нажать на эту закладку, скрипт подсветит красным устройства, у которых невалидная конфигурация.
    В последствии, валидация будет добавлена в функции агента по-умолчанию.
    */

    (function () {

    fetch(location.protocol + '//' + location.host + "/api/v1/devices")
  8. inebritov revised this gist Apr 22, 2024. 1 changed file with 27 additions and 22 deletions.
    49 changes: 27 additions & 22 deletions agent-validator.js
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,32 @@
    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('Нет устройств');
    (function () {

    console.log(devices);
    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('Нет устройств');

    let errors = 0;
    for (let device of devices) {
    let map = device.feature_mappings;
    if (!map || Object.keys(map).length == 0) {
    errors++;
    addDeviceAlert(device)
    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);
    });
    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';
    }


    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';
    }
    })();
  9. inebritov created this gist Apr 22, 2024.
    27 changes: 27 additions & 0 deletions agent-validator.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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';
    }