"Fossies" - the Fresh Open Source Software Archive

Member "mosshe/functions.postfix" (9 Sep 2020, 6281 Bytes) of package /linux/privat/old/mosshe.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    4 #
    5 #   function library - please call with external script
    6 #
    7 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    8 
    9 #############################################################################
   10 # MoSSHe: remote server monitoring environment
   11 #
   12 # Copyright (C) 2013- Volker Tanger
   13 #
   14 # This program is free software; you can redistribute it and/or
   15 # modify it under the terms of the GNU General Public License
   16 # as published by the Free Software Foundation; either version 2
   17 # of the License, or (at your option) any later version.
   18 #
   19 # For bug reports and suggestions or if you just want to talk to me please
   20 # contact me at volker.tanger@wyae.de
   21 #
   22 # Updates will be available at  http://www.wyae.de/software/mosshe/
   23 # please check there for updates prior to submitting patches!
   24 #
   25 # For list of changes please refer to the HISTORY file. Thanks.
   26 #############################################################################
   27 
   28 
   29 
   30 #############################################################################
   31 # Postfix checks - functions below
   32 #############################################################################
   33 
   34 
   35 #---------------------------------------------------------
   36 # PostfixOutTLS - WARN ALERT
   37 #---------------------------------------------------------
   38 PostfixOutTLS () {
   39     MossheLog "PostfixOutTLS $1 $2"
   40     typeset -i ALERT WARN VALUE  RTN
   41     WARN=$1
   42     ALERT=$2
   43     if [ -n "$(which journalctl)" ]; then
   44     VALUE=`journalctl --since "5 minute ago" | fgrep postfix/smtp[ | fgrep 'TLS connection established to ' | wc -l`
   45     if [ "$VALUE" -gt "$ALERT" ]; then 
   46         STATUS="ALERT"
   47         MESSAGE="Excessive TLS connections for Postfix $MYGROUP: $MYNAME "
   48     elif [ "$VALUE" -gt "$WARN" ]; then 
   49         STATUS="WARN"
   50         MESSAGE="High number of TLS connections for Postfix $MYGROUP: $MYNAME "
   51     else
   52         STATUS="OK"
   53         MESSAGE="Normal TLS connection rate by Postfix $MYGROUP: $MYNAME "
   54     fi
   55     echo "${DATIM};$MYGROUP;$MYNAME;PostfixOutTLS;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
   56     else
   57         echo "${DATIM};$MYGROUP;$MYNAME;PostfixOutTLS;-5;not a SYSTEMD system" >> $TEMPDIR/tmp.$$.collected.tmp             
   58     fi
   59 }
   60 
   61 
   62 #---------------------------------------------------------
   63 # PostfixInTLS - WARN ALERT
   64 #---------------------------------------------------------
   65 PostfixInTLS () {
   66     MossheLog "PostfixInTLS $1 $2"
   67     typeset -i ALERT WARN VALUE  RTN
   68     WARN=$1
   69     ALERT=$2
   70     if [ -n "$(which journalctl)" ]; then
   71     VALUE=`journalctl --since "5 minute ago" | fgrep postfix/smtpd | fgrep 'TLS connection established from ' | wc -l`
   72     if [ "$VALUE" -gt "$ALERT" ]; then 
   73         STATUS="ALERT"
   74         MESSAGE="Excessive TLS connections for Postfix $MYGROUP: $MYNAME "
   75     elif [ "$VALUE" -gt "$WARN" ]; then 
   76         STATUS="WARN"
   77         MESSAGE="High number of TLS connections for Postfix $MYGROUP: $MYNAME "
   78     else
   79         STATUS="OK"
   80         MESSAGE="Normal TLS connection rate by Postfix $MYGROUP: $MYNAME "
   81     fi
   82     echo "${DATIM};$MYGROUP;$MYNAME;PostfixInTLS;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
   83     else
   84         echo "${DATIM};$MYGROUP;$MYNAME;PostfixInTLS;-5;not a SYSTEMD system" >> $TEMPDIR/tmp.$$.collected.tmp              
   85     fi
   86 }
   87 
   88 
   89 #---------------------------------------------------------
   90 # PostfixInConnections - WARN ALERT
   91 #---------------------------------------------------------
   92 PostfixInConnections () {
   93     MossheLog "PostfixInConnections $1 $2"
   94     typeset -i ALERT WARN VALUE  RTN
   95     WARN=$1
   96     ALERT=$2
   97     if [ -n "$(which journalctl)" ]; then
   98     VALUE=`journalctl --since "5 minute ago" | fgrep ' connect from ' | wc -l`
   99     if [ "$VALUE" -gt "$ALERT" ]; then 
  100         STATUS="ALERT"
  101         MESSAGE="Excessive connections for Postfix $MYGROUP: $MYNAME "
  102     elif [ "$VALUE" -gt "$WARN" ]; then 
  103         STATUS="WARN"
  104         MESSAGE="High number of connections for Postfix $MYGROUP: $MYNAME "
  105     else
  106         STATUS="OK"
  107         MESSAGE="Normal connection rate by Postfix $MYGROUP: $MYNAME "
  108     fi
  109     echo "${DATIM};$MYGROUP;$MYNAME;PostfixInConnections;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  110     else
  111         echo "${DATIM};$MYGROUP;$MYNAME;PostfixInConnections;-5;not a SYSTEMD system" >> $TEMPDIR/tmp.$$.collected.tmp              
  112     fi
  113 }
  114 
  115 
  116 #---------------------------------------------------------
  117 # PostfixNoqueue - WARN ALERT
  118 #---------------------------------------------------------
  119 PostfixNoqueue () {
  120     MossheLog "PostfixNoqueue $1 $2"
  121     typeset -i ALERT WARN VALUE  RTN
  122     WARN=$1
  123     ALERT=$2
  124     if [ -n "$(which journalctl)" ]; then
  125     VALUE=`journalctl --since "5 minute ago" | fgrep ' NOQUEUE: reject: ' | wc -l`
  126     if [ "$VALUE" -gt "$ALERT" ]; then 
  127         STATUS="ALERT"
  128         MESSAGE="Excessive rejections by Postfix $MYGROUP: $MYNAME "
  129     elif [ "$VALUE" -gt "$WARN" ]; then 
  130         STATUS="WARN"
  131         MESSAGE="High number of rejections by Postfix $MYGROUP: $MYNAME "
  132     else
  133         STATUS="OK"
  134         MESSAGE="Normal rejection rate by Postfix $MYGROUP: $MYNAME "
  135     fi
  136     echo "${DATIM};$MYGROUP;$MYNAME;PostfixNoqueue;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  137     else
  138         echo "${DATIM};$MYGROUP;$MYNAME;PostfixNoqueue;-5;not a SYSTEMD system" >> $TEMPDIR/tmp.$$.collected.tmp                
  139     fi
  140 }
  141 
  142 #---------------------------------------------------------
  143 # PostfixSent - WARN ALERT
  144 #---------------------------------------------------------
  145 PostfixSent () {
  146     MossheLog "PostfixSent $1 $2"
  147     typeset -i ALERT WARN VALUE  RTN
  148     WARN=$1
  149     ALERT=$2
  150     if [ -n "$(which journalctl)" ]; then
  151     VALUE=`journalctl --since "5 minute ago" | fgrep postfix/smtp | fgrep ' status=sent' | wc -l`
  152     if [ "$VALUE" -gt "$ALERT" ]; then 
  153         STATUS="ALERT"
  154         MESSAGE="Excessive mail sending rate by Postfix $MYGROUP: $MYNAME "
  155     elif [ "$VALUE" -gt "$WARN" ]; then 
  156         STATUS="WARN"
  157         MESSAGE="High number of mails sent by Postfix $MYGROUP: $MYNAME "
  158     else
  159         STATUS="OK"
  160         MESSAGE="Normal mail sending rate by Postfix $MYGROUP: $MYNAME "
  161     fi
  162     echo "${DATIM};$MYGROUP;$MYNAME;PostfixSent;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  163     else
  164         echo "${DATIM};$MYGROUP;$MYNAME;PostfixSent;-5;not a SYSTEMD system" >> $TEMPDIR/tmp.$$.collected.tmp               
  165     fi
  166 }
  167 
  168 
  169 #############################################################################