Skip to content
Advertisement

How to set and record alerts for Jenkin server down and up

I have Jenkins pipeline job which goes thought all our Jenkins servers and check the connectivity (runs every few minutes).

ksh file:

#!/bin/ksh
JENKINS_URL=$1

    curl  --connect-timeout 10 "$JENKINS_URL" >/dev/null
    status=`echo $?`
     if [ "$status" == "7" ]; then
        export SUBJECT="Connection refused or can not connect to URL $JENKINS_URL"
        echo "$SUBJECT"|/usr/sbin/sendmail -t XXXX@gmail.com

    else
        echo "successfully connected $JENKINS_URL"
     fi

    exit 0

I would like to add another piece of code, which record all the times that server was down (it should include the name of the server and timestamp) into a file, and in case the server is up again, send an email which will notify about it, and it will be also recorded in the file. I don’t want to get extra alerts, only one alert (to file and mail) when it’s down, and one when it’s up again. any idea how to implement it?

Advertisement

Answer

The detailed answer was given by unix.stackexchange community:

https://unix.stackexchange.com/questions/562594/how-to-set-and-record-alerts-for-jenkin-server-down-and-up

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement