脚本添加cacti监控(第二版:加入硬盘项目)

简介:

 
 
  1. #!/bin/bash  
  2.  
  3. ip=('192.168.1.1' '192.168.1.2')  
  4.  
  5. tree=('test' 'test')  
  6.  
  7. function f_add_LinuxHost()  
  8. {  
  9.     /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_device.php --description="$1" --ip="$1" --template=3 --version=2 --community=public > /tmp/cacti_cache.txt  
  10.     id=`cat /tmp/cacti_cache.txt | grep "Success" | awk -F "[:()]" '{print $3}'`  
  11.     /bin/rm -f /tmp/cacti_cache.txt  
  12. }  
  13.  
  14. function f_add()  
  15. {  
  16.     host_id=$1  
  17.     graph_type=$2  
  18.     graph_template_id=$3  
  19.     snmp_query_id=$4  
  20.     snmp_query_type_id=$5  
  21.     snmp_field=$6  
  22.     snmp_value=$7  
  23.  
  24.     case $graph_type in 
  25.         ds)  
  26.             /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_graphs.php --host-id="$host_id" --graph-type="$graph_type" --graph-template-id="$graph_template_id" --snmp-query-id="$snmp_query_id" --snmp-query-type-id="$snmp_query_type_id" --snmp-field="$snmp_field" --snmp-value="$snmp_value"  
  27.         ;;  
  28.         cg)  
  29.             /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_graphs.php --host-id="$host_id" --graph-type="$graph_type" --graph-template-id="$graph_template_id"  
  30.         ;;  
  31.         *)  
  32.             echo "function parameter error!" 
  33.         ;;  
  34.     esac      
  35. }  
  36.  
  37. function f_add_tree()  
  38. {  
  39.     tree_id=`/usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_tree.php --list-trees | egrep "\b$2\b" | awk '{print $1}'`  
  40.     if [ -z $tree_id ];then 
  41.         /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_tree.php --type=tree --name="$2"  
  42.         tree_id=`/usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_tree.php --list-trees | egrep "\b$2\b" | awk '{print $1}'`  
  43.     fi  
  44.     /usr/local/php/bin/php /usr/local/nginx/html/cacti/cli/add_tree.php --type=node --node-type=host --tree-id="$tree_id" --host-id="$1"  
  45. }  
  46.  
  47.  
  48. for (( i=0; i<${#ip[@]}; i++ ))  
  49. do  
  50.     f_add_LinuxHost ${ip[i]}  
  51.     f_add $id ds 2 1 14 ifName eth0  
  52.     f_add $id ds 2 1 14 ifName eth1  
  53.     f_add $id ds 3 2 6  dskDevice "/dev/sda3" 
  54.     f_add $id cg 4  
  55.     f_add $id cg 7  
  56.     f_add $id cg 11  
  57.     f_add $id cg 13  
  58.     f_add_tree $id ${tree[i]}  
  59. done  

 f_add_LinuxHost ${ip[i]}                              #添加主机
 f_add $id ds 2 1 14 ifName eth0                   #添加网卡监控
 f_add $id ds 2 1 14 ifName eth1                   #添加网卡监控
 f_add $id ds 3 2 6  dskDevice "/dev/sda3"     #添加硬盘监控
 f_add $id cg 4                                               #添加CPU监控
 f_add $id cg 7                                               #添加ping监控
 f_add $id cg 11                                             #添加load监控
 f_add $id cg 13                                             #添加mem监控
 f_add_tree $id ${tree[i]}                               #添加树并加入节点

本文转自运维笔记博客51CTO博客,原文链接http://blog.51cto.com/lihuipeng/778476如需转载请自行联系原作者


lihuipeng

相关文章
|
监控 Windows 网络安全
|
监控 应用服务中间件 PHP
|
Web App开发 监控 关系型数据库
|
Web App开发 关系型数据库 测试技术
|
监控 开发工具 Windows
|
Web App开发 监控 关系型数据库
|
Web App开发 监控 Apache