Prettier timestamp
This commit is contained in:
		
							parent
							
								
									ebb8194170
								
							
						
					
					
						commit
						6d601ac73a
					
				
					 1 changed files with 38 additions and 12 deletions
				
			
		| 
						 | 
					@ -87,23 +87,50 @@ do
 | 
				
			||||||
  esac
 | 
					  esac
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Build the message's subject
 | 
					
 | 
				
			||||||
SUBJECT="[$NOTIFICATIONTYPE] $SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE!"
 | 
					# convert date
 | 
				
			||||||
 | 
					dateInSec=$(date -d "$LONGDATETIME" +%s)
 | 
				
			||||||
 | 
					nowInSec=$(date +%s)
 | 
				
			||||||
 | 
					ageInSec=$(($nowInSec - $dateInSec))
 | 
				
			||||||
 | 
					ageInMin=$(($ageInSec/60))
 | 
				
			||||||
 | 
					ageInHours=$(($ageInMin/60))
 | 
				
			||||||
 | 
					ageInDays=$(($ageInHours/24))
 | 
				
			||||||
 | 
					if [ "${LONGDATETIME:0:10}" == "$(date +"%Y-%m-%d")" ]; then
 | 
				
			||||||
 | 
						LONGDATETIME="${LONGDATETIME:11}"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					date=${LONGDATETIME#}
 | 
				
			||||||
 | 
					if   [ $ageInDays -gt 0 ]; then
 | 
				
			||||||
 | 
						age="${ageInDays}d $(($ageInHours-$ageInDays*24))h ($LONGDATETIME)"
 | 
				
			||||||
 | 
					elif [ $ageInHours -gt 0 ]; then
 | 
				
			||||||
 | 
						age="${ageInHours}h $(($ageInMin-$ageInHours*60))min ($LONGDATETIME)"
 | 
				
			||||||
 | 
					elif [ $ageInMin -gt 0 ]; then
 | 
				
			||||||
 | 
						age="${ageInMin}min $(($ageInSec-$ageInMin*60))s"
 | 
				
			||||||
 | 
					elif [ $ageInSec -gt 5 ]; then
 | 
				
			||||||
 | 
						age="${ageInSec}s"
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
						age="$LONGDATETIME"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ "$HOSTALIAS" == "$HOSTDISPLAYNAME" ]; then
 | 
				
			||||||
 | 
						HOSTALIAS2=""
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
						HOSTALIAS2=" ($HOSTALIAS)"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Build the message itself
 | 
					## Build the message itself
 | 
				
			||||||
NOTIFICATION_MESSAGE=$(cat << EOF
 | 
					NOTIFICATION_MESSAGE=$(cat << EOF
 | 
				
			||||||
$HOSTDISPLAYNAME ($HOSTALIAS) is $HOSTSTATE!
 | 
					<b>$HOSTDISPLAYNAME</b>$HOSTALIAS2 is $HOSTSTATE!
 | 
				
			||||||
When?    $LONGDATETIME
 | 
					Since   $age
 | 
				
			||||||
Info?    $HOSTOUTPUT
 | 
					Info      $HOSTOUTPUT
 | 
				
			||||||
Host?    $HOSTALIAS
 | 
					IPv4     $HOSTADDRESS
 | 
				
			||||||
IPv4?    $HOSTADDRESS
 | 
					 | 
				
			||||||
EOF
 | 
					EOF
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Is this host IPv6 capable?
 | 
					## Is this host IPv6 capable?
 | 
				
			||||||
if [ -n "$HOSTADDRESS6" ] ; then
 | 
					if [ -n "$HOSTADDRESS6" ] ; then
 | 
				
			||||||
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
 | 
					  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
 | 
				
			||||||
IPv6?    $HOSTADDRESS6"
 | 
					IPv6     $HOSTADDRESS6"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
## Are there any comments? Put them into the message!
 | 
					## Are there any comments? Put them into the message!
 | 
				
			||||||
if [ -n "$NOTIFICATIONCOMMENT" ] ; then
 | 
					if [ -n "$NOTIFICATIONCOMMENT" ] ; then
 | 
				
			||||||
| 
						 | 
					@ -114,14 +141,13 @@ fi
 | 
				
			||||||
## Are we using Icinga Web 2? Put the URL into the message!
 | 
					## Are we using Icinga Web 2? Put the URL into the message!
 | 
				
			||||||
if [ -n "$HAS_ICINGAWEB2" ] ; then
 | 
					if [ -n "$HAS_ICINGAWEB2" ] ; then
 | 
				
			||||||
  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
 | 
					  NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
 | 
				
			||||||
Get live status:
 | 
					<a href='$HAS_ICINGAWEB2/monitoring/host/show?host=$HOSTALIAS'>Icinga Web</a>"
 | 
				
			||||||
  $HAS_ICINGAWEB2/monitoring/host/show?host=$HOSTALIAS"
 | 
					 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
## Build the message's subject
 | 
					 | 
				
			||||||
SUBJECT="[$NOTIFICATIONTYPE] Host $HOSTDISPLAYNAME is $HOSTSTATE!"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Are we verbose? Then put a message to syslog...
 | 
					## Are we verbose? Then put a message to syslog...
 | 
				
			||||||
if [ "$VERBOSE" == "true" ] ; then
 | 
					if [ "$VERBOSE" == "true" ] ; then
 | 
				
			||||||
 | 
					  ## Build the message's subject
 | 
				
			||||||
 | 
					  SUBJECT="[$NOTIFICATIONTYPE] Host $HOSTDISPLAYNAME is $HOSTSTATE!"
 | 
				
			||||||
  logger "$PROG sends $SUBJECT => Telegram Channel $TELEGRAM_BOT"
 | 
					  logger "$PROG sends $SUBJECT => Telegram Channel $TELEGRAM_BOT"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue