From dd9977e7a46e2b45ea93d27d92c9492256cdc975 Mon Sep 17 00:00:00 2001 From: B Stack Date: Tue, 10 Jan 2017 13:55:17 -0500 Subject: initial commit --- usr/lib/nagios/plugins/check_apache_threads | 140 +++++++++++++++++++++ usr/share/nagios-plugins-apache-threads/README.txt | 12 ++ .../files-for-versioning.txt | 2 + .../nagios-plugins-apache-threads/localize_git.sh | 2 + .../nagios-plugins-apache-threads.spec | 39 ++++++ usr/share/nagios-plugins-apache-threads/pack | 105 ++++++++++++++++ usr/share/nagios-plugins-apache-threads/scrub.txt | 18 +++ 7 files changed, 318 insertions(+) create mode 100644 usr/lib/nagios/plugins/check_apache_threads create mode 100644 usr/share/nagios-plugins-apache-threads/README.txt create mode 100644 usr/share/nagios-plugins-apache-threads/files-for-versioning.txt create mode 100755 usr/share/nagios-plugins-apache-threads/localize_git.sh create mode 100644 usr/share/nagios-plugins-apache-threads/nagios-plugins-apache-threads.spec create mode 100755 usr/share/nagios-plugins-apache-threads/pack create mode 100644 usr/share/nagios-plugins-apache-threads/scrub.txt 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 < -c +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 < 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 </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." -- cgit