Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added customer token to Linux script #67

Closed
wants to merge 77 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
a24007e
Added customer token to configsyslog
Jun 24, 2014
7d10190
Validated Tomcat installation before Linux
Jun 24, 2014
b12a1f1
Added support to check Loggly port reachabilty
Jun 26, 2014
4160bca
Support for Tomcat downloaded as a package
Jun 26, 2014
8e46033
Added Apache2 Configuration Script
Jun 30, 2014
040fcaf
Download Linux script inside it
Jul 1, 2014
3f133cd
Downloads Linux script inside it
Jul 1, 2014
1e00b42
Logging OS name to Loggly if unsupported
Jul 3, 2014
c6b391f
Updated Red Hat to RedHat
Jul 3, 2014
1de793f
Updated RedhHat/ CentOS log file name
Jul 3, 2014
318770b
Stop of the user do not want to restart tomcat
Jul 3, 2014
dc77925
No verification if already configured
Jul 4, 2014
e6d46eb
No verification if already configured
Jul 4, 2014
afb9a36
Updated typos and link
Jul 4, 2014
2868b89
Removed duplicate variables and updated message
Jul 9, 2014
cb88b8f
Removed duplicate variables
Jul 9, 2014
b0115f9
Added file monitoring script
Jul 9, 2014
dee3dc3
Updated Manual link and Logging file name also
Jul 10, 2014
8e21171
Updated warning text
Jul 11, 2014
69324a4
Updated message text
Jul 11, 2014
200fd93
Made token optional
Jul 11, 2014
4bfbbc0
Made token optional
Jul 11, 2014
6f4412f
Made token optional
Jul 11, 2014
a1b6222
Check if the file name/ path contains spaces
Jul 14, 2014
1ae7d6b
Removed Extra characters
Jul 14, 2014
fe0a452
Updated version 1.0 to 1.01
Jul 14, 2014
0cf4b30
Updated message
Jul 15, 2014
1d22a45
Removed extra break
Jul 15, 2014
d63e96d
Updated text message
Jul 15, 2014
c6197df
Configure script if log file size is 0
Jul 16, 2014
9a98ed3
Configure Script if log file size is 0
Jul 16, 2014
8bffdca
Added README.md for the Linux Script
Jul 18, 2014
35323ad
Updated README
Jul 18, 2014
5d6e636
Create README.md
Jul 18, 2014
3752d2c
Create README.md
Jul 18, 2014
c4bf094
Update README.md
Jul 18, 2014
04891f1
Update README.md
Jul 18, 2014
14f566d
Create README.md
Jul 18, 2014
138ef2f
Incorporated Manoj's Feedback
Jul 21, 2014
aac29fa
Incorporated Manoj's Feedback
Jul 21, 2014
b45d7e9
Update README.md
Jul 21, 2014
be5085d
Update README.md
Jul 21, 2014
2364a89
Update README.md
Jul 21, 2014
e96a030
Update README.md
Jul 21, 2014
4c2ffe6
Updated script to support any Linux OS
Jul 23, 2014
302c243
Merge branch 'master' of https://github.com/psquickitjayant/install-s…
Jul 23, 2014
85df450
Added s3 monitoring scripts
Jul 25, 2014
f9c864d
Add support to Amazon AMI OS
Jul 27, 2014
8fee938
Removed extra variable
Jul 28, 2014
2cac672
Updated command
Jul 28, 2014
6c54ab7
Updated version number
Jul 28, 2014
c64f4b3
Updated version number
Jul 28, 2014
e7a7328
Updated version number
Jul 28, 2014
3d44e13
Updated Scripts (Under development)
Jul 28, 2014
beccd2a
Added check for sub domain
Jul 29, 2014
9d522f8
Changed message if Mac OSX found
Jul 30, 2014
151b89e
Revert "Changed message if Mac OSX found"
Jul 30, 2014
cc07795
Changed message if "Darwin OS"
Jul 30, 2014
9787d95
Updated s3 Script. Under Developement
Jul 30, 2014
29d982b
Added comments
Jul 30, 2014
bc505b9
Add support to download bucket/ file using -s3b
Jul 31, 2014
cfb1435
Minor Bug Fix
Jul 31, 2014
dcab550
Updated s3b to s3url and Minor bug fixes
Aug 1, 2014
2f3cf7e
Added more checks for the bucket name validation
Aug 4, 2014
b8abcd0
Removed extra quotes
Aug 5, 2014
7eac676
Updated script to support s3 file monitoring
Aug 5, 2014
a9436f9
Added check for the directory
Aug 5, 2014
991e9fb
Delete Temp Folder after Rollback
Aug 6, 2014
c22bc30
Added dynamic tag to modify from other scripts
Aug 7, 2014
9919125
Fixed a bug
Aug 7, 2014
cda8b4b
Revert "Fixed a bug"
Aug 7, 2014
c7d1e72
S3 Script: Added "s3file" tag
Aug 7, 2014
7dbf18a
Updated script to support multiple Linux machines
Aug 18, 2014
b84686d
File-Monitoring-
Aug 19, 2014
b7f7443
Revert "File-Monitoring-"
Aug 19, 2014
a2d377e
File-monitoring: Added support to set Format name
Aug 19, 2014
408af55
S3 Script: Setting New Format name
Aug 19, 2014
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Added Apache2 Configuration Script

  • Loading branch information
