nagios 自定义插件demo

#!/bin/bash

loadavg=$( 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 0
elif [ $load1int -le 2 -a $load5int -le 2 -a $load15int -le 2 ]
then
    echo "WARNING- $output"
    exit 1
elif [ $load1int -gt 2 -a $load5int -gt 2 -a $load15int -gt 2 ]
then
    echo "CRITICAL- $output"
    exit 2
else
echo "UNKNOWN- $output"
exit 3
fi

#!/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 ([email protected])"

PROGNAME=`/usr/bin/basename $0`

# Constants
BYTES_IN_MB=$(( 1024 * 1024 ))
KB_IN_MB=1024

# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_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 <limit> -c <limit>"
}

function print_help {
   # Print detailed help information
   print_revision
   echo "$AUTHOR\n\nCheck free memory on local machine\n"
   print_usage

   /bin/cat <<__EOT

Options:
-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 level
verbosity=0
# Warning threshold
thresh_warn=
# Critical threshold
thresh_crit=

# Parse command line options
while [ "$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
           ;;
   esac
done

if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
   # One or both thresholds were not specified
   echo "$PROGNAME: Threshold not set"
   print_usage
   exit $STATE_UNKNOWN
elif [[ "$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_UNKNOWN
fi

if [[ "$verbosity" -ge 2 ]]; then
   # Print debugging information
   /bin/cat <<__EOT
Debugging 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%)
__EOT
fi

if [[ "$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_CRITICAL
elif [[ "$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_WARNING
else
   # There‘s enough free memory!
   echo "MEMORY OK - $free_mem_perc% free ($free_mem MB out of $tot_mem MB)"
   exit $STATE_OK
fi
时间: 2024-10-06 01:20:28

nagios 自定义插件demo的相关文章

代码:jquery自定义插件 demo

jquery自定义插件 demo 2016-1-13 只是一个简易的示例 <script type="text/javascript" src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $.fn.portamento = function

cordova3.X 运用grunt生成plugin自定义插件骨架

Cordova提供了一组设备相关的API,通过这组API,移动应用能够以JavaScript访问原生的设备功能,如摄像头.麦克风等.Cordova还提供了一组统一的JavaScript类库,以及为这些类库所用的设备相关的原生后台代码. 一.安装cordova npm install -g cordova 二.创建项目 cordova create hello com.blue.sky.hybrid.app.hello HelloWorld 三.添加平台支持 cd hello cordova pl

shell编程之【nagios自定义监控系统磁盘脚本】

之前写了一篇文章主要介绍nagios的搭建使用 http://msiyuetian.blog.51cto.com/8637744/1704346 下面这篇文章主要介绍nagios自定义监控系统磁盘的脚本实现. Nagios可以识别4种状态返回信息,即 0 表示状态正常(OK).1 表示出现警告(WARNING).2 表示出现非常严重的错误(CRITICAL),3 表示未知错误(UNKNOWN).Nagios根据插件返回来的值,来判断监控对象的状态,并通过web显示出来.我们就可以利用上面这个特性

jquery自定义插件——window的实现

本例子实现弹窗的效果: 1.jquery.show.js /* * 开发者:lzugis * 开发时间:2014年6月10日 * 实现功能:点击在鼠标位置显示div * 版本序号:1.0 */ (function($){ $.fn.showDIV = function(options){ var defaults = {}; var options = $.extend(defaults, options); var showdiv=$(this); var close, title, cont

一个简单的MariaDB认证插件demo

代码地址如下:http://www.demodashi.com/demo/13076.html 一.前言 众所周知(其实可能很多人不知道)MariaDB支持插件认证.在MariaDB中新建用户,常见的语句是: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 这样创建的用户,登录时的认证方式是密码.其实创建用户的语句还可以是: CREATE USER 'username'@'host' IDENTIFIED VIA 'pluginna

Airflow自定义插件, 使用datax抽数

Airflow自定义插件 Airflow之所以受欢迎的一个重要因素就是它的插件机制.Python成熟类库可以很方便的引入各种插件.在我们实际工作中,必然会遇到官方的一些插件不足够满足需求的时候.这时候,我们可以编写自己的插件.不需要你了解内部原理,甚至不需要很熟悉Python, 反正我连蒙带猜写的. 插件分类 Airflow的插件分为Operator和Sensor两种.Operator是具体要执行的任务插件, Sensor则是条件传感器,当我需要设定某些依赖的时候可以通过不同的sensor来感知

Nagios自定义报警时间

Nagios自定义报警时间 遇到需要自定义检查和报警时间的,总结一下.大家集思广益,不断完善. 常调用的模板配置文件: efine service{ name                           generic-service         ; 定义一个服务名称 active_checks_enabled          1                       ; Activeservice checks are enabled passive_checks_enab

linux系统管理员之自动化检测工具 nagios及其插件配置

配置方式:源码编译. 参考: Linux下Nagios的安装与配置 nagios图像化pnp4nagios的安装和配置 烂泥:学习Nagios(四):pnp4nagios图形化绘制nagios数据 上面这三篇文章对我学习nagios的帮助很大,在此表示感谢. 言归正传,开始我们的配置吧. ---------------------------------------------------------------------------------------------------------

cordova 自定义插件

cordova /phonegap 自定义插件 在使用cordova 的过程中,虽然官方提供的插件以及其他人开源的插件较多.但有时为了实现某种需求,还是需要自己编写插件. 以前总是会手动的配置cordova插件,具体可以参考phonegap手动配置插件 今天主要是介绍官方提供的plugman来创建插件 pluman的使用 首先,安装plumam npm install -g plugman 安装完之后,就可以创建plugin plugman create --name <pluginName>