GRAYBYTE WORDPRESS FILE MANAGER9796

Server IP : 149.255.58.128 / Your IP : 216.73.216.213
System : Linux cloud516.thundercloud.uk 5.14.0-427.26.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 17 15:51:13 EDT 2024 x86_64
PHP Version : 8.2.28
Disable Function : allow_url_include, apache_child_terminate, apache_setenv, exec, passthru, pcntl_exec, posix_kill, posix_mkfifo, posix_getpwuid, posix_setpgid, posix_setsid, posix_setuid, posix_setgid, posix_seteuid, posix_setegid, posix_uname, proc_close, proc_get_status, proc_open, proc_terminate, shell_exec, show_source, system
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /lib64/nagios/plugins/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /lib64/nagios/plugins//check_apache2.sh
#!/bin/sh

#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

PROGNAME=`basename $0`
VERSION="Version 1.21,"
AUTHOR="2009, Mike Adolphs (http://www.matejunkie.com/)"

print_version() {
    echo "$VERSION $AUTHOR"
}

print_help() {
    print_version $PROGNAME $VERSION
    echo ""
    echo "Description"
    echo "$PROGNAME is a Nagios plugin to check the Apache's server status"
    echo "via the famous mod_status. Make sure, that you have permissions"
    echo "to access http://yourserver:port/server-status and that the Nagios"
    echo "User has the right to call 'ps ax' and 'ps -Ao pcpu,args', otherwise"
    echo "the script refuses to work. This will likely occur only on hardened"
    echo "systems."
    echo ""
    echo "How it works:"
    echo "The script first checks whether Apache is running and then gets the"
    echo "server's status page. Req/sec are generated by a diff from the amount"
    echo "of total requests being served by the Apache due to the fact that"
    echo "mod_status only provides an average value for the server's runtime."
    echo "The same applies to the CPU utilization value. Therefore we use ps"
    echo "to get more realistic data."
    echo ""
    echo "The script itself is written sh-compliant and free software under"
    echo "the terms of the GPLv2. There's a default value for each variable. It"
    echo "probably works just out of the box?"
    echo ""
    echo "$PROGNAME -H/--hostname localhost -p/--port 80 -t/--timeout 3 -o \$HOME"
    echo "-b /usr/sbin -e"
    echo ""
    echo "Options:"
    echo "  -b/--binary-dir)"
    echo "     You might need to choose the directory where your apache2 binary is"
    echo "     located. Otherwise the check will fail. Default is: /usr/sbin"
    echo "  -H/--hostname)"
    echo "     You may define a hostname. Default is: localhost"
    echo "  -p/--port)"
    echo "     You may define a port. Default is: 80"
    echo "  -t/--timeout)"
    echo "     You might want to define a timeout (in sec) for the wget call. Default"
    echo "     is: 3"
    echo "  -s/--status-page)"
    echo "     In case your server-status page got a different name, you may define"
    echo "     it here. Default is: server-status"
    echo "  -r/--remote-srv)"
    echo "     If you want to check a remote server and therefore ignore the process"
    echo "     check, you may use -r to turn it off. Default is: off"
    echo "  -o/--output-directory)"
    echo "     You may define a directory where a local copy of server-status"
    echo "     is being stored to spare the Apache. Default is: $HOME"
    echo "  -S/--secure)"
    echo "     Use -S or --secure if your Apache is accessible via HTTPS only. Please"
    echo "     also define the specific port via -p/--port then."
    echo "  -e/--extended-info)"
    echo "     Provides additional performance data: Total amount of requests, total"
    echo "     amount of transferred bytes, bytes per second, bytes per request and"
    echo "     The servers uptime. Default is off."
    echo "  -wr/--warning-req)"
    echo "     Sets a warning level for requests per second and must be used together"
    echo "     with the -c/--critical-req option. Default is off."
    echo "  -cr/--critical-req)"
    echo "     Sets a critical level for requests per second and must be used together"
    echo "     with the -w/--warning-req option. Default is off."
    exit $ST_UK
}

ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3

hostname="localhost"
port=80
timeout=3
status_page="server-status"
remote_srv=0
output_dir=/tmp
binary_dir="/usr/sbin"
secure=0
ext_info=0
running=0

wcdiff_req=0
wclvls_req=0

