关于批量添加就三个文件:add_hosts.sh,ips.txt,thold_test.php,关于如何使用,更是简单

./add_hosts.sh --add #执行批量工作./add_hosts.sh --help #查看帮助

1、cli/add_host.sh

  1. #!/bin/bash
  2. ## @author : admin@51bbo.com
  3. ## @date   : 2014.06.09
  4. ## @action : cacti批量填加机器
  5. ## @doc    : http://www.cacti.net/downloads/docs/html/cli_add_graphs.html
  6. ##
  7. PATH =/usr/local/php/bin:$PATH
  8. THISDIR =$(cd $(dirname $0); pwd)
  9. function linux_monitor() {
  10. while read host_line
  11. do
  12. #读取IP列表
  13. host_name =$(echo $host_line |awk '{print $1}')
  14. host_ip =$(echo $host_line |awk '{print $2}')
  15. host_tree =$(echo $host_line |awk '{print $3}')
  16. #添加cacti设备
  17. php add_device.php  --description = "$host_name($host_ip)"   --ip = "$host_ip"   --template = 1   --version= 2   --community = "chilijoy"
  18. #读取设备ID
  19. host_ids =$(php add_graphs.php --list-hosts |grep $host_ip |awk '{print $1}')
  20. #创建模板图像
  21. php add_graphs.php  --host-id = "$host_ids"   --graph-type = cg   --graph-template-id = 4
  22. php add_graphs.php  --host-id = "$host_ids"   --graph-type = cg   --graph-template-id = 7
  23. php add_graphs.php  --host-id = "$host_ids"   --graph-type = cg   --graph-template-id = 8
  24. php add_graphs.php  --host-id = "$host_ids"   --graph-type = cg   --graph-template-id = 9
  25. php add_graphs.php  --host-id = "$host_ids"   --graph-type = cg   --graph-template-id = 13
  26. php add_graphs.php  --host-id = "$host_ids"   --graph-type = cg   --graph-template-id = 41
  27. #创建网卡数据图像
  28. #php add_graphs.php  --host-id = "$host_ids"   --graph-type = ds    --graph-template-id = 2   --snmp-query-id = 1   --snmp-query-type-id = 13   --snmp-field = ifOperStatus   --snmp-value = "up"
  29. php add_graphs.php  --host-id = "$host_ids"   --graph-type = ds    --graph-template-id = 2   --snmp-query-id = 1   --snmp-query-type-id = 13   --snmp-field = ifDescr   --snmp-value = "eth0"
  30. #创建分区数据图像
  31. php add_graphs.php  --host-id = "$host_ids"   --graph-type = ds    --graph-template-id = 26   --snmp-query-id = 8   --snmp-query-type-id = 18   --snmp-field = hrStorageDescr   --snmp-value = "/"
  32. php add_graphs.php  --host-id = "$host_ids"   --graph-type = ds    --graph-template-id = 26   --snmp-query-id = 8   --snmp-query-type-id = 18   --snmp-field = hrStorageDescr   --snmp-value = "/data"
  33. php add_graphs.php  --host-id = "$host_ids"   --graph-type = ds    --graph-template-id = 26   --snmp-query-id = 8   --snmp-query-type-id = 18   --snmp-field = hrStorageDescr   --snmp-value = "Swap space"
  34. #添加设备到相应的组
  35. php add_tree.php  --host-id = "$host_ids"   --type = node   --node-type = host   --tree-id =$host_tree
  36. #添加自动阀值
  37. cd ../plugins/thold; php thold_test.php "$host_ids"
  38. cd $THISDIR
  39. #开启主机监控
  40. mysql -uroot -p'password' -e "update cacti.host set  monitor = 'on'  where  id = '$host_ids' "
  41. done  <  $THISDIR/ips.txt
  42. }
  43. function windows_monitor() {
  44. echo
  45. }
  46. usage ="\
  47. Usage:
  48. php add_device.php --help
  49. php add_graphs.php --help
  50. php add_tree.php --help
  51. shell >  php add_graphs.php --list-snmp-queries
  52. Known SNMP Queries:(id, name)
  53. 1   SNMP - 接口统计
  54. 2   ucd/net -  获取被监控分区
  55. 3   Karlnet - 无线网桥统计
  56. 4   Netware - 获取可用卷
  57. 6   Unix - 获取已挂载分区
  58. 7   Netware - 获取处理器信息
  59. 8   SNMP - 获取已挂载分区
  60. 9   SNMP - 获取处理器信息
  61. 10  ucd/net - Device I/O
  62. shell >  php add_graphs.php --list-snmp-fields   --host-id = 25   --snmp-query-id = 1
  63. Known SNMP Fields for host-id 25: (name)
  64. ifAlias
  65. ifDescr
  66. ifHwAddr
  67. ifIndex
  68. ifIP
  69. ifName
  70. ifOperStatus
  71. ifSpeed
  72. ifType
  73. shell >  php add_tree.php --list-trees
  74. Known Trees:
  75. id  sort method         name
  76. 4   手动排序 (不排序)  1-项目1
  77. 5   手动排序 (不排序)  2-项目2
  78. shell >  php add_graphs.php --list-query-types   --snmp-query-id = 1
  79. Known SNMP Query Types: (id, name)
  80. 2   输入/输出 错误/丢包
  81. 3   输入/输出 非单播包
  82. 4   输入/输出 单播包
  83. 9   输入/输出 字节 (64位计数)
  84. 13  输入/输出 位
  85. 14  输入/输出 位(64位计数)
  86. 16  输入/输出 字节
  87. 20  输入/输出 位(95%)
  88. 21  输入/输出 位(总带宽)
  89. 22  输入/输出 字节(总带宽)
  90. shell >  php add_graphs.php --list-snmp-values   --host-id = 25   --snmp-query-id = 1   --snmp-field = ifDescr
  91. Known values for ifDescr for host 25: (name)
  92. eth0
  93. lo
  94. shell >  php add_graphs.php --list-snmp-values   --host-id = 25   --snmp-query-id = 1   --snmp-field =ifOperStatus
  95. Known values for ifOperStatus for host 25: (name)
  96. Up
  97. shell >  cat ips.txt  #文件格式
  98. ID      IP          host tree
  99. s_name  192.168.0.1 5
  100. $0 --add    #执行批量工作
  101. $0 --help   #查看帮助\n"
  102. for ARGS in "$@"
  103. do
  104. case $ARGS in
  105. -add|--add)
  106. linux_monitor;;
  107. -h|-help|--help)
  108. echo -e "$usage";;
  109. esac
  110. done

