From 62074707c95538f0477e8dbfa6597b6b5dc63bba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Sachse?= <Joerg.Sachse@slub-dresden.de>
Date: Fri, 18 Feb 2022 09:33:29 +0100
Subject: [PATCH] feat: add Bash functions to count SubApp error mails

---
 tasks/configure_processing_user.yml | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tasks/configure_processing_user.yml b/tasks/configure_processing_user.yml
index a7dc221..e1022d2 100644
--- a/tasks/configure_processing_user.yml
+++ b/tasks/configure_processing_user.yml
@@ -22,6 +22,31 @@
     marker: "# {mark} ANSIBLE MANAGED BLOCK - SubApp-specific"
     state: present
     block: |
+      ta_get_error_mails() (
+        if [[ $1 != "" ]]; then YEAR="$1"
+        else YEAR="$( date +%Y )"
+        fi
+        LOG="/var/log/subapp/$(hostname)/staff_mails.log"
+        ( if [ -e ${LOG} ]; then
+            cat ${LOG}
+          fi
+          if compgen -G "${LOG}.*.lz" > /dev/null; then
+            lzip -cd "${LOG}.*.lz"
+          fi
+          if compgen -G "${LOG}.*.gz" > /dev/null; then
+            zcat "${LOG}.*.gz"
+          fi
+        ) | grep "\[$YEAR" | grep -o "slub\.lza\.staff.*"
+      )
+
+      ta_get_error_mail_count_all() (
+          ta_get_error_mails $1 | wc -l
+      )
+
+      ta_get_error_mail_count_dedup() (
+          ta_get_error_mails $1 | sort | uniq | wc -l
+      )
+
       cd ~
 
 - name: Add aliases for SubApp user
-- 
GitLab