while test -n "$1"; do
    case "$1" in
        --help|-h)
            print_help
            exit $ST_UK
            ;;
        --version|-v)
            print_version $PROGNAME $VERSION
            exit $ST_UK
            ;;
        --hostname|-H)
             hostname=$2
             shift
             ;;
        --port|-p)
             port=$2
             shift
             ;;
        --timeout|-t)
             timeout=$2
             shift
             ;;
        --remote-server|-r)
             remote_srv=1
             ;;
        --status-page|-s)
             status_page=$2
             shift
             ;;
        --output_directory|-o)
             output_dir=$2
             shift
             ;;
        --binary_dir|-b)
             binay_dir=$2
             shift
             ;;
        --secure|-S)
             secure=1
             ;;
        --extended-info|-e)
             ext_info=1
             ;;
        --warning-req|-wr)
             warn_req=$2
             shift
             ;;
        --critical-req|-cr)
             crit_req=$2
             shift
             ;;
        *)
            echo "Unknown argument: $1"
            print_help
            exit $ST_UK
            ;;
    esac
    shift
done

# get functions
get_wcdiff_req() {
    if [ ! -z "$warn_req" -a ! -z "$crit_req" ]
    then
        wclvls_req=1

        if [ ${warn_req} -gt ${crit_req} ]
        then
            wcdiff_req=1
        fi
    elif [ ! -z "$warn_req" -a -z "$crit_req" ]
    then
        wcdiff_req=2
    elif [ -z "$warn_req" -a ! -z "$crit_req" ]
    then
        wcdiff_req=3
    fi
}

get_processes() {
    ps ax | grep ${binary_dir}/[h]ttpd | grep -c -v "grep"
}

get_status() {
    if [ "$secure" = 1 ]
    then
        wget -q --no-check-certificate -t 3 -T ${timeout} https://${hostname}:${port}/${status_page}?auto -O ${output_dir}/server-status
        sleep 1
        wget -q --no-check-certificate -t 3 -T ${timeout} https://${hostname}:${port}/${status_page}?auto -O ${output_dir}/server-status.1
    else
        wget -q -t 3 -T ${timeout} http://${hostname}:${port}/${status_page}?auto -O ${output_dir}/server-status
        sleep 1
        wget -q -t 3 -T ${timeout} http://${hostname}:${port}/${status_page}?auto -O ${output_dir}/server-status.1
    fi
}

get_total_req() {
    total_req=`cat ${output_dir}/server-status | grep 'Total Accesses:' | awk '{print $3}'`
}

get_total_kb() {
    total_kb=`cat ${output_dir}/server-status | grep 'Total kBytes:' | awk '{print $3}'`
}

get_uptime() {
    uptime=`cat ${output_dir}/server-status | grep 'Uptime:' | awk '{print $2}'`
}

get_cpu_load() {
    cpu_load="$(cpu_load=0; ps -Ao pcpu,args | grep '/usr/sbin/httpd' | awk '{print $1}' | while read line
    do
        cpu_load=`echo "scale=3; $cpu_load + $line" | bc -l`
    echo $cpu_load
    done)"
    cpu_load=`echo $cpu_load | awk '{print $NF}' | sed 's/^\./0./'`
}

get_req_psec() {
    tmp1_req_psec=`cat ${output_dir}/server-status | grep 'Total Accesses:' | awk '{print $3}'`
    tmp2_req_psec=`cat ${output_dir}/server-status.1 | grep 'Total Accesses:' | awk '{print $3}'`
    req_psec=`echo "scale=2; ${tmp2_req_psec} - ${tmp1_req_psec}" | bc -l`
}

get_bytes_psec() {
    bytes_psec=`cat ${output_dir}/server-status | grep 'BytesPerSec:' | awk '{print $2}' | sed 's/^\./0./'`
}

get_bytes_preq() {
    bytes_preq=`cat ${output_dir}/server-status | grep 'BytesPerReq:' | awk '{print $2}' | sed 's/^\./0./'`
}

get_wkrs_busy() {
    wkrs_busy=`cat ${output_dir}/server-status | grep 'BusyWorkers:' | awk '{print $2}'`
}

get_wkrs_idle() {
    wkrs_idle=`cat ${output_dir}/server-status | grep 'IdleWorkers:' | awk '{print $2}'`
}


# check functions
check_processes() {
echo $1
    if [ $1 -lt 1 ]
    then
        echo "CRITICAL - Your Apache server seems not to run. Is your Nagios privileged to run 'ps ax' and is the Apache2 binary really located in $binary_dir?"
        exit $ST_CR
    fi
}

check_output() {
    stat_output=`stat -c %s ${output_dir}/server-status`
    if [ "$stat_output" = 0 ]
    then
        echo "CRITICAL - Local copy of server-status is empty. Are we allowed to access http://${hostname}:${port}/server-status?"
        exit $ST_CR
    fi
}


# Let's do this
get_wcdiff_req

if [ "$wcdiff_req" = 1 ]
then
    echo "Please adjust your warning/critical thresholds. The warning must be lower than the critical level!"
    exit $ST_UK