2、cli/ips.txt

  1. [root@s_name cli]# cat ips.txt
  2. s0.name 192.168.1.200   5
  3. s1.name 192.168.1.210   5
  4. s2.name 192.168.1.220   6

3、plugins/thold/thold_test.php

  1. [root@s_name thold]# cat plugins/thold/thold_test.php
  2. <?php
  3. chdir ('../../');
  4. include ( "./include/global.php" );
  5. include_once ( $config ['library_path'] . '/rrd.php');
  6. include_once ( $config ['base_path'] . '/plugins/thold/thold_functions.php');
  7. $hostid  =  $_SERVER ['argv'][1];
  8. #print  $hostid ;
  9. $c  = autocreate( $hostid );
  10. if  ( $c  == 0) {
  11. print 'Either No Templates  or  Threshold(s) Already Exists - No thresholds were created.';
  12. }

CACTI批量添加linux主机sh脚本的更多相关文章

  1. python批量修改linux主机密码

    +++++++++++++++++++++++++++++++++++++++++++标题:python批量修改Linux服务器密码时间:2019年2月24日内容:基于python实现批量修改linu ...

  2. linux执行sh脚本文件命令

    linux执行sh脚本文件命令 很多时候需要多个命令来完成一项工作,而这个工作又常常是重复的,这个时候我们自然会想到将这些命令写成sh脚本,下次执行下这个脚本一切就都搞定了,下面就是发布代码的一个脚本 ...

  3. cacti批量添加主机脚本

    #!/bin/bash ##cacti批量脚本位置 device=/var/www/html/cacti/cli/add_device.php graphs=/var/www/html/cacti/c ...

  4. Nagios配置—添加linux主机监控

    nagios安装请参看:Nginx平台安装Nagios监控服务 下面是我添加linux监控机的过程,如有错误或者不当的地方请指出: 测试环境: 监控主机:nagios+nagios插件+nrpe+网站 ...

  5. linux编写.sh脚本并赋权限

    今日打包编译项目时,发现缺少一个git pull更新项目的脚本,所以在linux编写了一个gitpull.sh脚本,能够实现更新项目的需求. 1.首先vi  gitpull.sh或者使用vim编辑器. ...

  6. 自动化部署脚本--linux执行sh脚本

    自动化部署脚本文件目录: 运行主程序:./install.sh #!/bin/bash SCRIPTPATH=$(cd "$(dirname "$0")"; p ...

  7. 用python实现批量获取Linux主机简要信息并保存到Excel中 unstable 1.1

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- #filename get_linux_info.py #获取Linux主机的信息 # titles=[' ...

  8. Linux为sh脚本文件添加执行权限

    chmod是权限管理命令change the permissions mode of a file的缩写..u代表所有者,x代表执行权限. + 表示增加权限.chmod u+x file.sh 就表示 ...

  9. linux利用sh脚本上传下载文件到ftp服务器

    ####本地的/app/awsm/csv2 to ftp服务器上的/awsm/#### #!/bin/sh export today=`date +%Y-%m-%d` ftp -v -n 10.116 ...