psquickitjayant
psquickitjayant committed Jun 30, 2014
commit 8e46033abd9e7e91532439da76c89733698c251e
@@ -0,0 +1,377 @@
#!/bin/bash

source configure-linux.sh "being-invoked"

########## Variable Declarations - Start ##########
#name of the current script
SCRIPT_NAME=configure-apache.sh
#version of the current script
SCRIPT_VERSION=1.0

#we have not found the apache version yet at this point in the script
APP_TAG="\"apache-version\":\"\""

#name of the service, in this case apache2
SERVICE=
#directory location for syslog
SYSLOG_ETCDIR_CONF=/etc/rsyslog.d
#name and location of apache syslog file
APACHE_SYSLOG_CONFFILE=$SYSLOG_ETCDIR_CONF/21-apache.conf
#name and location of apache syslog backup file
APACHE_SYSLOG_CONFFILE_BACKUP=$SYSLOG_ETCDIR_CONF/21-apache.conf.loggly.bk
#syslog directory
SYSLOG_DIR=/var/spool/rsyslog

#this variable will hold the path to the apache home
LOGGLY_APACHE_HOME=
#this variable will hold the value of the apache log folder
LOGGLY_APACHE_LOG_HOME=
#this variable will hold the users apache version
APACHE_VERSION=

MANUAL_CONFIG_INSTRUCTION="Manual instructions to configure Apache2 is available at https://www.loggly.com/docs/apache-application-server"

#this variable will hold if the check env function for linux is invoked
APACHE_ENV_VALIDATED=

This comment has been minimized.

@mchaudhary

mchaudhary Jul 17, 2014
Contributor

Default it to False here

########## Variable Declarations - End ##########

#check if apache environment is compatible for Loggly
checkApacheLogglyCompatibility()
{
#check if the linux environment is compatible for Loggly
checkLinuxLogglyCompatibility

#check if apache2 is installed on unix system
checkApacheDetails

APACHE_ENV_VALIDATED="true"
}


# executing the script for loggly to install and configure syslog.
installLogglyConfForApache()
{
#log message indicating starting of Loggly configuration
logMsgToConfigSysLog "INFO" "INFO: Initiating Configure Loggly for Apache."

#check if apache environment is compatible with Loggly
if [ "$APACHE_ENV_VALIDATED" = "" ]; then
checkApacheLogglyCompatibility
fi

#configure loggly for Linux
installLogglyConf

#check for the apache log file size
checkLogFileSize $LOGGLY_APACHE_LOG_HOME/access.log $LOGGLY_APACHE_LOG_HOME/error.log

#create 21apache.conf file
write21ApacheConfFile

#verify if the apache logs made it to loggly
checkIfApacheLogsMadeToLoggly

#log success message
logMsgToConfigSysLog "SUCCESS" "SUCCESS: Apache successfully configured to send logs via Loggly."
}