elif [ "$wcdiff_req" = 2 ]
then
    echo "Please also set a critical value when you want to use warning/critical thresholds!"
    exit $ST_UK
elif [ "$wcdiff_req" = 3 ]
then
    echo "Please also set a warning value when you want to use warning/critical thresholds!"
    exit $ST_UK
else

if [ "$remote_srv" = 0 ]
then
    running=`get_processes`
    check_processes $running
fi

    get_status
    check_output

    case $ext_info in
        1)
            get_req_psec; get_cpu_load; get_uptime; get_wkrs_busy; get_wkrs_idle;
            get_total_req; get_total_kb; get_bytes_psec; get_bytes_preq;
            perfdata="'req_psec'=$req_psec 'cpu_load'=$cpu_load 'uptime'=$uptime 'workers_busy'=$wkrs_busy 'workers_idle'=$wkrs_idle 'total_req'=$total_req 'total_kb'=$total_kb 'bytes_psec'=$bytes_psec 'bytes_preq'=$bytes_preq"
            ;;
        *)
            get_req_psec; get_cpu_load; get_wkrs_busy; get_wkrs_idle;
            perfdata="'req_psec'=$req_psec 'cpu_load'=$cpu_load 'workers_busy'=$wkrs_busy 'workers_idle'=$wkrs_idle"
            ;;
    esac

    rm -f ${output_dir}/server-status*

    if [ ${wclvls_req} = 1 ]
    then
        if [ ${req_psec} -ge ${warn_req} -a ${req_psec} -lt ${crit_req} ]
        then
            echo "WARNING - Apache serves $req_psec Requests per second with an average CPU utilization of $cpu_load% since $uptime seconds. Amount of workers currently busy: $wkrs_busy, currently idle: $wkrs_idle! | $perfdata"
            exit $ST_WR
        elif [ ${req_psec} -ge ${crit_req} ]
        then
            echo "CRITICAL - Apache serves $req_psec Requests per second with an average CPU utilization of $cpu_load% since $uptime seconds. Amount of workers currently busy: $wkrs_busy, currently idle: $wkrs_idle! | $perfdata"
            exit $ST_CR
        else
            echo "OK - Apache serves $req_psec Requests per second with an average CPU utilization of $cpu_load% since $uptime seconds. Amount of workers currently busy: $wkrs_busy, currently idle: $wkrs_idle! | $perfdata"
            exit $ST_OK
        fi
    else
        echo "OK - Apache serves $req_psec Requests per second with an average CPU utilization of $cpu_load% since $uptime seconds. Amount of workers currently busy: $wkrs_busy, currently idle: $wkrs_idle! | $perfdata"
        exit $ST_OK
    fi
fi


[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
April 28 2024 11:20:59
0 / root
0755
eventhandlers
--
April 28 2024 11:20:59
0 / root
0755
check_apache2.sh
10.779 KB
January 30 2013 12:21:10
0 / root
0755
check_cpu.sh
4.36 KB
February 12 2019 08:36:33
0 / root
0755
check_crm.pl
6.467 KB
September 17 2015 13:45:51
0 / root
0755
check_disk
53.047 KB
March 28 2024 13:15:48
0 / root
0755
check_iface.php
5.883 KB
September 29 2015 14:20:25
0 / root
0755
check_jetbackup
7.843 KB
July 29 2024 11:13:24
0 / root
0755
check_load
35.703 KB
March 28 2024 13:15:48
0 / root
0755
check_mem.pl
6.235 KB
January 28 2013 15:36:20
0 / root
0755
check_mpt.sh
2.267 KB
February 18 2015 18:15:28
0 / root
0755
check_mqueue_exiqgrep.sh
0.97 KB
February 27 2023 18:26:09
0 / root
0755
check_mqueue_postfix.sh
1.082 KB
February 13 2019 10:23:20
0 / root
0755
check_mysql.pl
27.219 KB
January 30 2013 13:09:36
0 / root
0755
check_mysql_replication.sh
2.065 KB
May 20 2010 10:29:33
0 / root
0755
check_raid.pl
114.584 KB
November 20 2015 12:37:21
0 / root
0755
check_service.sh
10.078 KB
October 30 2024 17:54:56
0 / root
0755
check_swap
31.719 KB
March 28 2024 13:15:48
0 / root
0755
error_log
0.551 KB
May 03 2024 08:18:25
0 / root
0644
negate
27.617 KB
March 28 2024 13:15:48
0 / root
0755
urlize
23.359 KB
March 28 2024 13:15:48
0 / root
0755
utils.sh
2.729 KB
March 28 2024 13:15:40
0 / root
0755

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF