no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | tech:nagios:plugin_access_count [2018/05/03 11:27] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Nagios Plugin to Count lines in HTTP Logs for the previous minute ====== | ||
+ | Obsoleted: Check [[plugin_http_metrics|Nagios HTTP Metrics]] | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | # | ||
+ | # Count Apache access log line count | ||
+ | # Written by Senthil Nathan | ||
+ | # Last Modified: Dec 8th 2015 | ||
+ | # | ||
+ | # Usage: ./ | ||
+ | # | ||
+ | # Description: | ||
+ | # | ||
+ | # This plugin is to check the lines generated by the log in the previosu minute | ||
+ | # Assumes apache log time stamp of format " | ||
+ | # E.g. 08/ | ||
+ | # | ||
+ | # Output: | ||
+ | # | ||
+ | # Count is OK/ | ||
+ | # | ||
+ | # Examples: | ||
+ | # | ||
+ | # Warn if total access count / minute > 10000 | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | PROGNAME=`/ | ||
+ | PROGPATH=`echo $0 | sed -e ' | ||
+ | REVISION=" | ||
+ | |||
+ | . $PROGPATH/ | ||
+ | |||
+ | check_root() | ||
+ | { | ||
+ | # make sure script is running as root | ||
+ | if [ `whoami` != root ]; then | ||
+ | echo " | ||
+ | exit $STATE_UNKNOWN | ||
+ | fi | ||
+ | } | ||
+ | |||
+ | print_usage() { | ||
+ | echo " | ||
+ | echo " | ||
+ | echo " | ||
+ | } | ||
+ | |||
+ | print_revision() { | ||
+ | echo " | ||
+ | echo " | ||
+ | } | ||
+ | print_help() { | ||
+ | print_revision | ||
+ | echo "" | ||
+ | print_usage | ||
+ | echo "" | ||
+ | echo "Check total access log count for the previous minute for Nagios" | ||
+ | echo "" | ||
+ | } | ||
+ | |||
+ | # Check user is root (not required) | ||
+ | #check_root | ||
+ | |||
+ | # Make sure the correct number of command line | ||
+ | # arguments have been supplied | ||
+ | |||
+ | if [ $# -lt 1 ]; then | ||
+ | print_usage | ||
+ | exit $STATE_UNKNOWN | ||
+ | fi | ||
+ | |||
+ | # Grab the command line arguments | ||
+ | |||
+ | exitstatus=$STATE_WARNING #default | ||
+ | while test -n " | ||
+ | case " | ||
+ | --help) | ||
+ | print_help | ||
+ | exit $STATE_OK | ||
+ | ;; | ||
+ | -h) | ||
+ | print_help | ||
+ | exit $STATE_OK | ||
+ | ;; | ||
+ | --version) | ||
+ | print_revision | ||
+ | exit $STATE_OK | ||
+ | ;; | ||
+ | -V) | ||
+ | print_revision | ||
+ | exit $STATE_OK | ||
+ | ;; | ||
+ | --warning) | ||
+ | thewarn=$2 | ||
+ | shift | ||
+ | ;; | ||
+ | -w) | ||
+ | thewarn=$2 | ||
+ | shift | ||
+ | ;; | ||
+ | --critical) | ||
+ | thecrit=$2 | ||
+ | shift | ||
+ | ;; | ||
+ | -c) | ||
+ | thecrit=$2 | ||
+ | shift | ||
+ | ;; | ||
+ | -f) | ||
+ | thefile=$2 | ||
+ | shift | ||
+ | ;; | ||
+ | --filename) | ||
+ | thefile=$2 | ||
+ | shift | ||
+ | ;; | ||
+ | *) | ||
+ | echo " | ||
+ | print_usage | ||
+ | exit $STATE_UNKNOWN | ||
+ | ;; | ||
+ | esac | ||
+ | shift | ||
+ | done | ||
+ | |||
+ | # Validate arguments | ||
+ | if [ -z $thecrit ]; then | ||
+ | print_usage | ||
+ | exit $STATE_UNKNOWN | ||
+ | fi | ||
+ | if [ -z $thewarn ]; then | ||
+ | print_usage | ||
+ | exit $STATE_UNKNOWN | ||
+ | fi | ||
+ | if [ -z $thefile ]; then | ||
+ | print_usage | ||
+ | exit $STATE_UNKNOWN | ||
+ | fi | ||
+ | |||
+ | # Check begins here | ||
+ | |||
+ | # | ||
+ | declare -i accesscount | ||
+ | PMIN=`date --date '-1 min' +" | ||
+ | accesscount=`grep -c $PMIN $thefile` | ||
+ | |||
+ | # | ||
+ | if [ $accesscount -ge $thecrit ]; then | ||
+ | echo " | ||
+ | exit $STATE_CRITICAL | ||
+ | fi | ||
+ | if [ $accesscount -ge $thewarn ]; then | ||
+ | echo " | ||
+ | exit $STATE_WARNING | ||
+ | fi | ||
+ | if [ $accesscount -lt $thewarn ]; then | ||
+ | echo " | ||
+ | exit $STATE_OK | ||
+ | fi | ||
+ | # | ||
+ | echo " | ||
+ | exit $STATE_UNKNOWN | ||
+ | |||
+ | </ | ||