Mainly add external monitoring of mail server
[distro-setup] / system-status
old mode 100755 (executable)
new mode 100644 (file)
index ddb5b73..747e2a6
@@ -31,6 +31,10 @@ write-status() {
   if [[ -e ${glob[0]} ]]; then
     chars+=("STALE!")
   fi
+  if [[ $(find /var/mail -type f \! -empty -print -quit) ]]; then
+    var_mail_msg="message in /var/mail"
+  fi
+  lo -1 var_mail $var_mail_msg
   glob=(/m/md/bounces/new/*)
   if [[ -e ${glob[0]} ]]; then
     chars+=("BOUNCE!")
@@ -50,64 +54,92 @@ write-status() {
     qlen=$(sudo /usr/sbin/exiqgrep -o 60 -c -b | awk '{print $1}')
   fi
   if ((qlen)); then
+    qmsg="queue length $qlen"
     chars+=("q $qlen")
   fi
-
-  cd /b/ds
-  if ! make -q ~/.local/distro-begin || [[ $(<~/.local/distro-begin) != 0 ]]; then
-    chars+=("DISTRO-BEGIN!")
+  case $HOSTNAME in
+    # No point in emailing about the mailq on a host where we don't
+    # check email.
+    $MAIL_HOST|l2)
+      lo -1 qlen $qmsg
+      ;;
+  esac
+
+  begin=false
+  if ! make -C /b/ds -q ~/.local/distro-begin || [[ $(<~/.local/distro-begin) != 0 ]]; then
+    begin=true
   fi
 
-  if ! make -q ~/.local/distro-end || [[ $(<~/.local/distro-end) != 0 ]]; then
-    chars+=("DISTRO-END!")
+  end=false
+  if ! make -C /b/ds -q ~/.local/distro-end || [[ $(<~/.local/distro-end) != 0 ]]; then
+    end=true
   fi
 
-  f=~/.local/conflink
-  for _ in 1; do
-    if [[ -e $f ]]; then
-      now=$(date +%s)
-      fsec=$(stat -c%Y $f)
-      # the / 60 makes it 0-59 seconds less strict, +1 makes sure we
-      # dont have any false positives.
-      fmin=$(( (fsec - now ) / 60 + 1 ))
-      fminplus=$(( fmin + 60*24 ))
-      # Filesystem files get copied, so find any newer than the last run.
-      # The rest are hueristics:
-      # Given the last time we added a file in git, is that newer than the last conflink run.
-      # Given new files not added to git, were they modified more recently than the last conflink? but,
-      # push their modification time back by a day so we can develop them before needing to add them to git.
-
-      all_dirs=({/a/bin/ds,/p/c}{/filesystem,/machine_specific/$HOSTNAME/filesystem})
-      # This part is copied from conflink
-      for x in /p/c/machine_specific/*.hosts /a/bin/ds/machine_specific/*.hosts; do
-        if grep -qxF $HOSTNAME $x; then all_dirs+=( ${x%.hosts} ); fi
-      done
-
-      # just because i forget a lot, -mmin -NUM means files modified <= NUM minutes ago
-      if (( $(date -d "$(git log --diff-filter=ACR --format=%aD -1)" +%s) > fsec )) || \
-           [[ $(find ${all_dirs[@]} -mmin $fmin -type f -print -quit 2>/dev/null) ]]; then
-        v conflink newer git or newer filesystem files
-        chars+=("CONFLINK!")
-        break
-      fi
-
-      for d in /a/bin/distro-setup /p/c; do
-        cd $d
-        untracked=$(git ls-files -o --exclude-standard)
-        if [[ $untracked && $(find $untracked -mmin $fminplus -type f -print -quit) ]]; then
-          v conflink: untracked in $d
+  # these conditions are so we dont have an overly verbose prompt
+  if $begin && $end; then
+    chars+=("DISTRO!")
+  elif $begin; then
+    chars+=("DISTRO-BEGIN!")
+  elif $end; then
+    chars+=("DISTRO-END!")
+  else
+    f=~/.local/conflink
+    for _ in 1; do
+      if [[ -e $f ]]; then
+        now=$(date +%s)
+        fsec=$(stat -c%Y $f)
+        # the / 60 makes it 0-59 seconds less strict, +1 makes sure we
+        # dont have any false positives.
+        fmin=$(( (fsec - now ) / 60 + 1 ))
+        fminplus=$(( fmin + 60*24 ))
+        # Filesystem files get copied, so find any newer than the last run.
+        # The rest are hueristics:
+        # Given the last time we added a file in git, is that newer than the last conflink run.
+        # Given new files not added to git, were they modified more recently than the last conflink? but,
+        # push their modification time back by a day so we can develop them before needing to add them to git.
+
+        all_dirs=({/a/bin/ds,/p/c}{/filesystem,/machine_specific/$HOSTNAME/filesystem})
+        # This part is copied from conflink
+        for x in /p/c/machine_specific/*.hosts /a/bin/ds/machine_specific/*.hosts; do
+          if grep -qxF $HOSTNAME $x; then all_dirs+=( ${x%.hosts} ); fi
+        done
+
+        # just because i forget a lot, -mmin -NUM means files modified <= NUM minutes ago
+        if   [[ $(find ${all_dirs[@]} -mmin $fmin -type f -print -quit 2>/dev/null) ]]; then
+          v conflink newer filesystem files
           chars+=("CONFLINK!")
           break
         fi
-      done
 
-    fi
-    if [[ ! -e $f || $(<$f) != 0 ]]; then
-      v conflink: last run not found or failed
-      chars+=("CONFLINK!")
-      break
-    fi
-  done
+        for d in /a/bin/distro-setup /p/c; do
+          cd $d
+          if [[ ! -e .git ]]; then
+            # some hosts i dont push all of /p/c
+            continue
+          fi
+          if (( $(date -d "$(git log --diff-filter=ACR --format=%aD -1)" +%s) > fsec )); then
+            v conflink: newer files checked in to git
+            chars+=("CONFLINK!")
+            break
+          fi
+
+          untracked=$(git ls-files -o --exclude-standard)
+          if [[ $untracked && $(find $untracked -mmin $fminplus -type f -print -quit) ]]; then
+            v conflink: untracked in $d
+            chars+=("CONFLINK!")
+            break
+          fi
+        done
+        cd /
+
+      fi
+      if [[ ! -e $f || $(<$f) != 0 ]]; then
+        v conflink: last run not found or failed
+        chars+=("CONFLINK!")
+        break
+      fi
+    done
+  fi
 
 
   ## Clean the paniclog, but only up to 4 times per day, or else we
@@ -149,7 +181,7 @@ write-status() {
     # Profiled it using time and also adding to the top of the file:
     # set -x
     # PS4='+ $(date "+%2N") '
-    snaps=($(ls -1avdr /mnt/root/btrbk/$vol.20*|head -n1))
+    snaps=($(ls -1avdr /mnt/root/btrbk/$vol.20*|head -n1 || [[ $? == 141 ]] ))
     now=$(date +%s)
     maxtime=0
     for s in ${snaps[@]}; do
@@ -160,7 +192,7 @@ write-status() {
       fi
     done
     if (( maxtime < now - 60*60 )); then
-      chars+=("OLD-SNAPSHOT!")
+      chars+=("OLD-SNAP!")
       snapshotmsg="/o snapshot older than 1 hour"
     fi
     lo -1 old-snapshot $snapshotmsg