#executing script to remove loggly configuration for Apache
removeLogglyConfForApache()
{
logMsgToConfigSysLog "INFO" "INFO: Initiating rollback."

#check if the user has root permission to run this script
checkIfUserHasRootPrivileges

#check if the OS is supported by the script. If no, then exit
checkIfSupportedOS

#check if apache2 is installed on unix system
checkApacheDetails

#remove 21apache.conf file
remove21ApacheConfFile

logMsgToConfigSysLog "INFO" "INFO: Rollback completed."
}

#identify if apache2 is installed on your system and is available as a service
checkApacheDetails()
{
getApacheServiceName

#verify if apache is installed as service
if [ ! -f /etc/init.d/$SERVICE ]; then
logMsgToConfigSysLog "ERROR" "ERROR: Apache is not configured as a service"
exit 1
fi

#get the version of apache installed
getApacheVersion

#check if apache is supported
checkIfSupportedApacheVersion

#set all the required apache variables by this script
setApacheVariables
}

#Get the apache service name on various linux flavors
getApacheServiceName()
{
case "$LINUX_DIST" in
*"Ubuntu"* )
SERVICE="apache2"
;;
*"Red Hat"* )
SERVICE="httpd"
;;
*"CentOS"* )
SERVICE="httpd"
;;
esac
}

#sets apache variables which will be used across various functions
setApacheVariables()
{
LOGGLY_APACHE_LOG_HOME=/var/log/$SERVICE
}

#gets the version of apache installed on the unix box
getApacheVersion()
{
APACHE_VERSION=$($SERVICE -v | grep "Server version: Apache")
APACHE_VERSION=${APACHE_VERSION#*/}
APACHE_VERSION=${APACHE_VERSION% *}
APACHE_VERSION=$APACHE_VERSION | tr -d ' '
APP_TAG="\"apache-version\":\"$APACHE_VERSION\""
echo "Apache version: " $APACHE_VERSION

This comment has been minimized.

@mchaudhary

mchaudhary Jul 17, 2014
Contributor

Log it to loggly instead of echo

}

#checks if the apache version is supported by this script, currently the script
#only supports apache2
checkIfSupportedApacheVersion()
{
apacheMajorVersion=${APACHE_VERSION%%.*}
if [[ ($apacheMajorVersion -ne 2 ) ]]; then
logMsgToConfigSysLog "ERROR" "ERROR: This script only supports Apache version 2."
exit 1
fi
}

checkLogFileSize()
{
accessFileSize=$(wc -c "$1" | cut -f 1 -d ' ')
errorFileSize=$(wc -c "$2" | cut -f 1 -d ' ')
fileSize=$((accessFileSize+errorFileSize))
if [ $fileSize -ge 100000000 ]; then

This comment has been minimized.

@mchaudhary

mchaudhary Jul 17, 2014
Contributor

This is 95.3 MB or so we should change it to be 100 MB like the one in the linux file monitoring script

logMsgToConfigSysLog "INFO" "INFO: "
while true; do
read -p "WARN: There are currently large log files which may use up your allowed volume. Please rotate your logs before continuing. Would you like to continue now anyway? (yes/no)" yn
case $yn in
[Yy]* )
logMsgToConfigSysLog "INFO" "INFO: Current apache logs size is $fileSize. Continuing with Apache Loggly configuration.";
break;;
[Nn]* )
logMsgToConfigSysLog "INFO" "INFO: Current apache logs size is $fileSize. Discontinuing with Apache Loggly configuration."
exit 1
break;;
* ) echo "Please answer yes or no.";;
esac
done
elif [ $fileSize -eq 0 ]; then
logMsgToConfigSysLog "WARN" "WARN: There are no recent log files from Apache so verification may not succeed."
fi
}

