4: Use severity in request to PushOver
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# Asset Direction Target TRIGGER SEVERITY NOTE
|
# Asset Direction Target TRIGGER SEVERITY NOTE
|
||||||
#############################################################
|
#############################################################
|
||||||
SOL BELOW 170.0 ONETIME CRITICAL "EMERGENCY: Risiko for Perps Solana long LIKVIDERING!"
|
SOL BELOW 170.0 ONETIME INFO "EMERGENCY: Risiko for Perps Solana long LIKVIDERING!"
|
||||||
#SOL BELOW 71.4 ONETIME CRITICAL "CRITICAL: Risiko for Solana Raydium LÅN LIKVIDERING!"
|
#SOL BELOW 71.4 ONETIME CRITICAL "CRITICAL: Risiko for Solana Raydium LÅN LIKVIDERING!"
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package com.r35157.jupiterperpsalarm;
|
package com.r35157.jupiterperpsalarm;
|
||||||
|
|
||||||
public enum AlarmSeverity {
|
public enum AlarmSeverity {
|
||||||
EMERGENCY, // Repeated wake-up alarm
|
EMERGENCY, // Repeated wake-up alarm - sound always
|
||||||
CRITICAL, // One-shot wake-up alarm
|
CRITICAL, // One-shot wake-up alarm - sound always
|
||||||
WARN, // Audible warning respecting quiet hours
|
WARN, // Audible warning - respecting quiet hours though
|
||||||
INFO, // Low-priority visible notification
|
INFO, // Normal notification with visual and audible feedback
|
||||||
SILENT // No user interruption
|
SILENT, // Low-priority notification - visual feedback without sound/vibration
|
||||||
|
GHOST // No visual/audible notification - only visible inside the Pushover app
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.r35157.jupiterperpsalarm.impl.ref;
|
package com.r35157.jupiterperpsalarm.impl.ref;
|
||||||
|
|
||||||
|
import com.r35157.jupiterperpsalarm.AlarmSeverity;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
@@ -28,13 +30,13 @@ public final class PushoverAlarmAction implements AlarmAction {
|
|||||||
price.slot()
|
price.slot()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Severity and note are intentionally parsed and retained in the model,
|
// TODO: Note is intentionally parsed and retained in the model, but are not used by Pushover yet.
|
||||||
// but are not used by Pushover yet.
|
// https://git.r35157.com/r35157/com_r35157_nenjim-hubd-impl_ref/issues/7
|
||||||
String body = form("token", applicationToken) + "&" +
|
String body = form("token", applicationToken) + "&" +
|
||||||
form("user", userKey) + "&" +
|
form("user", userKey) + "&" +
|
||||||
form("title", title) + "&" +
|
form("title", title) + "&" +
|
||||||
form("message", message) + "&" +
|
form("message", message) + "&" +
|
||||||
"priority=2&retry=30&expire=10800&sound=persistent";
|
createPushoverSeverityParameters(alarm.severity());;
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.newBuilder(PUSHOVER_URI)
|
HttpRequest request = HttpRequest.newBuilder(PUSHOVER_URI)
|
||||||
.timeout(Duration.ofSeconds(15))
|
.timeout(Duration.ofSeconds(15))
|
||||||
@@ -56,7 +58,7 @@ public final class PushoverAlarmAction implements AlarmAction {
|
|||||||
response.body()
|
response.body()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Pushover emergency alarm sent.");
|
System.out.println("Pushover alarm sent: " + alarm.severity());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -66,6 +68,17 @@ public final class PushoverAlarmAction implements AlarmAction {
|
|||||||
URLEncoder.encode(value, StandardCharsets.UTF_8);
|
URLEncoder.encode(value, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String createPushoverSeverityParameters(AlarmSeverity severity) {
|
||||||
|
return switch (severity) {
|
||||||
|
case EMERGENCY -> "priority=2&retry=30&expire=10800&sound=persistent";
|
||||||
|
case CRITICAL -> "priority=1&sound=spacealarm";
|
||||||
|
case WARN -> "priority=0&sound=siren";
|
||||||
|
case INFO -> "priority=0";
|
||||||
|
case SILENT -> "priority=-1";
|
||||||
|
case GHOST -> "priority=-2";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private final HttpClient httpClient = HttpClient.newHttpClient();
|
private final HttpClient httpClient = HttpClient.newHttpClient();
|
||||||
private final String applicationToken;
|
private final String applicationToken;
|
||||||
private final String userKey;
|
private final String userKey;
|
||||||
|
|||||||
Reference in New Issue
Block a user