随机推荐

  1. macos下简单的socket服务器+客户端

    TCP客户端服务器编程模型: 服务器: 调用socket函数创建套接字 调用bind绑定本地IP和端口 调用listen启动监听(准备好接收客户端链接的队列) 调用accept从已连接队列中提取第一个 ...

  2. 少有人知的 GitHub 使用技巧

    GitHub 大家常上吧?可是使用 GitHub 的各种小窍门你就不一定知道了.本文将各种使用 GitHub 的小窍门分享给大家. diff时忽略空格 有些修改只是增减了空格,在URL中添加?w=1就 ...

  3. Linux部署Django:报错 nohup: ignoring input and appending output to ‘nohup.out’

    一.部署 Django 到远程 Linux 服务器 利用 xshell 通过 ssh 连接到 Linux服务器,常规的启动命令是 python3 manage.py runserver 但是,关闭 x ...

  4. tsung报告中Transactions Statistics缺失问题

    长时间没有做性能测试,最近在使用tsung进行性能测试时,修改tsung自带的范例脚本后,运行查看结果时,发现测试报告中transactions  statistics缺失,刚开始一直以为是监控中的配 ...

  5. Spring事务管理----------整合学习版

    作者:学无先后 达者为先 Spring提供了一流的事务管理.在Spring中可以支持声明式事务和编程式事务. 一  spring简介 1 Spring的事务       事务管理在应用程序中起着至关重 ...

  6. Neo4j入门博客分享

    Neo4j学习参考博客:https://www.cnblogs.com/ljhdo/p/5516793.html Neo4j Cypher查询语言详解 http://www.ttlsa.com/nos ...

  7. qt 防止应用重复启动

    QApplication a(argc, argv); QSharedMemory singleton(a.applicationName()); if(!singleton.create(1)) { ...

  8. OFDM留空中央直流子载波目的及原理

    目的: 降低峰均比! 原理: IDFT公式: 直流分量k接近0,公式近似于对X(k)进行累加,因此直流分量会产生较大的信号能量,造成严重的峰均比. 详细内容可参考: https://dwz.cn/Zl ...

  9. http message

  10. sass,compass学习笔记总结

    最近在进行百度前端技术学院的任务,知道自己基础薄弱,可没想到弱到这种地步,同时在安装各种软件的同时遇到了各种坑,查阅了各种资料,一个个解决的时候也发现自己凌乱了.学习总结,在脑海中形成自己的学习系统才 ...