Difference between revisions of "Errornotify"

From James Dooley's Wiki
Jump to: navigation, search
(Script)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
[[Category:Scripts]]
 
==Overview==
 
==Overview==
 
A simple script I wrote to email me a summery of apache error messages in the last 24 hours.
 
A simple script I wrote to email me a summery of apache error messages in the last 24 hours.
Line 6: Line 7:
 
==Script==
 
==Script==
  
<code>[bash,n]
+
<source lang='bash'>
 
#!/bin/bash
 
#!/bin/bash
  
Line 61: Line 62:
  
 
rm -f email.txt
 
rm -f email.txt
</code>
+
</source>
  
 
==What to change==
 
==What to change==

Latest revision as of 14:32, 25 March 2014

Overview

A simple script I wrote to email me a summery of apache error messages in the last 24 hours.

Cuts out uniq data such as IP addresses and unique_ids for modsec.

Script

#!/bin/bash

acctlist="jamesdoo;jamesdooley.us;james@jamesdooley.us devize;devize.us;james@jamesdooley.us"

servername="server1.infusedsites.com"
masteremail="server@infusedsites.com"

logperiod=`date +"%b %d"`
fulllogs=`grep "$logperiod" /usr/local/apache/logs/error_log`
modseclogs=`echo "$fulllogs" | grep "ModSec" | cut -d "]" -f2- | sort | cut -d "]" -f1,3- | rev | cut -d "[" -f2- | rev | sort | uniq -c | sort -nr`
remaininglogs=`echo "$fulllogs" | grep -v "ModSec" | cut -d "]" -f2- | sort | uniq -c | sort -nr`

function masterlogs {
	echo -e "Daily Apache Error report for $servername \n\n\n" > email.txt
	echo -e "\n\n====Error Messages====\n" >> email.txt
	echo "$remaininglogs" | grep "\[error\]" >> email.txt
	echo -e "\n\n====Warnings====\n" >> email.txt
	echo "$remaininglogs" | grep "\[warn\]" >> email.txt
	echo -e "\n\n====Notice====\n"  >> email.txt
	echo "$remaininglogs" | grep "\[notice\]" >> email.txt
	echo -e "\n\n====ModSec====\n" >> email.txt
	echo "$modseclogs" >> email.txt
 
	cat email.txt | mail -s "Daily Apache Error Log Report" $masteremail
}

function processacctlogs {
	user=`echo $1 | cut -d ";" -f1`
	domain=`echo $1 | cut -d ";" -f2`
	email=`echo $1 | cut -d ";" -f3`
	
	domainlogs=`echo "$remaininglogs" | grep "$domain\|$user"`
	domainmodsec=`echo "$modseclogs" | grep "$domain\|$user"`
	
	echo -e "Daily Apache error report for $domain \n\n\n" > email.txt
	echo -e "\n\n====Error Messages====\n" >> email.txt
	echo "$domainlogs" | grep "\[error\]" >> email.txt
	echo -e "\n\n====Warnings====\n" >> email.txt
	echo "$domainlogs" | grep "\[warn\]" >> email.txt
	echo -e "\n\n====Notice====\n"  >> email.txt
	echo "$domainlogs" | grep "\[notice\]" >> email.txt
	echo -e "\n\n====ModSec====\n" >> email.txt
	echo "$domainmodsec" >> email.txt
	
	cat email.txt | mail -s "Daily Apache error log report for $domain" $email
}

masterlogs;
for account in $(echo $acctlist);
do
	processacctlogs $account
done

rm -f email.txt

What to change