Skip to content

Commit

Permalink
v0.2.1 release
Browse files Browse the repository at this point in the history
- handle when receiving an API 400 error. Escape the message so that the next flush does not also fail.
  • Loading branch information
n-hass committed May 23, 2024
1 parent 8bc3490 commit e7c8a7f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"envFile": "/root/.config/telelog/env",
"args": [
"-c",
"example/telelog.toml"
// "-c",
// "example/telelog.toml"
],
"cwd": "${workspaceFolder}",
},
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "telelog"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

[dependencies]
Expand Down
22 changes: 10 additions & 12 deletions example/telelog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ chat_id = "123456"
flush_seconds = 5

[match]
1 = {field="PRIORITY", value="5"}
1 = {field="PRIORITY", value=[
"5",
"4",
"3",
"2",
"1",
"0",
]}

[deny]
1 = {field="SYSLOG_IDENTIFIER", value="aardvark-dns|scrutiny|caddy|overseerr|winbindd|sabnzbd|calibre|samba-dcerpcd|rpcd_lsad|rpcd_mdssvc|rpcd_classic|rpcd_winreg"}
1 = {field="SYSLOG_IDENTIFIER", value="smbd"}
2 = {field="MESSAGE", value=[
"RequiresMountsFor=|podman-.*\\.service",
"unix_listener: cannot bind to path /run/user/0/gnupg/S.gpg-agent",
"auto-fix-vscode-server.service: Failed to open",
"nixos-rebuild-switch-to-configuration.service.*No such file or directory",
], rule="any"}
3 = [
{field="SYSLOG_IDENTIFIER", value="plex"},
Expand All @@ -21,20 +25,14 @@ flush_seconds = 5
], rule="any"}
]
4 = [
{field="SYSLOG_IDENTIFIER", value="private-wg"},
{field="SYSLOG_IDENTIFIER", value="vpn"},
{field="MESSAGE", value=[
"Loading configuration\\.\\.\\.",
"Configuration loaded\\.",
"Config saving\\.\\.\\.",
"Config saved\\.",
"Config syncing\\.\\.\\.",
"Config synced\\.",
"changing ownership of '\\/config\\/wg_confs': Read-only file system",
"\\/config\\/wg_confs\\/wg0\\.conf' is world accessible",
"ip link add wg0 type wireguard",
"wg setconf wg0 \\/dev\\/fd\\/63",
"ip -4 address add 10.254.33.0\\/24 dev wg0",
"ip link set mtu 1420 up dev wg0",
], rule="any"}
]

Expand Down
18 changes: 18 additions & 0 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,22 @@ pub fn colour_translate(priority: u8) -> String {
7 => "⚪️".to_owned(),
_ => "❓".to_owned(),
}
}

pub fn escape_message(message: &str) -> String {
let mut message = message.to_string();
if message.starts_with("<code>") {
message = message.strip_prefix("<code>").unwrap_or("").to_string();
}

if message.ends_with("</code>") {
message = message.strip_suffix("</code>").unwrap_or("").to_string();
}

message
.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&#39;")
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn main() {

let args = parse_cli_args();

println!("[telelog] Starting telelog v0.2.0");
println!("[telelog] Starting telelog v0.2.1");

let config_path = match args.get_one::<PathBuf>("config") {
Some(path) => path.to_str().unwrap(),
Expand Down
4 changes: 4 additions & 0 deletions src/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ async fn flush_log_buffer() {

failed_unsent_messages.push(message.to_string());
},
400 => {
println!("[telegram] API response 400. Escaping whole message for next flush... ");
failed_unsent_messages.push(escape_message(&message))
},
_ => {
println!("[telegram] API response {}: {:?}", status, text);
failed_unsent_messages.push(message.to_string());
Expand Down

0 comments on commit e7c8a7f

Please sign in to comment.