summaryrefslogtreecommitdiffstats
path: root/abs/core/xymon/login_notify.sh
blob: be81fea471dc83786a1bd9a81f88c5e015f6ef6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
. /etc/systemconfig
#
#    BBCOLORLEVEL  - The color of the alert: "red", "yellow" or "purple"
#    BBALPHAMSG    - The full text of the status log triggering the alert
#    ACKCODE       - The "cookie" that can be used to acknowledge the alert
#    RCPT          - The recipient, from the SCRIPT entry
#    BBHOSTNAME    - The name of the host that the alert is about
#    MACHIP        - The IP-address of the host that has a problem
#    BBSVCNAME     - The name of the service that the alert is about
#    BBSVCNUM      - The numeric code for the service. From SVCCODES definition.
#    BBHOSTSVC     - HOSTNAME.SERVICE that the alert is about.
#    BBHOSTSVCCOMMAS - As BBHOSTSVC, but dots in the hostname replaced with commas
#    BBNUMERIC     - A 22-digit number made by BBSVCNUM, MACHIP and ACKCODE.
#    RECOVERED     - Is "1" if the service has recovered.
#    DOWNSECS      - Number of seconds the service has been down.
#    DOWNSECSMSG   - When recovered, holds the text "Event duration : N" where

#  LOGIN_OUT=/tmp/login_out
#  echo $BBCOLORLEVEL  >> $LOGIN_OUT
#  echo $BBALPHAMSG >>$LOGIN_OUT
#  echo $RCPT >>$LOGIN_OUT
#  echo $BBHOSTNAME >>$LOGIN_OUT
#  echo $BBSVCNAME >>$LOGIN_OUT
#  echo $BBHOSTSVC >>$LOGIN_OUT
#  echo $BBHOME  >> $LOGIN_OUT
#  echo $DOWNSECS >> $LOGIN_OUT
#  echo $RECOVERED >> $LOGIN_OUT
#  echo "----------" >> $LOGIN_OUT

#BBCOLORLEVEL=red
#BBCOLORLEVEL=yellow
#BBALPHAMSG="vmtest:disk red [751147]"
#BBHOSTNAME="testcraa"
#BBSVCNAME="disk"
#BBSVCNAME="func"
#BBHOSTSVC="vmtest.disk"

#bbhome ends up as /home/xymon/server  which is why I didn't use it here
NOTICE_DIR="/home/xymon/var/login_alerts"
if [ ! -d $NOTICE_DIR ]
then
    mkdir $NOTICE_DIR
fi

if [ "x$RECOVERED" == "x1" ]
then
    if [ -f $NOTICE_DIR/$BBHOSTSVC ]
    then
        rm -f $NOTICE_DIR/$BBHOSTSVC
    else
        echo "$NOTICE_DIR/$BBHOSTSVC is not present, didn't remove it"
    fi
else
   echo "DOWN: $DOWNSECS" > $NOTICE_DIR/$BBHOSTSVC
   echo "SERVICE: $BBSVCNAME" >> $NOTICE_DIR/$BBHOSTSVC
   echo "HOST: $BBHOSTNAME" >> $NOTICE_DIR/$BBHOSTSVC
   echo "ACKCODE: $ACKCODE" >> $NOTICE_DIR/$BBHOSTSVC
   echo "COLOR: $BBCOLORLEVEL" >> $NOTICE_DIR/$BBHOSTSVC
   echo "MSG $BBALPHAMSG" >> $NOTICE_DIR/$BBHOSTSVC
fi

#remove old alerts that didn't recover
find $NOTICE_DIR -mmin +4 -type f -exec rm -f {} \;