---Work in progress---

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
 
neat="################################"
methodhttpd1=$( cat /etc/*release | grep -ic centos )
methodhttpd2=$( cat /etc/*release | grep -ic red )
#method rhl
methodapache1=$( cat /etc/*release | grep -ic ubuntu )
methodapache2=$( cat /etc/*release | grep -ic debian )
#method debian
 
##################################
#########CENTOS/RHL###############
apacherunning=$(service httpd status | grep -ic running)
apacheportcentos=$(netstat -plnt | grep http | awk '{print $4}' | sed 's/://g')
currentconcentos=$(ps afx | grep -ic /usr/sbin/httpd)
 
#FIX below when access to a server with max clients configured
maxclientscento=$(grep MaxClients /etc/httpd/conf/httpd.conf) #add awk for specific value
#maxclientscentos=$(grep "IfModule prefork.c" -A 6 /etc/httpd/conf/httpd.conf | grep MaxClients | awk '{print $2}')
 
#####Error Log data#####
# SORT OUT REGEX FOR ERROR LOGS error.log / error_log
errorlogformat=$(grep ^ErrorLog /etc/httpd/conf/httpd.conf | awk '{print $2}' | sed 's/.*[/]//')
errorlogcentos=$( grep -ic maxc /var/log/httpd/$errorlogformat )
zerrorlogcentos=$( zgrep -i maxc /var/log/httpd/error_log* )
 
#####APACHE BUDDY DATA#####
apachebuddy=$(curl http://cloudfiles.fanatassist.com/apachebuddy.pl --silent | perl | grep -ohe 'Percentage of RAM allocated to Apache.*' | awk '{print $7}')
apachebuddyram=$(curl http://cloudfiles.fanatassist.com/apachebuddy.pl --silent | perl | grep -ohe 'Max potential memory usage:.*' | awk '{print $5}')
 
##################################
########Ubuntu/Debian#############
 
 
 
 
 
##################################
 
echo $neat
echo ""
##################################
method1() {
 
        case $apacherunning in
 
#------------------------
# apache not running!
        0 )
            echo "Not running"
            echo "Please troubleshoot further"
            echo ""
            echo $neat
# error logs?
#------------------------
#if apache is running then:
        ;;
        1 )
echo "Apache: is running!"
echo "Port: "$apacheportcentos
echo "Current Connections "$currentconcentos
echo "Configured Max Connections: "$maxclientscentos
#if there is a value configured in apache config file for MaxClients then calculate difference between current connections and configured connections
    if [ "$maxclientscentos" != "" ] && [ "$maxclientscentos" -ge 1 ];then
        maxcdiff=$(awk '{$maxclientscentos - $currentconcentos}')
        echo "Difference = "$maxcdiff
            if [ "$maxcdiff" -ge 1 ]; then
                echo "MaxClients: Not been reached"
            elif [ "$maxcdiff" = [1-9] ]; then
                echo "MaxClients: CLOSE TO LIMIT"
            else
                echo "MaxClients: LIMIT REACHED!"
            fi
# if no value has been added then
    else
        echo ""
        echo "MaxClients: No Configured Value In Apache Config File!!"
        echo "Checking with apache buddy..."
    fi
 
 #add awk for maxcdiff=$(awk '{$maxclientscentos - $currentconcentos}')
 
 
    if [ "$errorlogcentos" -ge 1 ]; then
# maxclients may have been hit a previous day, try to incoporate date in the search
        echo "Error logs:"
        echo $errologscentos
    else #elif
####APACHE BUDDY SECTION####
        echo ""
        echo "Error Logs: Nothing to report!"
        echo "Current RAM allocation to apache: "$apachebuddy"%"
        echo "Apache Max RAM Usage: "$apachebuddyram"MB"
 
        case $apachebuddy in
        [0-75] )
            echo "apache has been allocated too much ram, this could be causing an issue"
        ;;
        *)
            echo "Apache Configuration: OK!"
        ;;
        esac
#############################
echo ""
echo $neat
#else
    fi
 
 
 
 
echo $neat
 
 
;;
        esac
}
 
 
#################################################
#Ubuntu
method2() {
 
 
 
echo "test"
 
 
 
 
}
 
##################################
if [ $methodhttpd1 -ge 1 ] || [ $methodhttpd2 -ge 1 ]; then
 
 
method1
 
 
##################################
elif [ $methodapache1 -ge 1 ] || [ $methodapache2 -ge 1 ]; then
 
 
method2
 
 
###################################
else
 
echo "Error! Server does not appear to be Ubuntu or Centos"
 
fi
###################################
#case $variable in
#
#apache )
#echo "Apache results: "
#echo "Maxclients = "
#echo "Recommended clients= "
#echo "Currently set clients= "
#echo "List of connected IPs= "
#;;
##################################