CACTI批量添加linux主机sh脚本
关于批量添加就三个文件:add_hosts.sh,ips.txt,thold_test.php,关于如何使用,更是简单./add_hosts.sh --add #执行批量工作./add_hosts.sh --help #查看帮助
1、cli/add_host.sh
[*]#!/bin/bash
[*]## @author : admin@51bbo.com
[*]## @date : 2014.06.09
[*]## @action : cacti批量填加机器
[*]## @doc : http://www.cacti.net/downloads/docs/html/cli_add_graphs.html
[*]##
[*]PATH =/usr/local/php/bin:$PATH
[*]THISDIR =$(cd $(dirname $0); pwd)
[*]function linux_monitor() {
[*] while read host_line
[*] do
[*] #读取IP列表
[*] host_name =$(echo $host_line |awk '{print $1}')
[*] host_ip =$(echo $host_line |awk '{print $2}')
[*] host_tree =$(echo $host_line |awk '{print $3}')
[*] #添加cacti设备
[*] php add_device.php--description = "$host_name($host_ip)" --ip = "$host_ip" --template = 1 --version= 2 --community = "chilijoy"
[*] #读取设备ID
[*] host_ids =$(php add_graphs.php --list-hosts |grep $host_ip |awk '{print $1}')
[*] #创建模板图像
[*] php add_graphs.php--host-id = "$host_ids" --graph-type = cg --graph-template-id = 4
[*] php add_graphs.php--host-id = "$host_ids" --graph-type = cg --graph-template-id = 7
[*] php add_graphs.php--host-id = "$host_ids" --graph-type = cg --graph-template-id = 8
[*] php add_graphs.php--host-id = "$host_ids" --graph-type = cg --graph-template-id = 9
[*] php add_graphs.php--host-id = "$host_ids" --graph-type = cg --graph-template-id = 13
[*] php add_graphs.php--host-id = "$host_ids" --graph-type = cg --graph-template-id = 41
[*] #创建网卡数据图像
[*] #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"
[*] 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"
[*] #创建分区数据图像
[*] 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 = "/"
[*] 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"
[*] 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"
[*] #添加设备到相应的组
[*] php add_tree.php--host-id = "$host_ids" --type = node --node-type = host --tree-id =$host_tree
[*] #添加自动阀值
[*] cd ../plugins/thold; php thold_test.php "$host_ids"
[*] cd $THISDIR
[*] #开启主机监控
[*] mysql -uroot -p'password' -e "update cacti.host setmonitor = 'on'whereid = '$host_ids' "
[*] done<$THISDIR/ips.txt
[*]}
[*]function windows_monitor() {
[*] echo
[*]}
[*]usage ="\
[*]Usage:
[*] php add_device.php --help
[*] php add_graphs.php --help
[*] php add_tree.php --help
[*]shell >php add_graphs.php --list-snmp-queries
[*]Known SNMP Queries:(id, name)
[*]1 SNMP - 接口统计
[*]2 ucd/net -获取被监控分区
[*]3 Karlnet - 无线网桥统计
[*]4 Netware - 获取可用卷
[*]6 Unix - 获取已挂载分区
[*]7 Netware - 获取处理器信息
[*]8 SNMP - 获取已挂载分区
[*]9 SNMP - 获取处理器信息
[*]10ucd/net - Device I/O
[*]shell >php add_graphs.php --list-snmp-fields --host-id = 25 --snmp-query-id = 1
[*]Known SNMP Fields for host-id 25: (name)
[*]ifAlias
[*]ifDescr
[*]ifHwAddr
[*]ifIndex
[*]ifIP
[*]ifName
[*]ifOperStatus
[*]ifSpeed
[*]ifType
[*]shell >php add_tree.php --list-trees
[*]Known Trees:
[*]idsort method name
[*]4 手动排序 (不排序)1-项目1
[*]5 手动排序 (不排序)2-项目2
[*]shell >php add_graphs.php --list-query-types --snmp-query-id = 1
[*]Known SNMP Query Types: (id, name)
[*]2 输入/输出 错误/丢包
[*]3 输入/输出 非单播包
[*]4 输入/输出 单播包
[*]9 输入/输出 字节 (64位计数)
[*]13输入/输出 位
[*]14输入/输出 位(64位计数)
[*]16输入/输出 字节
[*]20输入/输出 位(95%)
[*]21输入/输出 位(总带宽)
[*]22输入/输出 字节(总带宽)
[*]shell >php add_graphs.php --list-snmp-values --host-id = 25 --snmp-query-id = 1 --snmp-field = ifDescr
[*]Known values for ifDescr for host 25: (name)
[*]eth0
[*]lo
[*]shell >php add_graphs.php --list-snmp-values --host-id = 25 --snmp-query-id = 1 --snmp-field =ifOperStatus
[*]Known values for ifOperStatus for host 25: (name)
[*]Up
[*]shell >cat ips.txt#文件格式
[*]ID IP host tree
[*]s_name192.168.0.1 5
[*]$0 --add #执行批量工作
[*]$0 --help #查看帮助\n"
[*]for ARGS in "$@"
[*]do
[*] case $ARGS in
[*] -add|--add)
[*] linux_monitor;;
[*] -h|-help|--help)
[*] echo -e "$usage";;
[*] esac
[*]done
2、cli/ips.txt
[*]# cat ips.txt
[*]s0.name 192.168.1.200 5
[*]s1.name 192.168.1.210 5
[*]s2.name 192.168.1.220 6
3、plugins/thold/thold_test.php
[*]# cat plugins/thold/thold_test.php
[*]<?php
[*]chdir ('../../');
[*]include ( "./include/global.php" );
[*]include_once ( $config ['library_path'] . '/rrd.php');
[*]include_once ( $config ['base_path'] . '/plugins/thold/thold_functions.php');
[*]$hostid=$_SERVER ['argv'];
[*]#print$hostid ;
[*]$c= autocreate( $hostid );
[*]if( $c== 0) {
[*] print 'Either No TemplatesorThreshold(s) Already Exists - No thresholds were created.';
[*]}
[*]本文来自:Linux学习网
页:
[1]