标签:
Cacti 自定义脚本监控
*************************************************
脚本内容:
[root@cacti scripts]# cat get_snmp_network_data.sh
#!/bin/bash
# ========================================================================================
# goldengate health plugin for Nagios
#
# Written by : dd
# Release : 1.0.0
# Creation date : 2015-02-11
# Description : Nagios plugin (script) to check uptime .
# This script has been designed and written on Linux System.
#
# USAGE :./get_snmp_network_data.sh -v 2c -c sinolife 172.28.0.42 .1.3.6.1.4.1.15227.1.5.1.1.1.0
#
# Exemple: ./get_snmp_network_data.sh
#
#
# HISTORY :
# Release | Date | Authors | Description
# --------------+---------------+----------------------+-----------------------------------
# 1.0.0 | 2015.05.18 | dd | Create the script
# -----------------------------------------------------------------------------------------
# NOTICE:
#-----------------------------------------------------------------------------------------
# You should have the root Permissions ,You can use sudo to realize .
# -----------------------------------------------------------------------------------------
# Nagios return codes
WARNING=
CRITICAL=
BRIEF=0
SILENT=0
#定义 nagios返回的状态变量
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# 插件描述信息
PROGNAME="check_network_data.sh"
RELEASE="Revision 1.0.0"
AUTHOR="(c) 2015 dudong"
# Functions plugin usage
# 插件的使用方法函数
print_release() {
echo "$RELEASE $AUTHOR"
}
print_usage() {
echo ""
echo "$PROGNAME $RELEASE - check network script for Nagios"
echo ""
echo "Usage: get_snmp_network_data.sh"
echo ""
echo " -com COMMUNITY"
echo ""
echo " -i IPADDR"
echo ""
echo " -o OID"
echo ""
echo " -w warning"
echo ""
echo " -c critical"
echo ""
echo " -h Show this page"
echo ""
echo ""
echo " -v check the version"
echo "Usage: $PROGNAME"
echo "Usage: $PROGNAME --help"
echo ""
exit 0
}
print_help() {
print_usage
echo ""
echo "This plugin will check network "
echo ""
exit 0
}
# 传递参数
# process args
while [ ! -z "$1" ]; do
case $1 in
-com) shift; COMMUNITY=$1 ;;
-i) shift; IPADDR=$1 ;;
-o) shift; OID=$1 ;;
-w) shift; WARNING=$1 ;;
-c) shift; CRITICAL=$1 ;;
-h) show_help; exit 1 ;;
esac
shift
done
#获取数据
#UPDATE=$( uptime | awk ‘{print $3}‘)
MESSAGE_1=$(snmpwalk -v 2c -c $COMMUNITY $IPADDR $OID | awk ‘{print $5}‘)
MESSAGE=$(echo $MESSAGE_1 | awk -F‘[".]‘ ‘{print $1}‘)
echo " data:$MESSAGE"
#判断
#if [[ $MESSAGE -ge $CRITICAL ]]; then
# echo "Critical - data is $MESSAGE | data=$MESSAGE"
# exit $STATE_CRITICAL
#
#elif [[ $MESSAGE -ge $WARNING ]]; then
# echo "Warning - data is $MESSAGE | data=$MESSAGE"
# exit $STATE_WARNING
#
#else
# echo "OK - data is $MESSAGE | data=$MESSAGE"
# exit $STATE_OK
#
#fi
#
#
You have mail in /var/spool/mail/root
[root@cacti scripts]#
把脚本上传至cacti的screpts目录下:/var/www/html/scripts
注意修改脚本权限
测试:[root@cacti scripts]# ./get_snmp_network_data.sh -com sinolife -i 172.28.0.41 -o .1.3.6.1.4.1.15227.1.5.1.1.2.0
data:57
脚本可以根据nagios的nrpe脚本进行修改,但cacti的输出结构更简单。
变量:值 变量:值
即可!!
创建数据输入方法:
/bin/bash <path_cacti>/scripts/get_snmp_network_data.sh -com <community> -i <hostname> -o <OID>
输入字段有3个,两个可以"从主机派生",从主机派生,需要选择一下。
不能从主机派生,则需要自己输入:
输出字段一个:
创建数据模板:查询cpu的OID,红色部分注意修改。
其他的memery, session 一样方法,只是oid不同
创建图形模板:
对象:图形类型等
创建主机,然后添加图形即可。
查看数据源:
图形文件:
/var/www/html/rra/61/664.rrd
检查是否有值传进来:
[root@cacti log]# rrdtool lastupdate /var/www/html/rra/61/664.rrd
getsessiondata
1452834361: 1221
You have mail in /var/spool/mail/root
[root@cacti log]#
[root@cacti log]#
值1221 已传入rrd图形。
查看图形:
实时图形:
标签:
原文地址:http://www.cnblogs.com/MichaelDD/p/5133131.html