I managed to create rules for this.
Using DSL rules is more advanced than jruby, because you can’t ignore certificate error in java that easy.
I had to create a proper certificate: the certificate must have at least one SAN and it must be imported into java cacerts using keytool.
After creating and installing the certificate: copy the public key into a local file
echo -n | openssl s_client -connect 192.168.xx.yy:4343 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > aruba-cert.pem
and import it into cacerts:
sudo keytool -importcert -file aruba-cert.pem -alias aruba-instant -keystore /etc/ssl/certs/java/cacerts -storepass changeit
The location my be different, it depends your installation. This command tells you the location
readlink -f $(which java)
Afterwards I created this items, which triggers a rule:
Switch http_aruba_wlan_gast "Wlan Gast http" <network> (gAruba)
The first rule turns the ssid on or off. The second rule is for monitoring. It syncs the current status - just in case I had changed the status in Aruba WebUI, or to initialize that item after OH restart.
import java.net.URLEncoder
// Konfigurationsvariablen (global verwendbar)
// Configuration variables (used by all rules)
val baseUrl = "https://192.168.xx.yy:4343"
val username = "admin"
val password = "xxxx"
val ssidName = "Gast"
val contentType = "application/json"
val timeout = 5000
val apIp = "192.168.xx.yy" // IP-Adresse des Aruba IAP (für show-cmd)
rule "Gast WLAN Steuerung"
when
Item http_aruba_wlan_gast received update
then
logInfo("aruba", "WLAN-Gastschalter aktiviert – SSID soll Status: {}", http_aruba_wlan_gast.state.toString)
// 2 Sekunden warten, falls rule "SSID-Status prüfen" aktiv ist;
Thread::sleep(2000)
// Anmeldung beim Aruba Controller (Login)
val loginPayload = '{"user":"' + username + '","passwd":"' + password + '"}'
val loginResponse = sendHttpPostRequest(baseUrl + "/rest/login", contentType, loginPayload, timeout)
if (loginResponse === null) {
logError("aruba", "Login fehlgeschlagen – keine Antwort")
return
}
val loginStatus = transform("JSONPATH", "$.Status", loginResponse)
if (loginStatus != "Success") {
logError("aruba", "Login fehlgeschlagen – API-Status: {}", loginStatus)
return
}
val sid = transform("JSONPATH", "$.sid", loginResponse)
if (sid === null || sid.trim == "") {
logError("aruba", "Session-ID fehlt trotz erfolgreichem Login")
return
}
// logInfo("aruba", "Session-ID erhalten: {}", sid)
logInfo("aruba", "Session-ID erhalten")
// SSID aktivieren (POST zur REST API)
// SSID-Aktion vorbereiten
val ssidPayload = if (http_aruba_wlan_gast.state == ON)
'{"ssid-profile":{"action":"create","ssid-profile":"' + ssidName + '","enable":"yes"}}'
else
'{"ssid-profile":{"action":"create","ssid-profile":"' + ssidName + '","disable":"yes"}}'
// SSID schalten
val ssidUrl = baseUrl + "/rest/ssid?sid=" + sid
// logInfo("aruba", "Sende Aktivierungsbefehl für SSID '{}' an {}", ssidName, ssidUrl)
logInfo("aruba", "Sende Aktivierungsbefehl für SSID '{}'", ssidName)
val ssidResponse = sendHttpPostRequest(ssidUrl, contentType, ssidPayload, timeout)
if (ssidResponse === null) {
logError("aruba", "SSID-Steuerung fehlgeschlagen")
} else {
// logInfo("aruba", "SSID erfolgreich aktiviert: {}", ssidResponse)
logInfo("aruba", "SSID erfolgreich neuen Status gesetzt: {}", http_aruba_wlan_gast.state.toString)
}
// Abmelden (Logout)
val logoutPayload = '{"sid":"' + sid + '"}'
val logoutUrl = baseUrl + "/rest/logout"
val logoutResponse = sendHttpPostRequest(logoutUrl, contentType, logoutPayload, timeout)
if (logoutResponse === null) {
logWarn("aruba", "Logout fehlgeschlagen")
} else {
logInfo("aruba", "Logout erfolgreich")
}
end
rule "SSID-Status prüfen bei Systemstart"
when
Item A_SystemStartet received update OFF or
Item http_aruba_wlan_gast_status received update or
Time cron "0 24 * * * ?" // jede Stunde *:24
then
logInfo("aruba", "Starte SSID-Statusprüfung")
// Login
val loginPayload = '{"user":"' + username + '","passwd":"' + password + '"}'
val loginResponse = sendHttpPostRequest(baseUrl + "/rest/login", contentType, loginPayload, timeout)
if (loginResponse === null) {
logError("aruba", "Login fehlgeschlagen – keine Antwort")
return
}
val loginStatus = transform("JSONPATH", "$.Status", loginResponse)
if (loginStatus != "Success") {
logError("aruba", "Login fehlgeschlagen – API-Status: {}", loginStatus)
return
}
val sid = transform("JSONPATH", "$.sid", loginResponse)
if (sid === null || sid.trim == "") {
logError("aruba", "Session-ID konnte nicht extrahiert werden")
return
}
// logInfo("aruba", "Session-ID erhalten: {}", sid)
logInfo("aruba", "Session-ID erhalten")
// CLI-Command abrufen: show running-config
val cmd = "show running-config"
val encodedCmd = URLEncoder::encode(cmd, "UTF-8")
val showCmdUrl = baseUrl + "/rest/show-cmd?sid=" + sid + "&iap_ip_addr=" + apIp + "&cmd=" + encodedCmd
val cliResponse = sendHttpGetRequest(showCmdUrl, timeout)
if (cliResponse === null) {
logError("aruba", "Keine Antwort auf show-cmd erhalten")
} else {
val outputRaw = transform("JSONPATH", "$.['Command output']", cliResponse)
val output = outputRaw.replace("\\n", "\n")
//logInfo("aruba", "CLI-Ausgabe:\n{}", output)
// SSID-Zustand ermitteln (enabled/disabled)
if (output.contains("wlan ssid-profile " + ssidName + "\n enable")) {
logInfo("aruba", "SSID '{}' ist AKTIV", ssidName)
http_aruba_wlan_gast.postUpdate(ON)
} else if (output.contains("wlan ssid-profile " + ssidName + "\n disable")) {
logInfo("aruba", "SSID '{}' ist DEAKTIVIERT", ssidName)
http_aruba_wlan_gast.postUpdate(OFF)
} else {
logWarn("aruba", "SSID '{}' nicht eindeutig im CLI-Output erkannt", ssidName)
}
}
// Logout
val logoutPayload = '{"sid":"' + sid + '"}'
val logoutResponse = sendHttpPostRequest(baseUrl + "/rest/logout", contentType, logoutPayload, timeout)
if (logoutResponse === null) {
logWarn("aruba", "Logout fehlgeschlagen")
} else {
logInfo("aruba", "Logout erfolgreich")
}
end
thank you for your helb, rlkoshak and @jimtng !