diff options
author | B Stack <bgstack15@gmail.com> | 2017-01-10 13:55:17 -0500 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2017-01-10 13:55:17 -0500 |
commit | dd9977e7a46e2b45ea93d27d92c9492256cdc975 (patch) | |
tree | 82e1639251036d7b50842886966dd60693e37b53 | |
download | nagios-plugins-apache-threads-dd9977e7a46e2b45ea93d27d92c9492256cdc975.tar.gz nagios-plugins-apache-threads-dd9977e7a46e2b45ea93d27d92c9492256cdc975.tar.bz2 nagios-plugins-apache-threads-dd9977e7a46e2b45ea93d27d92c9492256cdc975.zip |
7 files changed, 318 insertions, 0 deletions
diff --git a/usr/lib/nagios/plugins/check_apache_threads b/usr/lib/nagios/plugins/check_apache_threads new file mode 100644 index 0000000..170fe45 --- /dev/null +++ b/usr/lib/nagios/plugins/check_apache_threads @@ -0,0 +1,140 @@ +#!/bin/sh +# File: /usr/lib64/nagios/plugins/check_apache_threads +# Author: bgstack15@gmail.com +# Startdate: 2017-01-09 15:53 +# Title: Nagios Check for Apache Threads +# Purpose: For a troublesome dmz wordpress host +# Package: nagios-plugins-apache-threads +# History: +# Usage: +# In nagios/nconf, use this checkcommand check command line: $USER1$/check_by_ssh -H $HOSTADDRESS$ -C "$USER1$/check_apache_threads -w $ARG1$ -c $ARG2$" +# Reference: general design /usr/lib64/nagios/plugins/check_sensors +# general design http://www.kernel-panic.it/openbsd/nagios/nagios6.html +# case -w http://www.linuxquestions.org/questions/programming-9/ash-test-is-string-a-contained-in-string-b-671773/ +# Improve: + +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin + +PROGNAME=`basename $0` +PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` +REVISION="0.0.1" + +. $PROGPATH/utils.sh + + +print_usage() { + cat <<EOF +Usage: $PROGNAME -w <thresh_warn> -c <thresh_crit> +EOF +} + +print_help() { + print_revision $PROGNAME $REVISION + echo "" + print_usage + echo "" + echo "This plugin checks for the number of active apache threads." + echo "" + support + exit $STATE_OK +} + + +# MAIN + +# Total httpd threads +tot_apache_threads="$( ps -ef | grep -ciE "httpd$" )" +verbosity=0 +thresh_warn= +thresh_crit= + +while test -n "${1}"; +do + case "$1" in + --help|-h) + print_help + exit $STATE_OK + ;; + --version|-V) + print_revision $PROGNAME $REVISION + exit $STATE_OK + ;; + -v | --verbose) + verbosity=$(( verbosity + 1 )) + shift + ;; + -w | --warning | -c | --critical) + if [[ -z "$2" || "$2" = -* ]]; + then + # Threshold not provided + echo "$PROGNAME: Option '$1' requires an argument." + print_usage + exit $STATE_UNKNOWN + elif [[ "$2" = +([0-9]) ]]; + then + # Threshold is a number + thresh="$2" + # use for a percentage template, from reference 2 + #elif [[ "$2" = +([0-9])% ]]; then + # # Threshold is a percentage + # thresh=$(( tot_mem * ${2%\%} / 100 )) + else + # Threshold is not a number or other valid input + echo "$PROGNAME: Threshold must be an integer." + print_usage + exit $STATE_UNKNOWN + fi + case "$1" in *-w*) thresh_warn=$thresh;; *) thresh_crit=$thresh;; esac + shift 2 + ;; + -?) + print_usage + exit $STATE_OK + ;; + *) + echo "$PROGNAME: Invalid option '$1'" + print_usage + exit $STATE_UNKNOWN + ;; + esac +done + +if test -z "$thresh_warn" || test -z "$thresh_crit"; +then + # One or both values were unspecified + echo "$PROGNAME: Threshold not set" + print_usage + exit $STATE_UNKNOWN +elif test "$thresh_crit" -le "$thresh_warn"; +then + echo "$PROGNAME: Critical value must be greater than warning value." + print_usage + exit $STATE_UNKNOWN +fi + +if test "$verbosity" -ge 2; +then + # Print debugging information + /bin/cat <<EOF +Debugging information: + Warning threshold: $thresh_warn + Critical threshold: $thresh_crit + Verbosity level: $verbosity + Apache threads: ${tot_apache_threads} +EOF +fi + +if test "${tot_apache_threads}" -gt "${thresh_crit}"; +then + # too many apache threads + echo "APACHE CRITICAL - $tot_apache_threads" + exit $STATE_CRITICAL +elif test "${tot_apache_threads}" -gt "${thresh_warn}"; +then + echo "APACHE WARNING - $tot_apache_threads" + exit $STATE_WARNING +else + # fine + echo "APACHE OK - $tot_apache_threads" + exit $STATE_OK +fi diff --git a/usr/share/nagios-plugins-apache-threads/README.txt b/usr/share/nagios-plugins-apache-threads/README.txt new file mode 100644 index 0000000..3ba27c6 --- /dev/null +++ b/usr/share/nagios-plugins-apache-threads/README.txt @@ -0,0 +1,12 @@ +### README for nagios-plugins-apache-threads + +You can use this check by configuring in nconf/nagios a checkcommand with a check command line of: +$USER1$/check_by_ssh -H $HOSTADDRESS$ -C "$USER1$/check_apache_threads -w $ARG1$ -c $ARG2$" + +Some sample default values for -w and -c are 50 and 150, respectively. + +### LICENSE +CC-BY-SA 4.0 + +### INSTALL +Nothing special. diff --git a/usr/share/nagios-plugins-apache-threads/files-for-versioning.txt b/usr/share/nagios-plugins-apache-threads/files-for-versioning.txt new file mode 100644 index 0000000..9c46ce6 --- /dev/null +++ b/usr/share/nagios-plugins-apache-threads/files-for-versioning.txt @@ -0,0 +1,2 @@ +nagios-plugins-apache-threads.spec +README.txt diff --git a/usr/share/nagios-plugins-apache-threads/localize_git.sh b/usr/share/nagios-plugins-apache-threads/localize_git.sh new file mode 100755 index 0000000..8359329 --- /dev/null +++ b/usr/share/nagios-plugins-apache-threads/localize_git.sh @@ -0,0 +1,2 @@ +#!/bin/sh +\cp -pRf /home/work/nagios-plugins-apache-threads.clean/.git /home/bgstack15/rpmbuild/SOURCES/nagios-plugins-apache-threads-0.0-1 diff --git a/usr/share/nagios-plugins-apache-threads/nagios-plugins-apache-threads.spec b/usr/share/nagios-plugins-apache-threads/nagios-plugins-apache-threads.spec new file mode 100644 index 0000000..4e15516 --- /dev/null +++ b/usr/share/nagios-plugins-apache-threads/nagios-plugins-apache-threads.spec @@ -0,0 +1,39 @@ +Name: nagios-plugins-apache-threads +Version: 0.0 +#Release: 1%{?dist} +Release: 1 +Summary: Nagios Plugin - check_apache_threads + +Group: Applications/Systems +License: CC-BY-SA 4.0 +URL: https://bgstack15.wordpress.com/ +Source0: nagios-plugins-apache-threads.tgz + +#BuildRequires: +Requires: nagios-plugins + +%description +Provides check_apache_threads support for Nagios. +In nagios/nconf, use this checkcommand check command line: $USER1$/check_by_ssh -H $HOSTADDRESS$ -C "$USER1$/check_apache_threads -w $ARG1$ -c $ARG2$" + +%prep +%setup -q + +%build + +%install +#make install DESTDIR=%{buildroot} +rm -rf %{buildroot} +rsync -a . %{buildroot}/ --exclude='**/.*.swp' + +%files +%doc %attr(0444, -, -) /usr/share/nagios-plugins-apache-threads/README.txt +/usr/share/nagios-plugins-apache-threads/nagios-plugins-apache-threads.spec +/usr/share/nagios-plugins-apache-threads/pack +/usr/share/nagios-plugins-apache-threads/localize_git.sh +%doc %attr(0444, -, -) /usr/share/nagios-plugins-apache-threads/scrub.txt +%doc %attr(0444, -, -) /usr/share/nagios-plugins-apache-threads/files-for-versioning.txt +%attr(0755, root, root) /usr/lib/nagios/plugins/check_apache_threads +%changelog +* Tue Jan 10 2017 B Stack <bgstack15@gmail.com> 0.0-1 +- Initial build diff --git a/usr/share/nagios-plugins-apache-threads/pack b/usr/share/nagios-plugins-apache-threads/pack new file mode 100755 index 0000000..3b13e75 --- /dev/null +++ b/usr/share/nagios-plugins-apache-threads/pack @@ -0,0 +1,105 @@ +#!/bin/bash +. /usr/bgscripts/bgscripts.bashrc --noclear --nodeps + +type=""; + +case "${thisflavor}" in + redhat|rhel|centos|fedora|korora) type=rpm;; + debian|ubuntu) type=dpkg;; + *) type=targz;; +esac + +echo " $@ " | grep -qiE -- "help|usage|\B-h\s|\B-\?" 1>/dev/null 2>&1 && { + # display help and exit + less -F <<EOF +pack utility version nagios-plugins-apache-threads-2017-01-10a +usage: pack [ rpm | deb | tar | scrub ] [ --debug | -d {0-10} ] +Provides a single command for building a package. This script is customized to each package. +optional arguments: + [ rpm | deb | tar | scrub ] Build that type of package. Scrub calls the scrub.py script. + The default depends on the local os flavor. This system is "${thisflavor}" + [ --debug {0-10} | -d {0-10} ] Display package type to build and exit. Debuglev not implemented here. +EOF +exit 1 +} + +# Derive package name and version number, for my simple package versions only. +fullname="$( pwd | sed -e 's/.*\(SOURCES\|deb\)\///;s/\/.*//;' )" +version="$( echo "${fullname}" | grep -oiE -- "-[0-9]{0,3}\.[0-9a-zA-Z]{0,5}-[0-9]{0,4}" | sed -e 's/^-//;' )" +shortversion="$( echo "${version}" | sed -e 's/-.*//;' )" +package="$( echo "${fullname}" | sed -e "s/-${version}//;" )" + +echo " $@ " | grep -qiE -- "rpm|rhel|redhat|centos|fedora|korora" 1>/dev/null 2>&1 && type=rpm +echo " $@ " | grep -qiE -- "debian|ubuntu|deb\s|dpkg" 1>/dev/null 2>&1 && type=dpkg +echo " $@ " | grep -qiE -- "tar|tgz|gz" 1>/dev/null 2>&1 && type=targz +echo " $@ " | grep -qiE -- "scrub" 1>/dev/null 2>&1 && type=scrub + +# Display information +echo "packaging ${package}-${version} as ${type}" +echo " $@ " | grep -qiE -- "debug|\B-d[ 0-9]{0,3}\s" 1>/dev/null 2>&1 && exit 0 + +case "${type}" in + rpm) + +########## PACKAGING for rhel/centos +# if you copy-paste this, be sure to define package, version, shortversion +rpmbuilddir=~/rpmbuild/ +packagespecfile="${package}-${version}/usr/share/${package}/${package}.spec" +sed -n -e '1,/^\%files$/p;' "${rpmbuilddir}/SOURCES/${packagespecfile}" > "${rpmbuilddir}/SOURCES/${packagespecfile}.swp.$$" #removes files and changelog +cd ${rpmbuilddir}/SOURCES/"${package}-${version}" +{ find * ! -type d ! -regex '.*.swp.*' ! -regex '.*?DEBIAN.*?' | sed -e 's/^/\//;s/\(.*\.txt\)/%doc %attr(0444, -, -) \1/;' -e 's/\(.*\)\.py$/\1\.py\n\1\.pyc\n\1\.pyo/;' -e 's/\(.*check_apache_threads\)/%attr(0755, root, root) \1/;' ; } >> "${rpmbuilddir}/SOURCES/${packagespecfile}.swp.$$" +sed -n -e '/^\%changelog/,$p' "${rpmbuilddir}/SOURCES/${packagespecfile}" >> "${rpmbuilddir}/SOURCES/${packagespecfile}.swp.$$" +mv -f "${rpmbuilddir}/SOURCES/${packagespecfile}.swp.$$" "${rpmbuilddir}/SOURCES/${packagespecfile}" +rm -rf ${rpmbuilddir}/SOURCES/"${package}-${shortversion}"; cp -prf ${rpmbuilddir}/SOURCES/"${package}-${version}" ${rpmbuilddir}/SOURCES/"${package}-${shortversion}" +rm -rf ${rpmbuilddir}/SOURCES/"${package}-${shortversion}"/DEBIAN +cd "${rpmbuilddir}/SOURCES" +rm -rf "${package}.tgz"; tar -zc --exclude='.git' -f "${package}.tgz" "${package}-${shortversion}" +cp -p "${rpmbuilddir}/SOURCES/${packagespecfile}" "${rpmbuilddir}/SPECS" +cd "${rpmbuilddir}/RPMS/x86_64" 1>/dev/null 2>&1 +rpmbuild -bb "${rpmbuilddir}/SPECS/${package}.spec" +rm -rf "${rpmbuilddir}/SOURCES/${package}-${shortversion}/" "${rpmbuilddir}/SOURCES/${package}.tgz" + + ;; + dpkg) + +########## PACKAGING for ubuntu +# You need package dpkg-dev to build packages. +# if you copy-paste this, be sure to define package, version +#packagedebfilesdir="${package}-${version}/usr/${package}/docs/debian" +#cd ~/deb/"${package}-${version}"/usr/bin +#for word in beep bup fl lecho newscript plecho send treesize; do ln -sf ../bgscripts/${word}.sh ${word}; done; ln -sf ../bgscripts/bgscripts.bashrc bp +#cd ~/deb/"${package}-${version}" +#find . -type f ! -regex '.*.hg.*' ! -regex '.*?debian-binary.*' ! -regex '.*?DEBIAN.*' ! -regex '.*?.swp' ! -regex '.*\.git.*' -printf '%P ' | xargs md5sum > ~/deb/"${packagedebfilesdir}"/md5sums +#rm -rf ~/deb/"${package}-${version}"/DEBIAN/ 2>/dev/null; mkdir -p ~/deb/"${package}-${version}"/DEBIAN/ +#cp -pf ~/deb/"${packagedebfilesdir}"/* ~/deb/"${package}-${version}"/DEBIAN/ +#cd ~/deb +#rm -rf ~/deb/"${package}-${version}.a" +#cp -pR ~/deb/"${package}-${version}" ~/deb/"${package}-${version}.a" +#mv ~/deb/"${package}-${version}/.git" ~/deb/".git$$" +#fakeroot dpkg-deb -b ~/deb/"${package}-${version}" +#mv ~/deb/".git$$" ~/deb/"${package}-${version}/.git" +[ ] + + ;; + targz) + +########## PACKAGING in a master.tgz +# if you copy-paste this, be sure to define package, version +cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES +rm -rf ./"${package}-${version}".master.tgz +tar -zcf "${package}-${version}".master.tgz "${package}-${version}"/ + + ;; + scrub) + +########## SCRUB for publication +# if you copy-paste this, be sure to define package, version +cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES +cd "$( find . -name "*scrub.txt" | grep -iE "${package}-${version}\/" | xargs dirname )" +/usr/bgscripts/scrub.py + + ;; + unknown) + echo "error: check $0 for errors on type ${type}." 1>&2 + ;; +esac diff --git a/usr/share/nagios-plugins-apache-threads/scrub.txt b/usr/share/nagios-plugins-apache-threads/scrub.txt new file mode 100644 index 0000000..59ca5c5 --- /dev/null +++ b/usr/share/nagios-plugins-apache-threads/scrub.txt @@ -0,0 +1,18 @@ +# scrubpyversion 2016-11-16a or newer +source /home/bgstack15/rpmbuild/SOURCES/nagios-plugins-apache-threads-0.0-1 +target /home/work/nagios-plugins-apache-threads.clean +ignore "tgz png gif jpg git swp ico ini" +BGSTACK15 BGSTACK15 +Bgstack15 Bgstack15 +bgstack15 bgstack15 +BNAME BNAME +Bname Bname +bname bname +STACK STACK +Stack Stack +stack stack +EXAMPLE EXAMPLE +example example +".COM" ".COM" +".com" ".com" +"203.0." "203.0." |