GRAYBYTE WORDPRESS FILE MANAGER1338

Server IP : 149.255.58.128 / Your IP : 216.73.216.236
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_service.sh
#!/usr/bin/env bash

# Author: Jon Schipp
# 2015-03-09 [Pascal Hegy] - Add sudo for linux
# 2015-03-09 [Pascal Hegy] - Change USER variable to USERNAME to avoid the use and confusion with the USER env variable
# 2017-08-30 [Roberto Leibman] - Reordered checks to make sure dead and inactive get checked first
# 2018-04-25 [Robin Gierse] - Update check via systemctl for Linux with grep to produce better output for systemctl
# 2019-03-15 [nem / liberodark] - Add support for check all failed services in linux

########
# Examples:

# 1.) List services for osx
# $ ./check_service.sh -l -o osx
#
# 2.) Check status of SSH service on a linux machine
# $ ./check_service.sh -o linux -s sshd

# 3.) Manually select service management tool and service
# $ ./check_service.sh -o linux -t "service rsyslog status"
# Exemple for check all failed services
# $ ./check_service.sh -o linux -t "systemctl list-units --state=failed"

# Nagios Exit Codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3

# Weather or not we can trust the exit code from the service management tool.
# Defaults to 0, put to 1 for systemd.  Otherwise we must rely on parsing the
# output from the service management tool.
TRUST_EXIT_CODE=0

usage()
{
cat <<EOF

Check status of system services for Linux, FreeBSD, OSX, and AIX.

     Options:
        -s <service>    Specify service name
        -l              List services
        -o <os>         OS type, "linux/osx/freebsd/aix"
        -u <user>       User if you need to ``sudo -u'' for launchctl (def: nagios, linux and osx only)
        -t <tool>       Manually specify service management tool (def: autodetect) with status and service
                        e.g. ``-t "service nagios status"''


EOF
}

argcheck() {
# if less than n argument
if [ $ARGC -lt $1 ]; then
        echo "Missing arguments! Use \`\`-h'' for help."
        exit 1
fi
}

os_check() {
if [ "$OS" == null ]; then
	unamestr=$(uname)
        if [[ $unamestr == 'Linux' ]]; then
                OS='linux'
        elif [[ $unamestr == 'FreeBSD' ]]; then
               OS='freebsd'
        elif [[ $unamestr == 'Darwin' ]]; then
               OS='osx'	       
        else
                echo "OS not recognized, Use \`-o\` and specify the OS as an argument"
                exit 3
        fi
fi
}



determine_service_tool() {
if [[ $OS == linux ]]; then
        if command -v systemctl >/dev/null 2>&1; then
                SERVICETOOL="systemctl status $SERVICE | grep -i Active"
                LISTTOOL="systemctl"
                if [ $USERNAME ]; then
                    SERVICETOOL="sudo -u $USERNAME systemctl status $SERVICE"
                    LISTTOOL="sudo -u $USERNAME systemctl"
                fi
		TRUST_EXIT_CODE=0
        elif command -v service >/dev/null 2>&1; then
                SERVICETOOL="service $SERVICE status"
                LISTTOOL="service --status-all"
                if [ $USERNAME ]; then
                    SERVICETOOL="sudo -u $USERNAME service $SERVICE status"
                    LISTTOOL="sudo -u $USERNAME service --status-all"
                fi
        elif command -v initctl >/dev/null 2>&1; then
                SERVICETOOL="status $SERVICE"
                LISTTOOL="initctl list"
                if [ $USERNAME ]; then
                    SERVICETOOL="sudo -u $USERNAME status $SERVICE"
                    LISTTOOL="sudo -u $USERNAME initctl list"
                fi
        elif command -v chkconfig >/dev/null 2>&1; then
                SERVICETOOL=chkconfig
                LISTTOOL="chkconfig --list"
                if [ $USERNAME ]; then
                    SERVICETOOL="sudo -u $USERNAME chkconfig"
                    LISTTOOL="sudo -u $USERNAME chkconfig --list"
                fi
        elif [ -f /etc/init.d/$SERVICE ] || [ -d /etc/init.d ]; then
                SERVICETOOL="/etc/init.d/$SERVICE status | tail -1"
                LISTTOOL="ls -1 /etc/init.d/"
                if [ $USERNAME ]; then
                    SERVICETOOL="sudo -u $USERNAME /etc/init.d/$SERVICE status | tail -1"
                    LISTTOOL="sudo -u $USERNAME ls -1 /etc/init.d/"
                fi
        else
                echo "Unable to determine the system's service tool!"
                exit 1
        fi
fi

if [[ $OS == freebsd ]]; then
        if command -v service >/dev/null 2>&1; then
                SERVICETOOL="service $SERVICE status"
                LISTTOOL="service -l"
        elif [ -f /etc/rc.d/$SERVICE ] || [ -d /etc/rc.d ]; then
                SERVICETOOL="/etc/rc.d/$SERVICE status"
                LISTTOOL="ls -1 /etc/rc.d/"
        else
                echo "Unable to determine the system's service tool!"
                exit 1
        fi
fi

if [[ $OS == osx ]]; then
        if [ -f /usr/sbin/serveradmin >/dev/null 2>&1 ] && serveradmin list | grep "$SERVICE" 2>&1 >/dev/null; then
                SERVICETOOL="serveradmin status $SERVICE"
                LISTTOOL="serveradmin list"
        elif [ -f /Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin >/dev/null 2>&1 ] && \
               /Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin list | \
                grep "$SERVICE" 2>&1 >/dev/null; then
                SERVICETOOL="/Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin status $SERVICE"
                LISTTOOL="/Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin list"
        elif command -v launchctl >/dev/null 2>&1; then
                SERVICETOOL="launchctl list | grep -v ^- | grep $SERVICE || echo $SERVICE not running! "
                LISTTOOL="launchctl list"
                if [ $USERNAME ]; then
                        SERVICETOOL="sudo -u $USERNAME launchctl list | grep -v ^- | grep $SERVICE || echo $SERVICE not running! "
                        LISTTOOL="sudo -u $USERNAME launchctl list"
                fi
        elif command -v service >/dev/null 2>&1; then
                SERVICETOOL="service --test-if-configured-on $SERVICE"
                LISTTOOL="service list"
        else
                echo "Unable to determine the system's service tool!"
                exit 1
        fi
fi

if [[ $OS == aix ]]; then
        if command -v lssrc >/dev/null 2>&1; then
                SERVICETOOL="lssrc -s $SERVICE | grep -v Subsystem"
                LISTTOOL="lssrc -a"
        else
                echo "Unable to determine the system's service tool!"
                exit 1
        fi
fi
}

