motd-gen

my Message of the Day scripts
git clone git://git.ckyln.com/motd-gen
Log | Files | Refs | README | LICENSE

99-alert-scripts.motd (814B)


      1 CHECKFILE=/etc/motd-check
      2 
      3 # So the checkfile is a csv file
      4 # the first value is what service it
      5 # is.
      6 
      7 # For a runit service, it starts with r
      8 # For a docker container it starts with d
      9 # For a systemd service, it starts with s
     10 
     11 systemdcheck() {
     12 	systemctl is-active "$1" >/dev/null 2>&1 || printf "\033[1;31mALERT: \033[0;00m$1 is not active\\n"
     13 }
     14 
     15 runitcheck() {
     16 	sv stat "$1" | grep -q down && printf "\033[1;31mALERT: \033[0;00m$1 is not active\\n"
     17 }
     18 
     19 dockercheck() {
     20 	docker container ls | grep -q "$1" || printf "\033[1;31mALERT: \033[0;00m$1 is not up\\n"
     21 }
     22 
     23 check() {
     24 	while IFS=, read -r service program ; do
     25 		case "$service" in
     26 			s) systemdcheck "$program" ;;
     27 			r) runitcheck "$program" ;;
     28 			d) dockercheck "$program" ;;
     29 		esac
     30 	done < "$CHECKFILE"
     31 }
     32 
     33 [ -n "$CHECKFILE" ] && check
     34 
     35 # vim:filetype=sh