Rundeck Dashboard For Reporting Job Run Status

DevOps

Rundeck is a very handy tool when it comes to runbook automation. Many organizations use rundeck as a job scheduler and to automate daily tasks. Similarly we used rundeck for our release and deployment activities. In Rundeck we had almost 30+ projects with different jobs(Though similar names for deployment jobs) running and our management wanted to know status of all jobs in a weekly and monthly report with a custom Rundeck dashboard to view daily job runs across all projects.
Rundeck currently does not have a consolidated reporting dashboard for all projects which can be shared/emailed automatically weekly and monthly. It is also very hard to go to individual projects and get the individual job runs status and format and send manually to management. So to avoid this we created a simple Rundeck dashboard for reporting named “Rundeck Reporting Dashboard” which displays all job run for individual projects active in Rundeck, Weekly and Monthly deployment/release job run report for individual projects, All activities count report per project,etc.

Custom Rundeck Dashboard ScreenShots:

Rundeck Dashboard Weekly Job Run Report:
rundeck dashboard for reporting

Rundeck Dashboard Monthly Job Run Report:
rundeck dashboard for reporting

 

Rundeck Dashboard All Projects Job Run Report:

rundeck dashboard for reporting

Rundeck Dashboard Project Wise Job Run Report:
rundeck dashboard for reporting

 

Rundeck Dashboard Login To Rundeck Console:
rundeck dashboard for reporting

 

 

Pre-Requisites:

