/** * NIS2 Agile — Gestione Connettori Discovery (mappatura rete/cloud → auto-popola Inventario). * Usa api.js (CRUD) + helper di common.js (escHtml/showModal/closeModal/showNotification). */ (function () { 'use strict'; function esc(s) { s = (s == null) ? '' : String(s); return (typeof escHtml === 'function') ? escHtml(s) : s.replace(/[&<>"]/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"' }[c]; }); } function notify(m, t) { if (typeof showNotification === 'function') showNotification(m, t || 'info'); else alert(m); } function fmtDate(s) { if (!s) return '—'; try { return new Date(String(s).replace(' ', 'T')).toLocaleString('it-IT', { timeZone: 'Europe/Rome' }); } catch (e) { return s; } } var INGEST_URL = location.origin + '/api/services/assets-ingest'; async function loadList() { var el = document.getElementById('dc-list'); el.innerHTML = 'Caricamento…'; var r = await api.get('/discovery-connectors/list'); if (!r || !r.success) { el.innerHTML = '
Nessun connettore. Creane uno con «+ Nuovo connettore».
'; return; } var html = '| Nome | Tipo | Stato | Ultimo run | Asset | Chiave | |
|---|---|---|---|---|---|---|
| ' + esc(c.name) + ' | ' + '' + esc(c.connector_type) + ' | ' + '' + esc(c.status) + ' | ' + '' + fmtDate(c.last_run_at) + (c.last_status ? (' (' + esc(c.last_status) + ')') : '') + ' | ' + '' + (c.last_discovered != null ? esc(c.last_discovered) : '—') + ' | ' + '' + esc(c.key_prefix || '—') + '… | '
+ '' + ' ' + ' ' + '' + ' |
Copia ORA questa chiave: non sarà più visibile.
' + '' + '' + 'Endpoint ingest: ' + esc(INGEST_URL) + ' · scope ingest:assets. Agente: scripts/discovery-agent.mjs.
Tipo: ' + esc(c.connector_type) + ' · Stato: ' + esc(c.status) + ' · Schedulazione: ' + esc(c.schedule) + '
' + 'Target: ' + esc(targets) + '
' + 'Chiave: ' + esc(c.key_prefix || '—') + '… · ultimo run: ' + fmtDate(c.last_run_at) + '
| Quando | Esito | Asset | Flussi | Note |
|---|
Nessun run ancora. Esegui l\'agente di discovery con la chiave di questo connettore.
'); showModal('Connettore: ' + esc(c.name), body, { size: 'lg', footer: '' }); } async function rotate(id, name) { if (!confirm('Rigenerare la chiave di «' + name + '»? La vecchia smetterà di funzionare.')) return; var r = await api.post('/discovery-connectors/' + id + '/rotateKey', {}); if (r && r.success) { keyModal('Nuova chiave API', r.data.api_key, name); loadList(); } else { notify('Errore nella rigenerazione', 'danger'); } } async function remove(id, name) { if (!confirm('Eliminare il connettore «' + name + '»? La sua chiave verrà disattivata.')) return; var r = await api.del('/discovery-connectors/' + id); if (r && r.success) { notify('Connettore eliminato', 'success'); loadList(); } else { notify('Errore nell\'eliminazione', 'danger'); } } function init() { var b = document.getElementById('btn-dc-new'); if (b) b.onclick = function () { var f = document.getElementById('dc-form-card'); f.style.display = (f.style.display === 'none') ? 'block' : 'none'; }; var bc = document.getElementById('btn-dc-create'); if (bc) bc.onclick = create; var bx = document.getElementById('btn-dc-cancel'); if (bx) bx.onclick = function () { document.getElementById('dc-form-card').style.display = 'none'; }; loadList(); } window.DiscoveryUI = { init: init, detail: detail, rotate: rotate, remove: remove }; })();