mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 10:19:09 +00:00 
			
		
		
		
	Use `systemd-escape --unescape` to restore human-readable unit identifiers in Telegram and Email alerts. Also ensure Telegram messages are URL-encoded and Email status checks try both raw and escaped forms for robustness. Fixes issue where slashes were shown as dashes in notifications. Context: see ChatGPT conversation https://chatgpt.com/share/68a4c171-db08-800f-8399-7e07f237a441
		
			
				
	
	
		
			25 lines
		
	
	
		
			684 B
		
	
	
	
		
			Django/Jinja
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			684 B
		
	
	
	
		
			Django/Jinja
		
	
	
	
	
	
| #!/bin/bash
 | |
| set -u
 | |
| # Reverse systemd escaping for human-readable mail subject/body
 | |
| friendly="$(systemd-escape --unescape "$1")"
 | |
| 
 | |
| # Try status with given arg; if empty, also try the escaped version
 | |
| STATUS_OUT="$(systemctl status --full "$1" 2>/dev/null | head -n 30)"
 | |
| if [ -z "$STATUS_OUT" ]; then
 | |
|   esc="$(systemd-escape "$1")"
 | |
|   STATUS_OUT="$(systemctl status --full "$esc" 2>/dev/null | head -n 30)"
 | |
| fi
 | |
| 
 | |
| /usr/bin/sendmail -t <<ERRMAIL
 | |
| To: {{ users.administrator.email }}
 | |
| From: systemd <{{ users['no-reply'].email }}>
 | |
| Subject: ${friendly}
 | |
| Content-Transfer-Encoding: 8bit
 | |
| Content-Type: text/plain; charset=UTF-8
 | |
| 
 | |
| A problem with the service ${friendly} occurred:
 | |
| 
 | |
| $STATUS_OUT
 | |
| 
 | |
| ERRMAIL
 |