博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nagios 自定义插件demo
阅读量:4975 次
发布时间:2019-06-12

本文共 5347 字,大约阅读时间需要 17 分钟。

#!/bin/bashloadavg=$( uptime | awk -F: '{print $4}' | xargs )load1int=$( echo $loadavg | cut -d "." -f 1 )load5int=$( echo $loadavg | awk -F, '{print $2}' | xargs | cut -d "." -f 1 )load15int=$( echo $loadavg | awk -F, '{print $3}' | xargs | cut -d "." -f 1 )load1=$( echo $loadavg | awk -F, '{print $1}' )load5=$( echo $loadavg | awk -F, '{print $2}' )load15=$( echo $loadavg | awk -F, '{print $3}' )output="Load Average: $loadavg | Load_1min=$load1, Load_5min=$load5, Load_15min=$load15" if [ $load1int -le 1 -a $load5int -le 1 -a $load15int -le 1 ]then    echo "OK- $output"    exit 0elif [ $load1int -le 2 -a $load5int -le 2 -a $load15int -le 2 ]then    echo "WARNING- $output"    exit 1elif [ $load1int -gt 2 -a $load5int -gt 2 -a $load15int -gt 2 ]then    echo "CRITICAL- $output"    exit 2elseecho "UNKNOWN- $output"exit 3fi#!/bin/ksh################################################################################# Sample Nagios plugin to monitor free memory on the local machine             ## Author: Daniele Mazzocchio (http://www.kernel-panic.it/)                     #################################################################################VERSION="Version 1.0"AUTHOR="(c) 2007-2009 Daniele Mazzocchio (danix@kernel-panic.it)"PROGNAME=`/usr/bin/basename $0`# ConstantsBYTES_IN_MB=$(( 1024 * 1024 ))KB_IN_MB=1024# Exit codesSTATE_OK=0STATE_WARNING=1STATE_CRITICAL=2STATE_UNKNOWN=3# Helper functions #############################################################function print_revision {   # Print the revision number   echo "$PROGNAME - $VERSION"}function print_usage {   # Print a short usage statement   echo "Usage: $PROGNAME [-v] -w 
-c
"}function print_help { # Print detailed help information print_revision echo "$AUTHOR\n\nCheck free memory on local machine\n" print_usage /bin/cat <<__EOTOptions:-h Print detailed help screen-V Print version information-w INTEGER Exit with WARNING status if less than INTEGER MB of memory are free-w PERCENT% Exit with WARNING status if less than PERCENT of memory is free-c INTEGER Exit with CRITICAL status if less than INTEGER MB of memory are free-c PERCENT% Exit with CRITICAL status if less than PERCENT of memory is free-v Verbose output__EOT}# Main ########################################################################## Total memory size (in MB)tot_mem=$(( `/sbin/sysctl -n hw.physmem` / BYTES_IN_MB))# Free memory size (in MB)free_mem=$(( `/usr/bin/vmstat | /usr/bin/tail -1 | /usr/bin/awk '{ print $5 }'` / KB_IN_MB ))# Free memory size (in percentage)free_mem_perc=$(( free_mem * 100 / tot_mem ))# Verbosity levelverbosity=0# Warning thresholdthresh_warn=# Critical thresholdthresh_crit=# Parse command line optionswhile [ "$1" ]; do case "$1" in -h | --help) print_help exit $STATE_OK ;; -V | --version) print_revision exit $STATE_OK ;; -v | --verbose) : $(( verbosity++ )) 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 (MB) thresh=$2 elif [[ "$2" = +([0-9])% ]]; then # Threshold is a percentage thresh=$(( tot_mem * ${
2%\%} / 100 )) else # Threshold is neither a number nor a percentage echo "$PROGNAME: Threshold must be integer or percentage" print_usage exit $STATE_UNKNOWN fi [[ "$1" = *-w* ]] && thresh_warn=$thresh || thresh_crit=$thresh shift 2 ;; -?) print_usage exit $STATE_OK ;; *) echo "$PROGNAME: Invalid option '$1'" print_usage exit $STATE_UNKNOWN ;; esacdoneif [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then # One or both thresholds were not specified echo "$PROGNAME: Threshold not set" print_usage exit $STATE_UNKNOWNelif [[ "$thresh_crit" -gt "$thresh_warn" ]]; then # The warning threshold must be greater than the critical threshold echo "$PROGNAME: Warning free space should be more than critical free space" print_usage exit $STATE_UNKNOWNfiif [[ "$verbosity" -ge 2 ]]; then # Print debugging information /bin/cat <<__EOTDebugging information: Warning threshold: $thresh_warn MB Critical threshold: $thresh_crit MB Verbosity level: $verbosity Total memory: $tot_mem MB Free memory: $free_mem MB ($free_mem_perc%)__EOTfiif [[ "$free_mem" -lt "$thresh_crit" ]]; then # Free memory is less than the critical threshold echo "MEMORY CRITICAL - $free_mem_perc% free ($free_mem MB out of $tot_mem MB)" exit $STATE_CRITICALelif [[ "$free_mem" -lt "$thresh_warn" ]]; then # Free memory is less than the warning threshold echo "MEMORY WARNING - $free_mem_perc% free ($free_mem MB out of $tot_mem MB)" exit $STATE_WARNINGelse # There's enough free memory! echo "MEMORY OK - $free_mem_perc% free ($free_mem MB out of $tot_mem MB)" exit $STATE_OKfi

转载于:https://www.cnblogs.com/huaxiaoyao/p/5018251.html

你可能感兴趣的文章
Python 文件处理
查看>>
邻接表详解
查看>>
迭代dict的value
查看>>
eclipse package,source folder,folder区别及相互转换
查看>>
Py 可能是最全面的 python 字符串拼接总结(带注释版)
查看>>
《Java程序设计实验》 软件工程18-1,3 OO实验2
查看>>
【Herding HDU - 4709 】【数学(利用叉乘计算三角形面积)】
查看>>
OPENSSL使用方法
查看>>
接口操作XML
查看>>
idhttp访问DATASNAP有密码验证的中间件
查看>>
libmidas.so.2
查看>>
开发WINDOWS服务程序
查看>>
httpencode编码
查看>>
cross socket和msgpack的数据序列和还原
查看>>
解决跨操作系统平台JSON中文乱码问题
查看>>
DELPHI搭建centos开发环境
查看>>
IdHTTPServer允许跨域访问
查看>>
更新.net core 3.0,dotnet ef命令无法使用的解决办法
查看>>
React躬行记(13)——React Router
查看>>
前端利器躬行记(1)——npm
查看>>