1. Rundeck already installed and all services working fine.
2. Rundeck cli already downloaded and installed. (Download: https://github.com/rundeck/rundeck-cli/releases)
3. Here server path are taken as below:
a. Rundeck installed in /opt/rundeck and is on a linux server.
b. Rundeck cli installed in /opt/rundeck/rd-0.1.15
c. Apache webserver is installed and available for use with directory listing module.
d. Rundeck dashboard reports scripts are stored at /opt/scripts/status folder
e. /opt/scripts/status folder has been mapped to Apache as a documentroot directory so that you can access the folders contents via web browser.

httpd.conf changes:

	DocumentRoot "/opt/scripts/status"
	<Directory "/opt/scripts/status">
	DirectoryIndex  index.htm index.html index.php

4. All the deployment jobs in all projects are under Deploy_Modules group. If you have something different then you have to update the same in the report generation script.
5. It is assumed that Apache hostname is rundeckserver.apache.techpaste.com and dashboard index.htm file can be accessed via http://rundeckserver.apache.techpaste.com/

Options/Features Available :

1. Report for Weekly Job runs status accross all projects.
2. Report for Monthly Job runs status accross all projets.
3. Report for detailed job runs for individual projects in one place.
4. Automatic email of Weekly Job Runs status reports and Monthly Job Run Status reports to email groups.

Assumptions :

1. This is a dirty way of getting things done but works for my scenario till the point we get any descent plugins to do the same from backend and make things better.
2. This is made outof shell script and it runs through the rundeck execution logs to get the results and generate the html reports.
3. We assume that you have good command on linux and shell scripting to understand this article and script functionalities.
4. Simple copy paste of script might not work for you and some modifications might be required to make it working on your environment and directory structure.

Custom Rundeck Dashboard Creation Steps:

1. Copy the below content into a file named index.htm and place the file at /opt/scripts/status folder whcih is the documentroot folder also in apache config file.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


<title>RunDeck Reports Dashboard</title>



<STYLE type="text/css">
body{
font-family:"Lucida Grande", arial, sans-serif;
background:#F3F3F3;
}

ul{
margin:0;
padding:0;
}

li{
width:200px;
height:50px;
float:left;
color:#191919;
text-align:center;
overflow:hidden;
}

a{
color:#FFF;
text-decoration:none;
}

p{
padding:0px 5px;
}

.subtext{
padding-top:15px;
}

/*Menu Color Classes*/
.green{background:#6AA63B top left no-repeat;}
.yellow{background:#FBC700 top left no-repeat;}
.red{background:#D52100 top left no-repeat;}
.purple{background:#5122B4 top left no-repeat;}
.blue{background:#0292C0 top left no-repeat;}
</STYLE>

<!--

Desc : Index page for all dashboard Menu's
Author : TechPaste.Com Solutions(admin(at)techpaste.com)
Date : 09/15/2016

-->

</head>

<body>

<script type="text/javascript">
var buffer = 20; //scroll bar buffer
var iframe = document.getElementById('iframe1');

function pageY(elem) {
return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;
}

function resizeIframe() {
var height = document.documentElement.clientHeight;
height -= pageY(document.getElementById('iframe1'))+ buffer ;
height = (height < 0) ? 0 : height;
document.getElementById('iframe1').style.height = height + 'px';
}

// .onload doesn't work with IE8 and older.
if (iframe.attachEvent) {
iframe.attachEvent("onload", resizeIframe);
} else {
iframe.onload=resizeIframe;
}

window.onresize = resizeIframe;
</script>

<center><h4>RunDeck Dashboard</h4></center>
<ul>
<li class="green" style="overflow: hidden; height: 50px; display: block;">
<P><a href="http://rundeckserver.apache.techpaste.com/" target='iframe1'>Home</a></p>

</li>

<li class="yellow" style="overflow: hidden; height: 50px; display: block;">
<p><a href="7DaysRelease.html" target='iframe1'>Weekly Report</a></p>

</li>
<li class="red" style="height: 50px; display: block; overflow: hidden;">
<p><a href="30DaysRelease.html" target='iframe1'>Monthly Report</a></p>
</li>
<li class="purple" style="overflow: hidden; height: 50px; display: block;">
<p><a href="all_projects.html" target='iframe1'>All Projects</a></p>
</li>

</ul>

<iframe id='iframe1' name='iframe1' src="http://rundeckserver.apache.techpaste.com/" onload="this.width=screen.width;this.height=screen.height;" align='center' ></iframe>

</body>

</html>

Sample Output of Dashboard frontend. You can add more tabs if required.
Rundeck Dashboard

2. Copy the below content into a file named status.sh and place the file at /opt/scripts/status folder which is the documentroot folder also in apache config file.

Short Descriptions of shell script functions:

1. clean_reports : Clear’s old html reports before generating new ones.
2. 7days_release : Generates 7 days of deployment job run report which matches Deploy_Modules* as group name.
3. 30days_release: Generates 30 days of deployment job run report which matches Deploy_Modules* as group name.
4. all_projects : Generates the base report with links to individual project wise job run reports.
5. email_admin : Generates and sends email templates reports for sending via email using cron jobs.

status.sh Script:

#!/bin/bash
# -x
# To get individual Projects Status.
# @Author: TechPaste.Com Solutions([email protected])

SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
while [ -h "$SOURCE" ]
do
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
#echo "`date` :Script Run Directory set to: $DIR"
cd "$DIR"
scriptname=`basename "$0"`
BASENAME=`basename "$1"`
if [[ $@ == "-h" || $@ == "-help" || $@ == "help" ]]; then

echo -e "USAGE DETAILS:";
echo "---------------------------------------------";
echo "./$scriptname";
echo "---------------------------------------------";
exit 0;
fi;

#cd /opt/scripts/status

export _command=$1

clean_reports() {
rm -rf /opt/scripts/status/*.html
}
7days_release() {

find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \;| grep -i "Deploy_Modules*" | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1 | egrep -E "`date +%Y-%m-%d`|`date +%Y-%m-%d --date="1 days ago"`|`date +%Y-%m-%d --date="2 days ago"`|`date +%Y-%m-%d --date="3 days ago"`|`date +%Y-%m-%d --date="4 days ago"`|`date +%Y-%m-%d --date="5 days ago"`|`date +%Y-%m-%d --date="6 days ago"`|`date +%Y-%m-%d --date="7 days ago"`" | awk '{if($5 == "failed") {print $1" "$2" "$3" "$4" _COLOR_IT_RED"$5" "$6;} else if($5=="succeeded") print $1" "$2" "$3" "$4" _COLOR_IT_GREEN"$5" "$6; }' | awk -v date="$(date +"%Y-%m-%d %r")" 'BEGIN{print "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=US-ASCII\">\n<style type='\''text/css'\''> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;-} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>QuickDeploy Report</title>\n</head>\n<body><script>\nfunction goBack() \n{ window.history.back();}</script>\n<script>\nfunction goForward()\n { \nwindow.history.forward();}\n</script>\n<table border='\''1'\'' width='\''90%'\'' align='\''center'\'' summary='\''Script output'\''>\n<tr>\n<th colspan=\"6\"><button onclick=\"goBack()\">Go Back</button>&nbsp;&nbsp;&nbsp;&nbsp;RUNDECK WEEKLY RELEASE REPORT&nbsp;&nbsp;<button onclick=\"goForward()\">Go Forward</button></th>\n</tr>\n\n<tr>\n<th colspan=\"2\">&nbsp;TOTAL RELEASES:&nbsp;__7count__&nbsp;&nbsp;</th>\n<th colspan=\"3\">SUCCESSFUL:&nbsp;__PASS7__&nbsp;</th>\n\n<th colspan=\"1\">FAILED:&nbsp;__FAIL7__&nbsp;</th>\n\n</tr>\n<tr>\n<th scope=\"col\">PROJECT NAME</th>\n<th scope=\"col\">RUN BY USER</th>\n<th scope=\"col\">DATE</th>\n<th scope=\"col\">TIME</th>\n<th scope=\"col\">STATUS</th>\n<th scope=\"col\">JOB NAME</th>\n</tr>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td align=\"right\">&nbsp;&nbsp;" $i"&nbsp;</td>\n";print "</tr>\n"} END{print "_REPLACE_ME_\n<tr>\n<th colspan=\"6\">\nReport Generated On: "date"&nbsp;IST</th>\n</tr>\n</table>\n<p>\n</body>\n</html>"}' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_GREEN/<td align=\"left\" style="background-color:#6AA63B">\&nbsp;\&nbsp;/g' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_RED/<td align=\"left\" style=\"background-color:#FF0000\">\&nbsp;\&nbsp;/g' | sed 's/succeeded/COMPLETED/g' | sed 's/failed/FAILED/g' | sed -e "/<tr>/,/./ s/\(<td align=\"right\">&nbsp;&nbsp;\)\(.*\)\(&nbsp;<\/td>\)/\1<a href=\"http:\/\/rundeckserver.apache.techpaste.com:9000\/\2_Jobrun.html\">\2<img src=\"http:\/\/rundeckserver.apache.techpaste.com:80\/Icon_External_Link.png\" alt=\"External Link\" style=\"width:12px;height:12px;\"><\/a>\3/g" >7DaysRelease.html

/opt/rundeck/rd-0.1.15/bin/rd projects list | awk -F":" '{print $1}' | awk '{print $2}' | sed 's/^Projects//g' | sed '/^$/d' | sort -nr | while read _line;
do

find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | grep $_line | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -r -k3,3 -k1,1 | awk '{if($5 == "failed") {print $1" "$2" "$3" "$4" _COLOR_IT_RED"$5" "$6;} else if($5=="succeeded") print $1" "$2" "$3" "$4" _COLOR_IT_GREEN"$5" "$6; }' | awk -v date="$(date +"%Y-%m-%d %r")" 'BEGIN{print "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=US-ASCII\">\n<style type='\''text/css'\''> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;-} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>QuickDeploy Report</title>\n</head>\n<body><script>\nfunction goBack() \n{ window.history.back();}</script>\n<script>\nfunction goForward()\n { \nwindow.history.forward();}\n</script>\n<table border='\''1'\'' width='\''90%'\'' align='\''center'\'' summary='\''Script output'\''>\n<tr>\n<th colspan=\"6\"><button onclick=\"goBack()\">Go Back</button>&nbsp;&nbsp;&nbsp;&nbsp;_PROJECT_NAME_: 30 DAYS UNIQUE JOB RUN REPORT&nbsp;&nbsp;&nbsp;&nbsp;<button onclick=\"goForward()\">Go Forward</button></th>\n</tr>\n<tr>\n<th scope=\"col\">PROJECT NAME</th>\n<th scope=\"col\">RUN BY USER</th>\n<th scope=\"col\">DATE</th>\n<th scope=\"col\">TIME</th>\n<th scope=\"col\">STATUS</th>\n<th scope=\"col\">JOB NAME</th>\n</tr>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td align=\"right\">&nbsp;&nbsp;" $i"&nbsp;</td>\n";print "</tr>\n"} END{print "\n<tr>\n<th colspan=\"6\">\nReport Generated On: "date"&nbsp;IST</th>\n</tr>\n</table>\n<p>\n</body>\n</html>"}' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_GREEN/<td align=\"left\" style="background-color:#6AA63B">\&nbsp;\&nbsp;/g' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_RED/<td align=\"left\" style=\"background-color:#FF0000\">\&nbsp;\&nbsp;/g' | sed 's/succeeded/SUCCESSFUL/g' | sed 's/failed/FAILED/g'| sed 's/_PROJECT_NAME_/'"${_line}"'/g' > `echo ${_line}_Jobrun.html`

_count=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \;| grep -i "Deploy_Modules*" | egrep -E "`date +%Y-%m-%d`|`date +%Y-%m-%d --date="1 days ago"`|`date +%Y-%m-%d --date="2 days ago"`|`date +%Y-%m-%d --date="3 days ago"`|`date +%Y-%m-%d --date="4 days ago"`|`date +%Y-%m-%d --date="5 days ago"`|`date +%Y-%m-%d --date="6 days ago"`|`date +%Y-%m-%d --date="7 days ago"`" | grep "$_line" | grep -v grep | wc -l)
_NAME=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $2}' | head -1)
_JOB=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $6}' | head -1)
_DATE=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $3}' | head -1)
_TIME=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $4}' | head -1)
if [ $_count -eq 0 ]; then

#echo "Found count = 0"
sed -i '/_REPLACE_ME_/a <tr>\n<td align=\"right\">&nbsp;&nbsp;<a href=\"http:\/\/rundeckserver.apache.techpaste.com:80\/'"$_line"'_Jobrun.html\">'"$_line"'<img src=\"http:\/\/rundeckserver.apache.techpaste.com:80\/Icon_External_Link.png\" alt=\"External Link\" style=\"width:12px;height:12px;\"><\/a>&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_NAME"'<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_DATE"'&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_TIME"'&nbsp;<\/td>\n<td align=\"left\" style=\"background-color:#FFFFCC\">&nbsp;&nbsp;NO RELEASE&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_JOB"'&nbsp;<\/td>\n<\/tr>' 7DaysRelease.html

fi;

done
_total7count=$(cat 7DaysRelease.html | grep -E "COMPLETED|FAILED" | grep -v "FAILED:" | wc -l)
_pass7count=$(cat 7DaysRelease.html | grep "COMPLETED" | grep -v "FAILED:" | wc -l)
_fail7count=$(cat 7DaysRelease.html | grep "FAILED" | grep -v "FAILED:" | wc -l)

sed -i 's/__7count__/'"$_total7count"'/g' 7DaysRelease.html
sed -i 's/__7count__/'"$_total7count"'/g' 7DaysRelease.html
sed -i 's/__PASS7__/'"$_pass7count"'/g' 7DaysRelease.html
sed -i 's/__FAIL7__/'"$_fail7count"'/g' 7DaysRelease.html
sed -i 's/_REPLACE_ME_//g' 7DaysRelease.html
}

30days_release() {
find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \;| grep -i "Deploy_Modules*" | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1 | egrep -E "`date +%Y-%m-%d`|`date +%Y-%m-%d --date="1 days ago"`|`date +%Y-%m-%d --date="2 days ago"`|`date +%Y-%m-%d --date="3 days ago"`|`date +%Y-%m-%d --date="4 days ago"`|`date +%Y-%m-%d --date="5 days ago"`|`date +%Y-%m-%d --date="6 days ago"`|`date +%Y-%m-%d --date="7 days ago"`|`date +%Y-%m-%d --date="8 days ago"`|`date +%Y-%m-%d --date="9 days ago"`|`date +%Y-%m-%d --date="10 days ago"`|`date +%Y-%m-%d --date="11 days ago"`|`date +%Y-%m-%d --date="12 days ago"`|`date +%Y-%m-%d --date="13 days ago"`|`date +%Y-%m-%d --date="14 days ago"`|`date +%Y-%m-%d --date="15 days ago"`|`date +%Y-%m-%d --date="16 days ago"`|`date +%Y-%m-%d --date="17 days ago"`|`date +%Y-%m-%d --date="18 days ago"`|`date +%Y-%m-%d --date="19 days ago"`|`date +%Y-%m-%d --date="20 days ago"`|`date +%Y-%m-%d --date="21 days ago"`|`date +%Y-%m-%d --date="22 days ago"`|`date +%Y-%m-%d --date="23 days ago"`|`date +%Y-%m-%d --date="24 days ago"`|`date +%Y-%m-%d --date="25 days ago"`|`date +%Y-%m-%d --date="26 days ago"`|`date +%Y-%m-%d --date="27 days ago"`|`date +%Y-%m-%d --date="28 days ago"`|`date +%Y-%m-%d --date="29 days ago"`|`date +%Y-%m-%d --date="30 days ago"`" | awk '{if($5 == "failed") {print $1" "$2" "$3" "$4" _COLOR_IT_RED"$5" "$6;} else if($5=="succeeded") print $1" "$2" "$3" "$4" _COLOR_IT_GREEN"$5" "$6; }' | awk -v date="$(date +"%Y-%m-%d %r")" 'BEGIN{print "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=US-ASCII\">\n<style type='\''text/css'\''> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;-} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>QuickDeploy Report</title>\n</head>\n<body>\n<script>\nfunction goBack() \n{ window.history.back();}</script>\n<script>\nfunction goForward()\n { \nwindow.history.forward();}\n</script>\n<table border='\''1'\'' width='\''90%'\'' align='\''center'\'' summary='\''Script output'\''>\n<tr>\n<th colspan=\"6\"><button onclick=\"goBack()\">Go Back</button>&nbsp;&nbsp;&nbsp;&nbsp;RUNDECK MONTHLY RELEASE REPORT&nbsp;&nbsp;&nbsp;&nbsp;<button onclick=\"goForward()\">Go Forward</button></th>\n</tr>\n<tr>\n<th colspan=\"2\">&nbsp;TOTAL RELEASES:&nbsp;__30count__&nbsp;&nbsp;</th>\n<th colspan=\"3\">SUCCESSFUL:&nbsp;__PASS30__&nbsp;</th>\n\n<th colspan=\"1\">FAILED:&nbsp;__FAIL30__&nbsp;</th>\n\n</tr>\n\n<tr>\n<th scope=\"col\">PROJECT NAME</th>\n<th scope=\"col\">RUN BY USER</th>\n<th scope=\"col\">DATE</th>\n<th scope=\"col\">TIME</th>\n<th scope=\"col\">STATUS</th>\n<th scope=\"col\">JOB NAME</th>\n</tr>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td align=\"right\">&nbsp;&nbsp;" $i"&nbsp;</td>\n";print "</tr>\n"} END{print "_REPLACE_ME_\n<tr>\n<th colspan=\"6\">\nReport Generated On: "date"&nbsp;IST</th>\n</tr>\n</table>\n<p>\n</body>\n</html>"}' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_GREEN/<td align=\"left\" style="background-color:#6AA63B">\&nbsp;\&nbsp;/g' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_RED/<td align=\"left\" style=\"background-color:#FF0000\">\&nbsp;\&nbsp;/g' | sed 's/succeeded/COMPLETED/g' | sed 's/failed/FAILED/g' | sed -e "/<tr>/,/./ s/\(<td align=\"right\">&nbsp;&nbsp;\)\(.*\)\(&nbsp;<\/td>\)/\1<a href=\"http:\/\/rundeckserver.apache.techpaste.com:80\/\2_Jobrun.html\">\2<img src=\"http:\/\/rundeckserver.apache.techpaste.com:80\/Icon_External_Link.png\" alt=\"External Link\" style=\"width:12px;height:12px;\"><\/a>\3/g" >30DaysRelease.html

/opt/rundeck/rd-0.1.15/bin/rd projects list | awk -F":" '{print $1}' | awk '{print $2}' | sed 's/^Projects//g' | sed '/^$/d' | sort -nr | while read _line;
do

_count=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \;| grep -i "Deploy_Modules*" | egrep -E "`date +%Y-%m-%d`|`date +%Y-%m-%d --date="1 days ago"`|`date +%Y-%m-%d --date="2 days ago"`|`date +%Y-%m-%d --date="3 days ago"`|`date +%Y-%m-%d --date="4 days ago"`|`date +%Y-%m-%d --date="5 days ago"`|`date +%Y-%m-%d --date="6 days ago"`|`date +%Y-%m-%d --date="7 days ago"`|`date +%Y-%m-%d --date="8 days ago"`|`date +%Y-%m-%d --date="9 days ago"`|`date +%Y-%m-%d --date="10 days ago"`|`date +%Y-%m-%d --date="11 days ago"`|`date +%Y-%m-%d --date="12 days ago"`|`date +%Y-%m-%d --date="13 days ago"`|`date +%Y-%m-%d --date="14 days ago"`|`date +%Y-%m-%d --date="15 days ago"`|`date +%Y-%m-%d --date="16 days ago"`|`date +%Y-%m-%d --date="17 days ago"`|`date +%Y-%m-%d --date="18 days ago"`|`date +%Y-%m-%d --date="19 days ago"`|`date +%Y-%m-%d --date="20 days ago"`|`date +%Y-%m-%d --date="21 days ago"`|`date +%Y-%m-%d --date="22 days ago"`|`date +%Y-%m-%d --date="23 days ago"`|`date +%Y-%m-%d --date="24 days ago"`|`date +%Y-%m-%d --date="25 days ago"`|`date +%Y-%m-%d --date="26 days ago"`|`date +%Y-%m-%d --date="27 days ago"`|`date +%Y-%m-%d --date="28 days ago"`|`date +%Y-%m-%d --date="29 days ago"`|`date +%Y-%m-%d --date="30 days ago"`" | grep "$_line" | grep -v grep | wc -l)
_NAME=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $2}' | head -1)
_JOB=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $6}' | head -1)
_DATE=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $3}' | head -1)
_TIME=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $4}' | head -1)
#echo "NAME found: $_NAME"
#echo "JOB found:$_JOB"

if [ $_count -eq 0 ]; then

#echo "Found count = 0"
sed -i '/_REPLACE_ME_/a <tr>\n<td align=\"right\">&nbsp;&nbsp;<a href=\"http:\/\/rundeckserver.apache.techpaste.com:80\/'"$_line"'_Jobrun.html\">'"$_line"'<img src=\"http:\/\/rundeckserver.apache.techpaste.com:80\/Icon_External_Link.png\" alt=\"External Link\" style=\"width:12px;height:12px;\"><\/a>&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_NAME"'<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_DATE"'&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_TIME"'&nbsp;<\/td>\n<td align=\"left\" style=\"background-color:#FFFFCC\">&nbsp;&nbsp;NO RELEASE&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_JOB"'&nbsp;<\/td>\n<\/tr>' 30DaysRelease.html

fi;

done

_total30count=$(cat 30DaysRelease.html | grep -E "COMPLETED|FAILED" | grep -v "FAILED:" | wc -l)
_pass30count=$(cat 30DaysRelease.html | grep "COMPLETED" | grep -v "FAILED:" | wc -l)
_fail30count=$(cat 30DaysRelease.html | grep "FAILED" | grep -v "FAILED:" | wc -l)

sed -i 's/_REPLACE_ME_//g' 30DaysRelease.html
sed -i 's/__30count__/'"$_total30count"'/g' 30DaysRelease.html
sed -i 's/__PASS30__/'"$_pass30count"'/g' 30DaysRelease.html
sed -i 's/__FAIL30__/'"$_fail30count"'/g' 30DaysRelease.html

sed -i 's/_REPLACE_ME_//g' 30DaysRelease.html
}

all_projects() {

/opt/rundeck/rd-0.1.15/bin/rd projects list | awk -F":" '{print $1}' | awk '{print $2}' | sed 's/^Projects//g' | sed '/^$/d' | pr -s' ' -3 -l1 -t | awk -v date="$(date +"%Y-%m-%d %r")" 'BEGIN{print "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=US-ASCII\">\n<style type='\''text/css'\''> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;-} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>QuickDeploy Report</title>\n</head>\n<body>\n<script>\nfunction goBack() \n{ window.history.back();}</script>\n<script>\nfunction goForward()\n { \nwindow.history.forward();}\n</script>\n<table border='\''1'\'' width='\''90%'\'' align='\''center'\'' summary='\''Script output'\''>\n<tr>\n<th colspan=\"6\"><button onclick=\"goBack()\">Go Back</button>&nbsp;&nbsp;&nbsp;&nbsp;ALL PROJECTS DETAILED RUN REPORT&nbsp;&nbsp;&nbsp;&nbsp;<button onclick=\"goForward()\">Go Forward</button></th>\n</tr>\n"} {print "<tr>";for(i=1;i<=NF;i++)print "<td align=\"right\">&nbsp;&nbsp;" $i"&nbsp;</td>\n";print "</tr>\n"} END{print "<tr>\n<th colspan=\"6\">\nReport Generated On: "date"&nbsp;IST</th>\n</tr>\n</table>\n<p>\n</body>\n</html>"}' | sed -e "s/\(<td align=\"right\">&nbsp;&nbsp;\)\(.*\)\(&nbsp;<\/td>\)/\1<a href=\"http:\/\/rundeckserver.apache.techpaste.com:80\/\2_Jobrun.html\">\2<img src=\"http:\/\/rundeckserver.apache.techpaste.com:80\/Icon_External_Link.png\" alt=\"External Link\" style=\"width:12px;height:12px;\"><\/a>\3/g" > all_projects.html

}

email_admin() {

find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \;| grep -i "Deploy_Modules*" | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1 | egrep -E "`date +%Y-%m-%d`|`date +%Y-%m-%d --date="1 days ago"`|`date +%Y-%m-%d --date="2 days ago"`|`date +%Y-%m-%d --date="3 days ago"`|`date +%Y-%m-%d --date="4 days ago"`|`date +%Y-%m-%d --date="5 days ago"`|`date +%Y-%m-%d --date="6 days ago"`|`date +%Y-%m-%d --date="7 days ago"`" | awk '{if($5 == "failed") {print $1" "$2" "$3" "$4" _COLOR_IT_RED"$5" "$6;} else if($5=="succeeded") print $1" "$2" "$3" "$4" _COLOR_IT_GREEN"$5" "$6; }' | awk -v date="$(date +"%Y-%m-%d %r")" 'BEGIN{print "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=US-ASCII\">\n<style type='\''text/css'\''> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;-} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>QuickDeploy Report</title>\n</head>\n<body>\n<table border='\''1'\'' width='\''90%'\'' align='\''center'\'' summary='\''Script output'\''>\n<tr>\n<th colspan=\"6\">&nbsp;&nbsp;&nbsp;&nbsp;RUNDECK WEEKLY RELEASE REPORT&nbsp;&nbsp;</th>\n</tr>\n\n<tr>\n<th colspan=\"2\">&nbsp;TOTAL RELEASES:&nbsp;__7count__&nbsp;&nbsp;</th>\n<th colspan=\"3\">SUCCESSFUL:&nbsp;__PASS7__&nbsp;</th>\n\n<th colspan=\"1\">FAILED:&nbsp;__FAIL7__&nbsp;</th>\n\n</tr>\n\n<tr>\n<th scope=\"col\">PROJECT NAME</th>\n<th scope=\"col\">RUN BY USER</th>\n<th scope=\"col\">DATE</th>\n<th scope=\"col\">TIME</th>\n<th scope=\"col\">STATUS</th>\n<th scope=\"col\">JOB NAME</th>\n</tr>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td align=\"right\">&nbsp;&nbsp;" $i"&nbsp;</td>\n";print "</tr>\n"} END{print "_REPLACE_ME_\n<tr>\n<th colspan=\"6\">\nReport Generated On: "date"&nbsp;IST</th>\n</tr>\n</table>\n<p>\n</body>\n</html>"}' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_GREEN/<td align=\"left\" style="background-color:#6AA63B">\&nbsp;\&nbsp;/g' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_RED/<td align=\"left\" style=\"background-color:#FF0000\">\&nbsp;\&nbsp;/g' | sed 's/succeeded/COMPLETED/g' | sed 's/failed/FAILED/g' | sed -e "/<tr>/,/./ s/\(<td align=\"right\">&nbsp;&nbsp;\)\(.*\)\(&nbsp;<\/td>\)/\1<a href=\"http:\/\/rundeckserver.apache.techpaste.com:80\/\2_Jobrun.html\"><b><u>\2<\/u><\/b><\/a>\3/g" >7DayEmail.html

find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \;| grep -i "Deploy_Modules*" | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1 | egrep -E "`date +%Y-%m-%d`|`date +%Y-%m-%d --date="1 days ago"`|`date +%Y-%m-%d --date="2 days ago"`|`date +%Y-%m-%d --date="3 days ago"`|`date +%Y-%m-%d --date="4 days ago"`|`date +%Y-%m-%d --date="5 days ago"`|`date +%Y-%m-%d --date="6 days ago"`|`date +%Y-%m-%d --date="7 days ago"`|`date +%Y-%m-%d --date="8 days ago"`|`date +%Y-%m-%d --date="9 days ago"`|`date +%Y-%m-%d --date="10 days ago"`|`date +%Y-%m-%d --date="11 days ago"`|`date +%Y-%m-%d --date="12 days ago"`|`date +%Y-%m-%d --date="13 days ago"`|`date +%Y-%m-%d --date="14 days ago"`|`date +%Y-%m-%d --date="15 days ago"`|`date +%Y-%m-%d --date="16 days ago"`|`date +%Y-%m-%d --date="17 days ago"`|`date +%Y-%m-%d --date="18 days ago"`|`date +%Y-%m-%d --date="19 days ago"`|`date +%Y-%m-%d --date="20 days ago"`|`date +%Y-%m-%d --date="21 days ago"`|`date +%Y-%m-%d --date="22 days ago"`|`date +%Y-%m-%d --date="23 days ago"`|`date +%Y-%m-%d --date="24 days ago"`|`date +%Y-%m-%d --date="25 days ago"`|`date +%Y-%m-%d --date="26 days ago"`|`date +%Y-%m-%d --date="27 days ago"`|`date +%Y-%m-%d --date="28 days ago"`|`date +%Y-%m-%d --date="29 days ago"`|`date +%Y-%m-%d --date="30 days ago"`" | awk '{if($5 == "failed") {print $1" "$2" "$3" "$4" _COLOR_IT_RED"$5" "$6;} else if($5=="succeeded") print $1" "$2" "$3" "$4" _COLOR_IT_GREEN"$5" "$6; }' | awk -v date="$(date +"%Y-%m-%d %r")" 'BEGIN{print "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=US-ASCII\">\n<style type='\''text/css'\''> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;-} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>QuickDeploy Report</title>\n</head>\n<body>\n<table border='\''1'\'' width='\''90%'\'' align='\''center'\'' summary='\''Script output'\''>\n<tr>\n<th colspan=\"6\">&nbsp;&nbsp;&nbsp;&nbsp;RUNDECK MONTHLY RELEASE REPORT&nbsp;&nbsp;</th>\n</tr>\n\n<tr>\n<th colspan=\"2\">&nbsp;TOTAL RELEASES:&nbsp;__30count__&nbsp;&nbsp;</th>\n<th colspan=\"3\">SUCCESSFUL:&nbsp;__PASS30__&nbsp;</th>\n\n<th colspan=\"1\">FAILED:&nbsp;__FAIL30__&nbsp;</th>\n\n</tr>\n\n<tr>\n<th scope=\"col\">PROJECT NAME</th>\n<th scope=\"col\">RUN BY USER</th>\n<th scope=\"col\">DATE</th>\n<th scope=\"col\">TIME</th>\n<th scope=\"col\">STATUS</th>\n<th scope=\"col\">JOB NAME</th>\n</tr>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td align=\"right\">&nbsp;&nbsp;" $i"&nbsp;</td>\n";print "</tr>\n"} END{print "_REPLACE_ME_\n<tr>\n<th colspan=\"6\">\nReport Generated On: "date"&nbsp;IST</th>\n</tr>\n</table>\n<p>\n</body>\n</html>"}' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_GREEN/<td align=\"left\" style="background-color:#6AA63B">\&nbsp;\&nbsp;/g' | sed 's/<td align=\"right\">\&nbsp;\&nbsp;_COLOR_IT_RED/<td align=\"left\" style=\"background-color:#FF0000\">\&nbsp;\&nbsp;/g' | sed 's/succeeded/COMPLETED/g' | sed 's/failed/FAILED/g' | sed -e "/<tr>/,/./ s/\(<td align=\"right\">&nbsp;&nbsp;\)\(.*\)\(&nbsp;<\/td>\)/\1<a href=\"http:\/\/rundeckserver.apache.techpaste.com:80\/\2_Jobrun.html\"><b><u>\2<\/u><\/b><\/a>\3/g" >30DayEmail.html
_total7count=$(cat 7DayEmail.html | grep -E "COMPLETED|FAILED" | grep -v "FAILED:" | wc -l)
_pass7count=$(cat 7DayEmail.html | grep "COMPLETED" | grep -v "FAILED:" | wc -l)
_fail7count=$(cat 7DayEmail.html | grep "FAILED" | grep -v "FAILED:" | wc -l)

_total30count=$(cat 30DayEmail.html | grep -E "COMPLETED|FAILED" | grep -v "FAILED:" | wc -l)
_pass30count=$(cat 30DayEmail.html | grep "COMPLETED" | grep -v "FAILED:" | wc -l)
_fail30count=$(cat 30DayEmail.html | grep "FAILED" | grep -v "FAILED:" | wc -l)
/opt/rundeck/rd-0.1.15/bin/rd projects list | awk -F":" '{print $1}' | awk '{print $2}' | sed 's/^Projects//g' | sed '/^$/d' | sort -nr | while read _line;
do

_count=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \;| grep -i "Deploy_Modules*" | egrep -E "`date +%Y-%m-%d`|`date +%Y-%m-%d --date="1 days ago"`|`date +%Y-%m-%d --date="2 days ago"`|`date +%Y-%m-%d --date="3 days ago"`|`date +%Y-%m-%d --date="4 days ago"`|`date +%Y-%m-%d --date="5 days ago"`|`date +%Y-%m-%d --date="6 days ago"`|`date +%Y-%m-%d --date="7 days ago"`" | grep "$_line" | grep -v grep | wc -l)

_30count=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \;| grep -i "Deploy_Modules*" | egrep -E "`date +%Y-%m-%d`|`date +%Y-%m-%d --date="1 days ago"`|`date +%Y-%m-%d --date="2 days ago"`|`date +%Y-%m-%d --date="3 days ago"`|`date +%Y-%m-%d --date="4 days ago"`|`date +%Y-%m-%d --date="5 days ago"`|`date +%Y-%m-%d --date="6 days ago"`|`date +%Y-%m-%d --date="7 days ago"`|`date +%Y-%m-%d --date="8 days ago"`|`date +%Y-%m-%d --date="9 days ago"`|`date +%Y-%m-%d --date="10 days ago"`|`date +%Y-%m-%d --date="11 days ago"`|`date +%Y-%m-%d --date="12 days ago"`|`date +%Y-%m-%d --date="13 days ago"`|`date +%Y-%m-%d --date="14 days ago"`|`date +%Y-%m-%d --date="15 days ago"`|`date +%Y-%m-%d --date="16 days ago"`|`date +%Y-%m-%d --date="17 days ago"`|`date +%Y-%m-%d --date="18 days ago"`|`date +%Y-%m-%d --date="19 days ago"`|`date +%Y-%m-%d --date="20 days ago"`|`date +%Y-%m-%d --date="21 days ago"`|`date +%Y-%m-%d --date="22 days ago"`|`date +%Y-%m-%d --date="23 days ago"`|`date +%Y-%m-%d --date="24 days ago"`|`date +%Y-%m-%d --date="25 days ago"`|`date +%Y-%m-%d --date="26 days ago"`|`date +%Y-%m-%d --date="27 days ago"`|`date +%Y-%m-%d --date="28 days ago"`|`date +%Y-%m-%d --date="29 days ago"`|`date +%Y-%m-%d --date="30 days ago"`" | grep "$_line" | grep -v grep | wc -l)
#echo "Count For $_line : $_count"
#find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \;| grep test_project | awk '{print $1$3}' | sort -nrk1,1 | sort -nu
_NAME=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $2}' | head -1)
_JOB=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $6}' | head -1)
_DATE=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $3}' | head -1)
_TIME=$(find /opt/rundeck -name "*executions.log*" -exec egrep -i -E "succeeded|failed" '{}' \; | awk -F' ' '{print $1 " "$2 " " $3 " "$4" "$5" "$6" " $8 }' | awk -F'"' '{print $1 " "$2 " "}' | awk -F"[" '{print $2 $3}' | awk -F"]" '{print $1 $2 $3}' | awk -F"," '{print $1 $2 $3}' | awk -F":" '{print $1":"$2" "$3" "$4}' | awk '{print $8" "$4" "$1" "$2" "$7" "$9}' | sort -u -r -k3,3 -k1,1| grep "$_line" | grep -v grep | awk '{print $4}' | head -1)
if [ $_count -eq 0 ]; then

sed -i '/_REPLACE_ME_/a <tr>\n<td align=\"right\">&nbsp;&nbsp;<a href=\"http:\/\/rundeckserver.apache.techpaste.com:80\/'"$_line"'_Jobrun.html\"><b><u>'"$_line"'<\/u><\/b><\/a>&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_NAME"'<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_DATE"'&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_TIME"'&nbsp;<\/td>\n<td align=\"left\" style=\"background-color:#FFFFCC\">&nbsp;&nbsp;NO RELEASE&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_JOB"'&nbsp;<\/td>\n<\/tr>' 7DayEmail.html

fi;

if [ $_30count -eq 0 ]; then
sed -i '/_REPLACE_ME_/a <tr>\n<td align=\"right\">&nbsp;&nbsp;<a href=\"http:\/\/rundeckserver.apache.techpaste.com:80\/'"$_line"'_Jobrun.html\"><b><u>'"$_line"'<\/u><\/b><\/a>&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_NAME"'<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_DATE"'&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_TIME"'&nbsp;<\/td>\n<td align=\"left\" style=\"background-color:#FFFFCC\">&nbsp;&nbsp;NO RELEASE&nbsp;<\/td>\n<td align=\"right\">&nbsp;&nbsp;'"$_JOB"'&nbsp;<\/td>\n<\/tr>' 30DayEmail.html
fi;

done

sed -i 's/_REPLACE_ME_//g' 7DayEmail.html
sed -i 's/_REPLACE_ME_//g' 30DayEmail.html

sed -i 's/__30count__/'"$_total30count"'/g' 30DayEmail.html
sed -i 's/__7count__/'"$_total7count"'/g' 7DayEmail.html

sed -i 's/__PASS7__/'"$_pass7count"'/g' 7DayEmail.html
sed -i 's/__FAIL7__/'"$_fail7count"'/g' 7DayEmail.html

sed -i 's/__PASS30__/'"$_pass30count"'/g' 30DayEmail.html
sed -i 's/__FAIL30__/'"$_fail30count"'/g' 30DayEmail.html
if [[ $1 == "emailmgmt" && -f /opt/scripts/status/7DayEmail.html ]]; then
DATE=`date +%A,%D`

echo "`cat /opt/scripts/status/7DayEmail.html`" | mail -s "$(echo -e "[RUNDECK DASHBOARD] Weekly Release Status Report For ${DATE}\nContent-Type: text/html")" prod_deployment(at)techpaste.com -c manager-prod_deployment(at)techpaste.com -- -f RunDeck(at)techpaste.com
else
echo "Did not find anything."
fi

if [[ $1 == "email30mgmt" && -f /opt/scripts/status/30DayEmail.html ]]; then
DATE=`date +%A,%D`

echo "`cat /opt/scripts/status/30DayEmail.html`" | mail -s "$(echo -e "[RUNDECK DASHBOARD] Monthly Release Status Report For ${DATE}\nContent-Type: text/html")" prod_deployment(at)techpaste.com -c manager-prod_deployment(at)techpaste.com -- -f RunDeck(at)techpaste.com

else
echo "Did not find anything."
fi

}

Main() {
clean_reports
7days_release
30days_release
all_projects
if [[ $_command == "emailmgmt" ]]; then
email_admin $_command

fi

if [[ $_command == "email30mgmt" ]]; then
email_admin $_command

fi
}

Main

3. cd to /opt/scripts/status folder and run the status.sh file after providing the execute privileges. This will generate all the html reports like below including all projects individual job run reports.

rundeck reporting dashboard templates

4. Once all above reports are generated you can use the dashboard to access the individual reports via web browser as shown in the demo screenshots in the starting of the post.

Sending job run reports via Email Weekly and Monthly:

You can schedule the script to generate the reports each day and send emails about job runs daily,weekly and monthly.

30 11 * * * /opt/scripts/status/status.sh
0 11 * * 0 /opt/scripts/status/status.sh emailmgmt
0 0 1 * * /opt/scripts/status/status.sh email30mgmt

Sample Email output for weekly and monthly job runs sent to bigger groups:

Rundeck Dashboard Email Screenshot

This concludes the custom rundeck reporting dashboard creation.

In case of any ┬ęCopyright or missing credits issue please check CopyRights page for faster resolutions.

1 Response

  1. Yedu says:

    Excellent work :@TECHPASTE TEAM. very useful. I have doubt on this line of code. what is this line of code exactly doing ?

    {code}
    \2\3/g” >7DaysRelease.html
    {code}

    reason, am getting only 2_jobrun.html file generated but 7DaysRelease.html file is empty.

Leave a Reply