Get alert about LAMP stack

In this article I am going to show you a very very rudimentary script to get over it.I have written it just to show you how it can be done,but having said that this script can be written with more information and much more complex way.Yes ,there is a  lot scope of improvement of this script and I would like to get your feedback on that.

So without much delay here is the mundane script to monitor the LAMP stack and provide alert


1 #!/bin/bash
2 # This program is written for my own help.Needs lot of tweaking.
3 #This script is written on Fedora and RHEL keep in mind,so other distribution
4 #should cross check the binary space of the specified program to their distribution.
5 #Author : Bhaskar Chowdhury
6 #Date : 03-12-2010
7
8
9 date=`date`
10
11 echo "Today is :" $date
12 echo
13 echo
14 host_name=`hostname`
15 echo "This is for the $host_name"
16 echo
17 echo
18 #System binary location information
19 kernel=`uname -r`
20
21 apache=`/usr/sbin/httpd -v`
22
23 mysql=`/usr/bin/mysql --version`
24
25 php=`/usr/bin/php -v`
26
27 webroot='/var/www/html'
28
29 mail='whoeverincahrgeofit@gmail.com' #The person in-charge of lamp stack
30
31 echo "******************************* GNU/Linux ******************************"
32
33 echo " We are running Linux Kernel: " $kernel
34 echo
35 echo
36
37
38
39
40 echo
41 echo
42 echo "Check out kernel stuff...."
43 echo
44
45
46 /sbin/sysctl -p
47 echo
48 echo
49
50
51 echo
52 echo "********************* OS End *************************"
53 echo
54 echo
55
56 sleep 5
57
58
59 echo "************ Apache ******************"
60 echo
61
62 echo " We are running Apache : " $apache
63 echo
64 echo
65
66
67 echo " How Apache has been compiled with other stuff : "
68 echo
69 echo
70
71 /usr/sbin/httpd -V
72
73 echo
74 echo
75
76 echo "Check out the modules loaded with it.."
77
78 /usr/sbin/httpd -M
79
80 echo
81 echo
82 echo
83
84 echo " Check out Apache process ..."
85 echo
86
87 ps -ef | grep httpd
88
89 echo
90 echo
91
92 sleep 5
93
94 echo
95 echo "***************************** Apache End *************************"
96 echo
97 echo
98
99
100 echo " **************** PHP **********************"
101 echo
102
103
104 echo "We are running Php : " $php
105 echo
106 echo
107
108
109 echo " Let's check out php related thing ..checking ini files....."
110 echo
111 echo
112
113 php --ini
114
115 echo
116 echo
117 echo " Get details of php things into the system..like modules and other stuff..."
118 echo
119 echo
120
121 php -im
122
123 echo
124 echo
125 echo
126 echo "****************************** PHP End **********************************"
127 echo
128 echo
129
130 sleep 5
131
132
133 echo "************************** MySql ***********************"
134
135
136 echo "We are running MySql : " $mysql
137 echo
138 echo
139 echo
140
141
142 echo " Check out the process for it....."
143 echo
144 echo
145
146 ps -ef | grep mysql
147
148 echo
149 echo
150
151
152 echo "****************************** MySql End **************************"
153 echo
154 echo
155
156 sleep 5
157
158 echo " Let's check the web tree permission.."
159
160 echo
161
162 ls -d $webroot
163
164 echo
165 echo
166
167 echo " Check out the SELinux thing applied on the webtree ..."
168 echo
169 echo
170
171 ls -Z $webroot
172 echo
173 echo
174
175 #if [[ `pidof httpd` -ne 0 ]]
176 # then
177 # echo "Httpd seems working fine!"
178 #else
179 # echo " problem with httpd daemon"
180 #fi
181
182 #if [[ `pidof mysql` -ne 0 ]]
183 #then
184 # echo " Yup,mysql working"
185 #else
186 #echo " Seems to check the mysql thing"
187 #fi
188
189
190 #if [[`pidof php` -ne 0 ]]
191 #then
192 # echo "Looks good"
193 #else
194 # echo " Problem with php"
195 #fi
196
197 echo " If the stack goes down ..let me know.."
198 echo
199 echo
200
201 if [[`/sbin/pidof httpd mysqld php` -eq 0 ]]
202 then
203 mail -s "problem with lamp stack" $mail
204 echo "Mail sent with information"
205 fi

Now you can trash out lot of echo statement out of that script,but I’ve kept it for readability .The basic motto behind that script to check out the binary position of those LAMP(GNU/Linux,Apache,MySql,Php/Perl/Python) software and call them to verify it.Then I move onto checking how the web server( In this case Apache) was complied with what sort of flags.

Next checking out ini file related to php thing and then mysql server started or not.Then I checked the web root tree permission and SELinux thing with it.Finally if something not working (by checking the pid of it,kindly point out the better way to check)and if that is equal to zero then surely something not came up in the stack and need attention.

This script is just an outline and as I said need your feedback(with reason) to improve it.

Hope this will help.

Cheers!
Bhaskar

About unixbhaskar
GNU/Linux Consultant

One Response to Get alert about LAMP stack

  1. Pingback: Links 9/12/2010: Up to Another 1.5 Million GNU/Linux Laptops in Brazil, Mageia Gets Official Logo, Dell and Red Hat Grow Closer | Techrights

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: