Sie zeigen eine alte Version dieser Seite an. Zeigen Sie die aktuelle Version an.

Unterschiede anzeigen Seitenhistorie anzeigen

Version 1 Aktuelle »

Unter Einstellungen > Schnittstellen > Datenübergabe > Lua Scripts können Sie beliebige Systeme anbinden, sofern diese über eine öffentlich erreichbare Schnittstelle verfügen.


Alamos FE2


Eingabeparameter

Eingabeparameter
[
  {
    "type": "password",
    "key": "apiKey",
    "label": "API Key *"
  },
  {
    "type": "text",
    "key": "fe2Id",
    "label": "FE2-Identifikation *"
  },
  {
    "type": "text",
    "key": "customerId",
    "label": "Kunden-Identifikation"
  },
  {
    "type": "password",
    "key": "password",
    "label": "Verschlüsselungspasswort * (min. 16 Zeichen)"
  },
  {
    "type": "text",
    "key": "partnerName",
    "label": "Partner Name"
  }
]


Script

Script
local fetch = require "fetch"
local json = require "json"
local encoding = require "encoding"
local crypto = require "crypto"

local function isEmpty(value)
    return value == "" or value == nil or value == json.null
end

assert(event.model == "alarm", "Nur Alarm Events werden unterstützt")
assert(not isEmpty(configuration.fe2Id), "FE2-Identifikation muss gesetzt sein")
assert(not isEmpty(configuration.apiKey), "API Key muss gesetzt sein")
assert(not isEmpty(configuration.customerId), "Kunden-Identifikation")
assert(not isEmpty(configuration.password), "Verschlüsselungspasswort muss gesetzt sein")
assert(typeof(configuration.password) == "string" and configuration.password:len() >= 16, "Verschlüsselungspasswort muss min. 16 Zeichen lang sein")
configuration.partnerName = configuration.partnerName or "DIVERA 24/7"


local alarm = event.payload

local externalId = `{alarm.id}`
if not isEmpty(alarm.foreign_id) then
    externalId = alarm.foreign_id
end

local payload = {
    type = "ALARM",
    timestamp = alarm.ts_update,
    sender = configuration.sender or `DIVERA Einheit {alarm.cluster_id}`,
    authorization = configuration.authorization,
    data = {
        externalId = externalId,
        message = { alarm.text },
        keyword = alarm.title,
        units = { },
        vehicles = { }
    }
}


payload.data.location = {}

if not isEmpty(alarm.lat) and not isEmpty(alarm.lng) then
    payload.data.location.coordinate = { alarm.lng, alarm.lat }
end

if not isEmpty(alarm.address) then
    payload.data.custom = { location_dest = alarm.address }
end

-- Gruppen zu units hinzufügen
if next(event.payload.groups) ~= "nil" then
    for key,value in event.payload.groups do
        table.insert(payload.data.units, {address = event.payload.groups[key].title})
    end
end

-- Fahrzeuge zu units hinzufügen
if next(event.payload.vehicles) ~= "nil" then
    for key,value in event.payload.vehicles do
        table.insert(payload.data.vehicles, {name = event.payload.vehicles[key].name})
    end
end

local password = crypto.subtle.importKey("raw", configuration.password, "PBKDF2", false)
local salt = crypto.getRandomValues(buffer.create(64))
local key = crypto.subtle.deriveKey({
    name = "PBKDF2",
    hash = "SHA-1",
    salt = salt,
    iterations = 5000
}, password, {
    name = "AES-CBC",
    length = 256
}, false)

local iv = crypto.getRandomValues(buffer.create(16))
local encryptedMessage = crypto.subtle.encrypt(
    {
        name = "AES-CBC",
        iv = iv
    },
    key,
    json.encode(payload)
)

local cloudPayload = {
    iv = encoding.encode("BASE64", iv),
    salt = encoding.encode("BASE64", salt),
    encryptedMessage = encoding.encode("BASE64", encryptedMessage),
    nameOfPartner = configuration.partnerName,
    apiKey = configuration.apiKey,
    topic = `{configuration.fe2Id}{configuration.customerId}`,
    messageIdentifier = crypto.randomUUID()
}

print(json.encode(cloudPayload))

local url =  "https://tpac.alamos-gmbh.bayern/thirdparty/alarm"
local response = fetch.post(url, {
    contentType = "application/json",
    data = json.encode(cloudPayload)
})

print(response.body)



VOMATEC FLOW


Eingabeparameter

Eingabeparameter

 


Script

Script

 



Zum Zeitpunkt der Veröffentlichung der einzelnen Scripts waren diese funktionstüchtig und mit dem jeweiligen Drittsystem kompatibel.

Wir geben jedoch keine Gewährleistung auf die uneingeschränkte und dauerhafte Funktionalität der vorgestellten Lua Scripts.

Verwandte Artikel

  • Keine Stichwörter