write21ApacheConfFile()
{
#Create apache syslog config file if it doesn't exist
echo "INFO: Checking if apache sysconf file $APACHE_SYSLOG_CONFFILE exist."
if [ -f "$APACHE_SYSLOG_CONFFILE" ]; then
logMsgToConfigSysLog "WARN" "WARN: Apache syslog file $APACHE_SYSLOG_CONFFILE already exist."
while true; do
read -p "Do you wish to override $APACHE_SYSLOG_CONFFILE? (yes/no)" yn
case $yn in
[Yy]* )
logMsgToConfigSysLog "INFO" "INFO: Going to back up the conf file: $APACHE_SYSLOG_CONFFILE to $APACHE_SYSLOG_CONFFILE_BACKUP";
sudo mv -f $APACHE_SYSLOG_CONFFILE $APACHE_SYSLOG_CONFFILE_BACKUP;
write21ApacheFileContents;
break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
else
write21ApacheFileContents
fi
}

#function to write the contents of apache syslog config file
write21ApacheFileContents()
{

logMsgToConfigSysLog "INFO" "INFO: Creating file $APACHE_SYSLOG_CONFFILE"
sudo touch $APACHE_SYSLOG_CONFFILE
sudo chmod o+w $APACHE_SYSLOG_CONFFILE

imfileStr="\$ModLoad imfile
\$InputFilePollInterval 10
\$WorkDirectory $SYSLOG_DIR
"
if [[ "$LINUX_DIST" == *"Ubuntu"* ]]; then
imfileStr+="\$PrivDropToGroup adm
"
fi

imfileStr+="
# Apache access file:
\$InputFileName $LOGGLY_APACHE_LOG_HOME/access.log
\$InputFileTag apache-access:
\$InputFileStateFile stat-apache-access
\$InputFileSeverity info
\$InputFilePersistStateInterval 20000
\$InputRunFileMonitor
#Apache Error file:
\$InputFileName $LOGGLY_APACHE_LOG_HOME/error.log
\$InputFileTag apache-error:
\$InputFileStateFile stat-apache-error
\$InputFileSeverity error
\$InputFilePersistStateInterval 20000
\$InputRunFileMonitor
#Add a tag for apache events
\$template LogglyFormatApache,\"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [$LOGGLY_AUTH_TOKEN@41058 tag=\\\"apache\\\"] %msg%\n\"
if \$programname == 'apache-access' then @@logs-01.loggly.com:514;LogglyFormatApache
if \$programname == 'apache-access' then ~
if \$programname == 'apache-error' then @@logs-01.loggly.com:514;LogglyFormatApache
if \$programname == 'apache-error' then ~
"

#change the apache-21 file to variable from above and also take the directory of the apache log file.
sudo cat << EOIPFW >> $APACHE_SYSLOG_CONFFILE
$imfileStr
EOIPFW

restartRsyslog
}