ARGC=$#
LIST=0
MANUAL=0
OS=null
SERVICETOOL=null
LISTTOOL=null
SERVICE=".*"
#USERNAME=nagios

argcheck 1

while getopts "hls:o:t:u:" OPTION
do
     case $OPTION in
         h)
             usage
             exit 0
             ;;
         l)
             LIST=1
             ;;
         s)
             SERVICE="$OPTARG"
             ;;
         o)
             if [[ "$OPTARG" == linux ]]; then
                     OS="$OPTARG"
             elif [[ "$OPTARG" == osx ]]; then
                     OS="$OPTARG"
             elif [[ "$OPTARG" == freebsd ]]; then
                     OS="$OPTARG"
             elif [[ "$OPTARG" == aix ]]; then
                     OS="$OPTARG"
             else
                     echo "Unknown type!"
                     exit 1
             fi
             ;;
         t)
             MANUAL=1
             MANUALSERVICETOOL="$OPTARG"
             ;;
         u)
             USERNAME="$OPTARG"
             ;;
         \?)
             exit 1
             ;;
     esac
done

os_check

if [ $MANUAL -eq 1 ]; then
SERVICETOOL=$MANUALSERVICETOOL
else
determine_service_tool
fi

# -l conflicts with -t                                                                                                                                                   
if [ $MANUAL -eq 1 ] && [ $LIST -eq 1 ]; then
    echo "Options conflict: \`\`-t'' and \`\`-l''"
    exit 2
fi

if [ $LIST -eq 1 ]; then
        if [[ $LISTTOOL != null ]]; then
                $LISTTOOL
                exit 0
        else
                echo "OS not specified! Use \`\`-o''"
                exit 2
        fi
fi

# Check the status of a service
STATUS_MSG=$(eval "$SERVICETOOL" 2>&1)
EXIT_CODE=$?

## Exit code from the service tool - if it's non-zero, we should
## probably return CRITICAL.  (though, in some cases UNKNOWN would
## probably be more appropriate)
[ $EXIT_CODE -ne 0 ] && echo "$STATUS_MSG" && exit $CRITICAL

## For systemd and most systems, $EXIT_CODE can be trusted - if it's 0, the service is running.
## Ref https://github.com/jonschipp/nagios-plugins/issues/15
[ $TRUST_EXIT_CODE -eq 1 ] && [ $EXIT_CODE -eq 0 ] && echo "$STATUS_MSG" && exit $OK 

case $STATUS_MSG in

*stop*)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
*STOPPED*)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
*not*running*)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
*NOT*running*)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
*NOT*RUNNING*)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
#*inactive*)
#        echo "$STATUS_MSG"
#        exit $CRITICAL
#        ;;
*dead*)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
*running*)
        echo "$STATUS_MSG"
        exit $OK
        ;;
*RUNNING*)
        echo "$STATUS_MSG"
        exit $OK
        ;;
*SUCCESS*)
        echo "$STATUS_MSG"
        exit $OK
        ;;
*[eE]rr*)
        echo "Error in command: $STATUS_MSG"
        exit $CRITICAL
        ;;
*[fF]ailed*)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
*[eE]nable*)
        echo "$STATUS_MSG"
        exit $OK
        ;;
*[dD]isable*)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
*[cC]annot*)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
*[aA]ctive*)
        echo "$STATUS_MSG"
        exit $OK
        ;;
*Subsystem*not*on*file)
        echo "$STATUS_MSG"
        exit $CRITICAL
        ;;
[1-9][1-9]*)
        echo "$SERVICE running: $STATUS_MSG"
        exit $OK
        ;;
"")
	echo "$SERVICE is not running: no output from service command"
	exit $CRITICAL
	;;
*)
        echo "Unknown status: $STATUS_MSG"
        echo "Is there a typo in the command or service configuration?: $STATUS_MSG"
        exit $UNKNOWN
        ;;
*0\ loaded*)
        echo "$STATUS_MSG"
        exit $OK
        ;;
esac


[ 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