Files
matrix/hookshot/proxmox.js

18 lines
1.1 KiB
JavaScript
Raw Normal View History

var embed = (data.embeds && data.embeds[0]) || {};
var title = embed.title || 'Proxmox Notification';
var description = embed.description || '';
var fields = embed.fields || [];
var fieldMap = {};
fields.forEach(function(f) { fieldMap[f.name] = f.value; });
var severity = (fieldMap['Severity'] || 'info').toLowerCase();
var node = fieldMap['Node'] || '';
var type = fieldMap['Type'] || '';
var vmid = fieldMap['VM/CT ID'] || '';
var emoji = severity === 'error' ? '🔴' : (severity === 'warning' ? '🟡' : '');
var lines = [emoji + ' ' + title];
var htmlParts = ['<b>' + emoji + ' ' + title + '</b>'];
if (node) { lines.push('\uD83D\uDDA5\uFE0F Node: ' + node); htmlParts.push('\uD83D\uDDA5\uFE0F Node: <b>' + node + '</b>'); }
if (type) { lines.push('\uD83D\uDCCB Type: ' + type); htmlParts.push('\uD83D\uDCCB Type: ' + type); }
if (vmid && vmid !== 'N/A') { lines.push('\uD83D\uDD32 VM/CT: ' + vmid); htmlParts.push('\uD83D\uDD32 VM/CT: ' + vmid); }
if (description) { lines.push(description); htmlParts.push(description); }
result = { version: 'v2', plain: lines.join('\n'), html: htmlParts.join('<br>'), msgtype: 'm.notice' };