#checks if the apache logs made to loggly
checkIfApacheLogsMadeToLoggly()
{
counter=1
maxCounter=10

apacheInitialLogCount=0
apacheLatestLogCount=0
queryParam="tag%3Aapache&from=-15m&until=now&size=1"

queryUrl="$LOGGLY_ACCOUNT_URL/apiv2/search?q=$queryParam"
logMsgToConfigSysLog "INFO" "INFO: Search URL: $queryUrl"

logMsgToConfigSysLog "INFO" "INFO: Getting initial apache log count."
#get the initial count of apache logs for past 15 minutes
searchAndFetch apacheInitialLogCount "$queryUrl"

logMsgToConfigSysLog "INFO" "INFO: Verifying if the apache logs made it to Loggly."
logMsgToConfigSysLog "INFO" "INFO: Verification # $counter of total $maxCounter."
#get the final count of apache logs for past 15 minutes
searchAndFetch apacheLatestLogCount "$queryUrl"
let counter=$counter+1

while [ "$apacheLatestLogCount" -le "$apacheInitialLogCount" ]; do
echo "INFO: Did not find the test log message in Loggly's search yet. Waiting for 30 secs."
sleep 30
echo "INFO: Done waiting. Verifying again."
logMsgToConfigSysLog "INFO" "INFO: Verification # $counter of total $maxCounter."
searchAndFetch apacheLatestLogCount "$queryUrl"
let counter=$counter+1
if [ "$counter" -gt "$maxCounter" ]; then
logMsgToConfigSysLog "ERROR" "ERROR: Apache logs did not make to Loggly in time. Please check your token & network/firewall settings and retry."
exit 1
fi
done

if [ "$apacheLatestLogCount" -gt "$apacheInitialLogCount" ]; then
logMsgToConfigSysLog "SUCCESS" "SUCCESS: Apache logs successfully transferred to Loggly! You are now sending Apache logs to Loggly."
exit 0
fi
}

#remove 21apache.conf file
remove21ApacheConfFile()
{
echo "INFO: Deleting the loggly apache syslog conf file."
if [ -f "$APACHE_SYSLOG_CONFFILE" ]; then
sudo rm -rf "$APACHE_SYSLOG_CONFFILE"
fi
echo "INFO: Removed all the modified files."
restartRsyslog
}

#display usage syntax
usage()
{
cat << EOF
usage: configure-apache [-a loggly auth account or subdomain] [-t loggly token] [-u username] [-p password (optional)] [-ah apache home (optional)]
usage: configure-linux [-a loggly auth account or subdomain] [-r to rollback]
usage: configure-apache [-h for help]
EOF
}

########## Get Inputs from User - Start ##########

if [ $# -eq 0 ]; then
usage
exit
else
while [ "$1" != "" ]; do
case $1 in
-t | --token ) shift
LOGGLY_AUTH_TOKEN=$1
echo "AUTH TOKEN $LOGGLY_AUTH_TOKEN"

This comment has been minimized.

@mchaudhary

mchaudhary Jul 17, 2014
Contributor

we should log this to loggly account. Any reason why we are not logging this same for other input parameters from users

This comment has been minimized.

@varshneyjayant

varshneyjayant Jul 18, 2014
Author Contributor

@mchaudhary We log customer-token, username and subdomain as fields with each log sent to configsyslog account.

;;
-a | --account ) shift
LOGGLY_ACCOUNT=$1
echo "Loggly account or subdomain: $LOGGLY_ACCOUNT"
;;
-u | --username ) shift
LOGGLY_USERNAME=$1
echo "Username is set"
;;
-p | --password ) shift
LOGGLY_PASSWORD=$1
;;
-r | --rollback )
LOGGLY_ROLLBACK="true"
;;
-h | --help)
usage
exit
;;
esac
shift
done
fi

if [ "$LOGGLY_DEBUG" != "" -a "$LOGGLY_AUTH_TOKEN" != "" -a "$LOGGLY_ACCOUNT" != "" -a "$LOGGLY_USERNAME" != "" ]; then
if [ "$LOGGLY_PASSWORD" = "" ]; then
getPassword
fi
debug
elif [ "$LOGGLY_AUTH_TOKEN" != "" -a "$LOGGLY_ACCOUNT" != "" -a "$LOGGLY_USERNAME" != "" ]; then
if [ "$LOGGLY_PASSWORD" = "" ]; then
getPassword
fi
installLogglyConfForApache
elif [ "$LOGGLY_ROLLBACK" != "" -a "$LOGGLY_ACCOUNT" != "" ]; then
removeLogglyConfForApache
else
usage
fi

########## Get Inputs from User - End ##########
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.